Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.phone; |
| 18 | |
Jordan Liu | ff2ccd7 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 19 | import android.annotation.IntDef; |
sangyun | 1c1918a | 2023-11-13 22:37:50 +0900 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 21 | import android.app.Activity; |
| 22 | import android.app.KeyguardManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 23 | import android.app.ProgressDialog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import android.content.BroadcastReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.content.ContentResolver; |
| 26 | import android.content.Context; |
| 27 | import android.content.ContextWrapper; |
| 28 | import android.content.Intent; |
| 29 | import android.content.IntentFilter; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 30 | import android.content.pm.PackageManager; |
Youming Ye | 47a6adc | 2018-11-19 15:33:36 -0800 | [diff] [blame] | 31 | import android.content.res.XmlResourceParser; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.media.AudioManager; |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 33 | import android.net.ConnectivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 34 | import android.net.Uri; |
| 35 | import android.os.AsyncResult; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 36 | import android.os.Handler; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.os.Message; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 38 | import android.os.PersistableBundle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | import android.os.PowerManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 40 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.preference.PreferenceManager; |
Sanket Padawe | 4c69923 | 2016-02-09 11:07:22 -0800 | [diff] [blame] | 42 | import android.provider.Settings; |
Meng Wang | 6130762 | 2019-10-23 14:08:43 -0700 | [diff] [blame] | 43 | import android.sysprop.TelephonyProperties; |
Tyler Gunn | 900d8fd | 2018-09-21 09:22:12 -0700 | [diff] [blame] | 44 | import android.telecom.TelecomManager; |
Nathan Harold | f9df6ea | 2019-03-08 11:54:22 -0800 | [diff] [blame] | 45 | import android.telephony.AnomalyReporter; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 46 | import android.telephony.CarrierConfigManager; |
Aishwarya Mallampati | 05483bf | 2024-10-08 21:42:52 +0000 | [diff] [blame] | 47 | import android.telephony.NetworkRegistrationInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.telephony.ServiceState; |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 49 | import android.telephony.SubscriptionInfo; |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 50 | import android.telephony.SubscriptionManager; |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 51 | import android.telephony.TelephonyCallback; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 52 | import android.telephony.TelephonyLocalConnection; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 53 | import android.telephony.TelephonyManager; |
Sarah Chin | 37b3907 | 2023-11-05 13:28:21 -0800 | [diff] [blame] | 54 | import android.text.TextUtils; |
Ling Ma | 317906d | 2022-12-05 15:58:14 -0800 | [diff] [blame] | 55 | import android.util.ArraySet; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 56 | import android.util.LocalLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.util.Log; |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 58 | import android.widget.Toast; |
Ta-wei Yen | b29425b | 2016-09-21 17:28:14 -0700 | [diff] [blame] | 59 | |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 60 | import com.android.ims.ImsFeatureBinderRepository; |
Siim Sammul | 182d61b | 2021-05-04 16:01:42 +0100 | [diff] [blame] | 61 | import com.android.internal.os.BinderCallsStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 62 | import com.android.internal.telephony.CallManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 63 | import com.android.internal.telephony.IccCardConstants; |
| 64 | import com.android.internal.telephony.MmiCode; |
| 65 | import com.android.internal.telephony.Phone; |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 66 | import com.android.internal.telephony.PhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 67 | import com.android.internal.telephony.PhoneConstants; |
| 68 | import com.android.internal.telephony.PhoneFactory; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 69 | import com.android.internal.telephony.SettingsObserver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 70 | import com.android.internal.telephony.TelephonyCapabilities; |
Youming Ye | 47a6adc | 2018-11-19 15:33:36 -0800 | [diff] [blame] | 71 | import com.android.internal.telephony.TelephonyComponentFactory; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 72 | import com.android.internal.telephony.TelephonyIntents; |
Jack Yu | 3e2ac6e | 2022-03-26 13:59:45 -0700 | [diff] [blame] | 73 | import com.android.internal.telephony.data.DataEvaluation.DataDisallowedReason; |
Hwangoo Park | ba21cf2 | 2022-11-30 14:34:04 +0000 | [diff] [blame] | 74 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
Daniel Banta | b26e96f | 2022-10-19 23:25:35 +0000 | [diff] [blame] | 75 | import com.android.internal.telephony.emergency.EmergencyStateTracker; |
Thomas Nguyen | 090fb00 | 2023-09-11 17:35:30 -0700 | [diff] [blame] | 76 | import com.android.internal.telephony.flags.FeatureFlags; |
Ling Ma | 51dd302 | 2023-08-29 11:46:38 -0700 | [diff] [blame] | 77 | import com.android.internal.telephony.flags.FeatureFlagsImpl; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 78 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 79 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 80 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 81 | import com.android.internal.telephony.satellite.SatelliteController; |
Nagendra Prasad Nagarle Basavaraju | f668eda | 2024-02-15 15:02:57 +0000 | [diff] [blame] | 82 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 83 | import com.android.internal.telephony.uicc.UiccPort; |
Jordan Liu | 06bdef1 | 2021-03-24 17:25:46 -0700 | [diff] [blame] | 84 | import com.android.internal.telephony.uicc.UiccProfile; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 85 | import com.android.internal.util.IndentingPrintWriter; |
Andrew Lee | fb7f92e | 2015-02-26 16:23:32 -0800 | [diff] [blame] | 86 | import com.android.phone.settings.SettingsConstants; |
Ta-wei Yen | f0a71bc | 2017-05-17 12:28:28 -0700 | [diff] [blame] | 87 | import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver; |
Hunsuk Choi | c2e3fbc | 2024-05-10 05:05:17 +0000 | [diff] [blame] | 88 | import com.android.services.telephony.domainselection.DynamicRoutingController; |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 89 | import com.android.services.telephony.rcs.TelephonyRcsService; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 90 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 91 | import java.io.FileDescriptor; |
| 92 | import java.io.PrintWriter; |
Jordan Liu | ff2ccd7 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 93 | import java.lang.annotation.Retention; |
| 94 | import java.lang.annotation.RetentionPolicy; |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 95 | import java.util.List; |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 96 | import java.util.concurrent.atomic.AtomicBoolean; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 97 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 98 | /** |
| 99 | * Global state for the telephony subsystem when running in the primary |
| 100 | * phone process. |
| 101 | */ |
Sailesh Nepal | bf90054 | 2014-07-15 16:18:32 -0700 | [diff] [blame] | 102 | public class PhoneGlobals extends ContextWrapper { |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 103 | public static final String LOG_TAG = "PhoneGlobals"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * Phone app-wide debug level: |
| 107 | * 0 - no debug logging |
| 108 | * 1 - normal debug logging if ro.debuggable is set (which is true in |
| 109 | * "eng" and "userdebug" builds but not "user" builds) |
| 110 | * 2 - ultra-verbose debug logging |
| 111 | * |
| 112 | * Most individual classes in the phone app have a local DBG constant, |
| 113 | * typically set to |
| 114 | * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1) |
| 115 | * or else |
| 116 | * (PhoneApp.DBG_LEVEL >= 2) |
| 117 | * depending on the desired verbosity. |
| 118 | * |
| 119 | * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 ************* |
| 120 | */ |
Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 121 | public static final int DBG_LEVEL = 0; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 122 | |
| 123 | private static final boolean DBG = |
| 124 | (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); |
| 125 | private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 126 | |
| 127 | // Message codes; see mHandler below. |
| 128 | private static final int EVENT_SIM_NETWORK_LOCKED = 3; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | private static final int EVENT_SIM_STATE_CHANGED = 8; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 130 | private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10; |
Jordan Liu | ff2ccd7 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 131 | private static final int EVENT_DATA_ROAMING_CONNECTED = 11; |
| 132 | private static final int EVENT_DATA_ROAMING_OK = 12; |
| 133 | private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13; |
Jordan Liu | ff2ccd7 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 134 | private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15; |
| 135 | private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16; |
Lei Liu | 863eac0 | 2020-06-24 20:12:55 +0800 | [diff] [blame] | 136 | private static final int EVENT_CARRIER_CONFIG_CHANGED = 17; |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 137 | private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 18; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | |
| 139 | // The MMI codes are also used by the InCallScreen. |
| 140 | public static final int MMI_INITIATE = 51; |
| 141 | public static final int MMI_COMPLETE = 52; |
| 142 | public static final int MMI_CANCEL = 53; |
| 143 | // Don't use message codes larger than 99 here; those are reserved for |
| 144 | // the individual Activities of the Phone UI. |
| 145 | |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 146 | public static final int AIRPLANE_ON = 1; |
| 147 | public static final int AIRPLANE_OFF = 0; |
| 148 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 149 | /** |
| 150 | * Allowable values for the wake lock code. |
| 151 | * SLEEP means the device can be put to sleep. |
| 152 | * PARTIAL means wake the processor, but we display can be kept off. |
| 153 | * FULL means wake both the processor and the display. |
| 154 | */ |
| 155 | public enum WakeState { |
| 156 | SLEEP, |
| 157 | PARTIAL, |
| 158 | FULL |
| 159 | } |
| 160 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 161 | private static PhoneGlobals sMe; |
| 162 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 163 | CallManager mCM; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 164 | CallNotifier notifier; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 165 | NotificationMgr notificationMgr; |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 166 | TelephonyRcsService mTelephonyRcsService; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 167 | public PhoneInterfaceManager phoneMgr; |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 168 | public ImsRcsController imsRcsController; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 169 | public ImsStateCallbackController mImsStateCallbackController; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 170 | public ImsProvisioningController mImsProvisioningController; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 171 | CarrierConfigLoader configLoader; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 172 | |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 173 | private Phone phoneInEcm; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 174 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 175 | static boolean sVoiceCapable = true; |
| 176 | |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 177 | // TODO: Remove, no longer used. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 178 | CdmaPhoneCallState cdmaPhoneCallState; |
| 179 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 180 | // The currently-active PUK entry activity and progress dialog. |
| 181 | // Normally, these are the Emergency Dialer and the subsequent |
| 182 | // progress dialog. null if there is are no such objects in |
| 183 | // the foreground. |
| 184 | private Activity mPUKEntryActivity; |
| 185 | private ProgressDialog mPUKEntryProgressDialog; |
| 186 | |
Jordan Liu | ff2ccd7 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 187 | /** @hide */ |
| 188 | @Retention(RetentionPolicy.SOURCE) |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 189 | @IntDef(prefix = {"ROAMING_NOTIFICATION_REASON_"}, |
| 190 | value = { |
| 191 | ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED, |
| 192 | ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED, |
| 193 | ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED, |
| 194 | ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED, |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 195 | ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED, |
| 196 | ROAMING_NOTIFICATION_REASON_DISCONNECTED_SINGLE_NETWORK}) |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 197 | public @interface RoamingNotificationReason {} |
| 198 | private static final int ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED = 0; |
| 199 | private static final int ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED = 1; |
| 200 | private static final int ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED = 2; |
| 201 | private static final int ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED = 3; |
| 202 | private static final int ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED = 4; |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 203 | private static final int ROAMING_NOTIFICATION_REASON_DISCONNECTED_SINGLE_NETWORK = 5; |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 204 | |
| 205 | /** @hide */ |
| 206 | @Retention(RetentionPolicy.SOURCE) |
Jordan Liu | ff2ccd7 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 207 | @IntDef(prefix = {"ROAMING_NOTIFICATION_"}, |
| 208 | value = { |
| 209 | ROAMING_NOTIFICATION_NO_NOTIFICATION, |
| 210 | ROAMING_NOTIFICATION_CONNECTED, |
| 211 | ROAMING_NOTIFICATION_DISCONNECTED}) |
| 212 | public @interface RoamingNotification {} |
| 213 | |
| 214 | private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0; |
| 215 | private static final int ROAMING_NOTIFICATION_CONNECTED = 1; |
| 216 | private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2; |
| 217 | |
| 218 | @RoamingNotification |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 219 | private int mCurrentRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION; |
Jack Yu | 953f935 | 2017-05-18 14:41:06 -0700 | [diff] [blame] | 220 | |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 221 | /** |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 222 | * If true, update roaming notifications after the Internet is completely disconnected. If |
| 223 | * carrier allows only a single data network, wait until the Internet connection is completely |
| 224 | * disconnected and then update the roaming notification once more to check if |
| 225 | * ONLY_ALLOWED_SINGLE_NETWORK disallow reason is disappeared. |
| 226 | */ |
| 227 | private AtomicBoolean mWaitForInternetDisconnection = new AtomicBoolean(false); |
| 228 | |
| 229 | /** |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 230 | * Reasons that have already shown notification to prevent duplicate shows for the same reason. |
| 231 | */ |
| 232 | private ArraySet<String> mShownNotificationReasons = new ArraySet<>(); |
Ling Ma | 317906d | 2022-12-05 15:58:14 -0800 | [diff] [blame] | 233 | |
sangyun | 1c1918a | 2023-11-13 22:37:50 +0900 | [diff] [blame] | 234 | // For reorganize_roaming_notification feature disabled. |
| 235 | @RoamingNotification |
| 236 | private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION; |
| 237 | |
| 238 | // For reorganize_roaming_notification feature disabled. |
| 239 | /** Operator numerics for which we've shown is-roaming notifications. **/ |
| 240 | private ArraySet<String> mPrevRoamingOperatorNumerics = new ArraySet<>(); |
| 241 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 242 | private WakeState mWakeState = WakeState.SLEEP; |
| 243 | |
| 244 | private PowerManager mPowerManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 245 | private PowerManager.WakeLock mWakeLock; |
| 246 | private PowerManager.WakeLock mPartialWakeLock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 247 | private KeyguardManager mKeyguardManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 248 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 249 | private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
| 250 | private final LocalLog mDataRoamingNotifLog = new LocalLog(50); |
| 251 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 252 | // Broadcast receiver for various intent broadcasts (see onCreate()) |
| 253 | private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver(); |
| 254 | |
Ta-wei Yen | f0a71bc | 2017-05-17 12:28:28 -0700 | [diff] [blame] | 255 | private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver = |
| 256 | new CarrierVvmPackageInstalledReceiver(); |
| 257 | |
joonhunshin | 051ab23 | 2024-02-06 02:21:46 +0000 | [diff] [blame] | 258 | private SettingsObserver mSettingsObserver; |
Siim Sammul | 182d61b | 2021-05-04 16:01:42 +0100 | [diff] [blame] | 259 | private BinderCallsStats.SettingsObserver mBinderCallsSettingsObserver; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 260 | |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 261 | // Mapping of phone ID to the associated TelephonyCallback. These should be registered without |
| 262 | // fine or coarse location since we only use ServiceState for |
| 263 | private PhoneAppCallback[] mTelephonyCallbacks; |
| 264 | |
joonhunshin | 051ab23 | 2024-02-06 02:21:46 +0000 | [diff] [blame] | 265 | private FeatureFlags mFeatureFlags = new FeatureFlagsImpl(); |
sangyun | 15019e0 | 2023-11-13 21:50:15 +0900 | [diff] [blame] | 266 | |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 267 | private class PhoneAppCallback extends TelephonyCallback implements |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 268 | TelephonyCallback.ServiceStateListener, |
| 269 | TelephonyCallback.DataConnectionStateListener { |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 270 | private final int mSubId; |
| 271 | |
| 272 | PhoneAppCallback(int subId) { |
| 273 | mSubId = subId; |
| 274 | } |
| 275 | |
| 276 | @Override |
| 277 | public void onServiceStateChanged(ServiceState serviceState) { |
| 278 | // Note when registering that we should be registering with INCLUDE_LOCATION_DATA_NONE. |
| 279 | // PhoneGlobals only uses the state and roaming status, which does not require location. |
| 280 | handleServiceStateChanged(serviceState, mSubId); |
| 281 | } |
| 282 | |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 283 | @Override |
| 284 | public void onDataConnectionStateChanged(int state, int networkType) { |
| 285 | if (mSubId == mDefaultDataSubId && state == TelephonyManager.DATA_DISCONNECTED) { |
| 286 | // onDataConnectionStateChanged is an event about the state of exact DataNetwork, |
| 287 | // but since the DataNetwork of internet may not have been completely removed from |
| 288 | // the DataNetworkController list, The post handler event expects the internet data |
| 289 | // network to be completely removed from the DataNetworkController list. |
| 290 | mHandler.post(() -> { |
| 291 | if (mWaitForInternetDisconnection.compareAndSet(true, false)) { |
| 292 | Log.d(LOG_TAG, "onDisconnectedInternetDataNetwork."); |
| 293 | updateDataRoamingStatus( |
| 294 | ROAMING_NOTIFICATION_REASON_DISCONNECTED_SINGLE_NETWORK); |
| 295 | } |
| 296 | }); |
| 297 | } |
| 298 | } |
| 299 | |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 300 | public int getSubId() { |
| 301 | return mSubId; |
| 302 | } |
| 303 | } |
| 304 | |
Nazish Tabassum | 160d211 | 2019-12-23 17:31:33 +0530 | [diff] [blame] | 305 | private static class EventSimStateChangedBag { |
| 306 | final int mPhoneId; |
| 307 | final String mIccStatus; |
| 308 | |
| 309 | EventSimStateChangedBag(int phoneId, String iccStatus) { |
| 310 | mPhoneId = phoneId; |
| 311 | mIccStatus = iccStatus; |
| 312 | } |
| 313 | } |
| 314 | |
Jordan Liu | 06bdef1 | 2021-03-24 17:25:46 -0700 | [diff] [blame] | 315 | // Some carrier config settings disable the network lock screen, so we call handleSimLock |
| 316 | // when either SIM_LOCK or CARRIER_CONFIG changes so that no matter which one happens first, |
| 317 | // we still do the right thing |
| 318 | private void handleSimLock(int subType, Phone phone) { |
| 319 | PersistableBundle cc = getCarrierConfigForSubId(phone.getSubId()); |
| 320 | if (!CarrierConfigManager.isConfigForIdentifiedCarrier(cc)) { |
| 321 | // If we only have the default carrier config just return, to avoid popping up the |
| 322 | // the SIM lock screen when it's disabled by the carrier. |
| 323 | Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Carrier config not loaded"); |
| 324 | return; |
| 325 | } |
| 326 | if (cc.getBoolean(CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) { |
| 327 | // Some products don't have the concept of a "SIM network lock" |
| 328 | Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Disabled by carrier config"); |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | // if passed in subType is unknown, retrieve it here. |
| 333 | if (subType == -1) { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 334 | final UiccPort uiccPort = phone.getUiccPort(); |
| 335 | if (uiccPort == null) { |
Jordan Liu | 06bdef1 | 2021-03-24 17:25:46 -0700 | [diff] [blame] | 336 | Log.e(LOG_TAG, |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 337 | "handleSimLock: uiccPort for phone " + phone.getPhoneId() + " is null"); |
Jordan Liu | 06bdef1 | 2021-03-24 17:25:46 -0700 | [diff] [blame] | 338 | return; |
| 339 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 340 | final UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Jordan Liu | 06bdef1 | 2021-03-24 17:25:46 -0700 | [diff] [blame] | 341 | if (uiccProfile == null) { |
| 342 | Log.e(LOG_TAG, |
| 343 | "handleSimLock: uiccProfile for phone " + phone.getPhoneId() + " is null"); |
| 344 | return; |
| 345 | } |
| 346 | subType = uiccProfile.getApplication( |
| 347 | uiccProfile.mCurrentAppType).getPersoSubState().ordinal(); |
| 348 | } |
| 349 | // Normal case: show the "SIM network unlock" PIN entry screen. |
| 350 | // The user won't be able to do anything else until |
| 351 | // they enter a valid SIM network PIN. |
| 352 | Log.i(LOG_TAG, "show sim depersonal panel"); |
| 353 | IccNetworkDepersonalizationPanel.showDialog(phone, subType); |
| 354 | } |
| 355 | |
| 356 | private boolean isSimLocked(Phone phone) { |
| 357 | TelephonyManager tm = getSystemService(TelephonyManager.class); |
| 358 | return tm.createForSubscriptionId(phone.getSubId()).getSimState() |
| 359 | == TelephonyManager.SIM_STATE_NETWORK_LOCKED; |
| 360 | } |
| 361 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 362 | Handler mHandler = new Handler() { |
| 363 | @Override |
| 364 | public void handleMessage(Message msg) { |
| 365 | PhoneConstants.State phoneState; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 366 | if (VDBG) Log.v(LOG_TAG, "event=" + msg.what); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 367 | switch (msg.what) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 368 | // TODO: This event should be handled by the lock screen, just |
| 369 | // like the "SIM missing" and "Sim locked" cases (bug 1804111). |
| 370 | case EVENT_SIM_NETWORK_LOCKED: |
Jordan Liu | 06bdef1 | 2021-03-24 17:25:46 -0700 | [diff] [blame] | 371 | int subType = (Integer) ((AsyncResult) msg.obj).result; |
| 372 | Phone phone = (Phone) ((AsyncResult) msg.obj).userObj; |
| 373 | handleSimLock(subType, phone); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 374 | break; |
| 375 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 376 | case EVENT_DATA_ROAMING_DISCONNECTED: |
Aishwarya Mallampati | 05483bf | 2024-10-08 21:42:52 +0000 | [diff] [blame] | 377 | Log.d(LOG_TAG, "EVENT_DATA_ROAMING_DISCONNECTED"); |
Nagendra Prasad Nagarle Basavaraju | f668eda | 2024-02-15 15:02:57 +0000 | [diff] [blame] | 378 | if (SubscriptionManagerService.getInstance() |
| 379 | .isEsimBootStrapProvisioningActiveForSubId(msg.arg1)) { |
| 380 | Log.i(LOG_TAG, |
| 381 | "skip notification/warnings during esim bootstrap activation"); |
Aishwarya Mallampati | 05483bf | 2024-10-08 21:42:52 +0000 | [diff] [blame] | 382 | } else if (skipDataRoamingDisconnectedNotificationInSatelliteMode((msg.arg1))) { |
| 383 | Log.i(LOG_TAG, "skip data roaming disconnected notification when device is " |
| 384 | + "connected to satellite network that does not support data."); |
Nagendra Prasad Nagarle Basavaraju | f668eda | 2024-02-15 15:02:57 +0000 | [diff] [blame] | 385 | } else { |
Aishwarya Mallampati | 05483bf | 2024-10-08 21:42:52 +0000 | [diff] [blame] | 386 | notificationMgr.showDataRoamingNotification((msg.arg1), false); |
Nagendra Prasad Nagarle Basavaraju | f668eda | 2024-02-15 15:02:57 +0000 | [diff] [blame] | 387 | } |
Jordan Liu | ff2ccd7 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 388 | break; |
| 389 | |
| 390 | case EVENT_DATA_ROAMING_CONNECTED: |
Nagendra Prasad Nagarle Basavaraju | f668eda | 2024-02-15 15:02:57 +0000 | [diff] [blame] | 391 | if (SubscriptionManagerService.getInstance() |
| 392 | .isEsimBootStrapProvisioningActiveForSubId(msg.arg1)) { |
| 393 | Log.i(LOG_TAG, |
| 394 | "skip notification/warnings during esim bootstrap activation"); |
| 395 | } else { |
| 396 | notificationMgr.showDataRoamingNotification(msg.arg1, true); |
| 397 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 398 | break; |
| 399 | |
| 400 | case EVENT_DATA_ROAMING_OK: |
Jordan Liu | ff2ccd7 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 401 | notificationMgr.hideDataRoamingNotification(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 402 | break; |
| 403 | |
| 404 | case MMI_COMPLETE: |
| 405 | onMMIComplete((AsyncResult) msg.obj); |
| 406 | break; |
| 407 | |
| 408 | case MMI_CANCEL: |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 409 | PhoneUtils.cancelMmiCode(mCM.getFgPhone()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 410 | break; |
| 411 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 412 | case EVENT_SIM_STATE_CHANGED: |
Nazish Tabassum | 160d211 | 2019-12-23 17:31:33 +0530 | [diff] [blame] | 413 | EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj; |
Sarah Chin | 010884c | 2023-06-14 15:55:08 -0700 | [diff] [blame] | 414 | // Dismiss the "No services" notification if the SIM is removed. |
| 415 | if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) { |
| 416 | notificationMgr.dismissNetworkSelectionNotificationForInactiveSubId(); |
| 417 | } |
| 418 | |
| 419 | // Marks the event where the SIM goes into ready state. |
| 420 | // Right now, this is only used for the PUK-unlocking process. |
Tyler Gunn | 3fc09c0 | 2020-05-08 16:35:55 -0700 | [diff] [blame] | 421 | if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus) |
Nazish Tabassum | 59126a9 | 2020-07-03 21:44:49 +0530 | [diff] [blame] | 422 | || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus) |
| 423 | || IccCardConstants.INTENT_VALUE_ICC_NOT_READY.equals(bag.mIccStatus) |
| 424 | || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) { |
Sarah Chin | 010884c | 2023-06-14 15:55:08 -0700 | [diff] [blame] | 425 | // When the right event is triggered and there are UI objects in the |
| 426 | // foreground, we close them to display the lock panel. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 427 | if (mPUKEntryActivity != null) { |
Tyler Gunn | 3fc09c0 | 2020-05-08 16:35:55 -0700 | [diff] [blame] | 428 | Log.i(LOG_TAG, "Dismiss puk entry activity"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 429 | mPUKEntryActivity.finish(); |
| 430 | mPUKEntryActivity = null; |
| 431 | } |
| 432 | if (mPUKEntryProgressDialog != null) { |
Tyler Gunn | 3fc09c0 | 2020-05-08 16:35:55 -0700 | [diff] [blame] | 433 | Log.i(LOG_TAG, "Dismiss puk progress dialog"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 434 | mPUKEntryProgressDialog.dismiss(); |
| 435 | mPUKEntryProgressDialog = null; |
| 436 | } |
Nazish Tabassum | 59126a9 | 2020-07-03 21:44:49 +0530 | [diff] [blame] | 437 | Log.i(LOG_TAG, "Dismissing depersonal panel" + (bag.mIccStatus)); |
Nazish Tabassum | 160d211 | 2019-12-23 17:31:33 +0530 | [diff] [blame] | 438 | IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 439 | } |
| 440 | break; |
| 441 | |
| 442 | case EVENT_UNSOL_CDMA_INFO_RECORD: |
| 443 | //TODO: handle message here; |
| 444 | break; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 445 | case EVENT_DATA_ROAMING_SETTINGS_CHANGED: |
sangyun | 1c1918a | 2023-11-13 22:37:50 +0900 | [diff] [blame] | 446 | if (mFeatureFlags.reorganizeRoamingNotification()) { |
| 447 | updateDataRoamingStatus( |
| 448 | ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED); |
| 449 | } else { |
| 450 | updateDataRoamingStatusForFeatureDisabled(null); |
| 451 | } |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 452 | break; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 453 | case EVENT_MOBILE_DATA_SETTINGS_CHANGED: |
sangyun | 1c1918a | 2023-11-13 22:37:50 +0900 | [diff] [blame] | 454 | if (mFeatureFlags.reorganizeRoamingNotification()) { |
| 455 | updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED); |
| 456 | } else { |
| 457 | updateDataRoamingStatusForFeatureDisabled(null); |
| 458 | } |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 459 | break; |
Lei Liu | 863eac0 | 2020-06-24 20:12:55 +0800 | [diff] [blame] | 460 | case EVENT_CARRIER_CONFIG_CHANGED: |
| 461 | int subId = (Integer) msg.obj; |
| 462 | // The voicemail number could be overridden by carrier config, so need to |
| 463 | // refresh the message waiting (voicemail) indicator. |
| 464 | refreshMwiIndicator(subId); |
Jordan Liu | 06bdef1 | 2021-03-24 17:25:46 -0700 | [diff] [blame] | 465 | phone = getPhone(subId); |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 466 | if (phone != null) { |
| 467 | if (isSimLocked(phone)) { |
| 468 | // pass in subType=-1 so handleSimLock can find the actual subType if |
| 469 | // needed. This is safe as valid values for subType are >= 0 |
| 470 | handleSimLock(-1, phone); |
| 471 | } |
| 472 | TelephonyManager tm = getSystemService(TelephonyManager.class); |
| 473 | PhoneAppCallback callback = mTelephonyCallbacks[phone.getPhoneId()]; |
| 474 | // TODO: We may need to figure out a way to unregister if subId is invalid |
| 475 | tm.createForSubscriptionId(callback.getSubId()) |
| 476 | .unregisterTelephonyCallback(callback); |
| 477 | callback = new PhoneAppCallback(subId); |
| 478 | tm.createForSubscriptionId(subId).registerTelephonyCallback( |
Ling Ma | 317906d | 2022-12-05 15:58:14 -0800 | [diff] [blame] | 479 | TelephonyManager.INCLUDE_LOCATION_DATA_COARSE, mHandler::post, |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 480 | callback); |
| 481 | mTelephonyCallbacks[phone.getPhoneId()] = callback; |
| 482 | } |
| 483 | break; |
| 484 | case EVENT_MULTI_SIM_CONFIG_CHANGED: |
| 485 | int activeModems = (int) ((AsyncResult) msg.obj).result; |
| 486 | TelephonyManager tm = getSystemService(TelephonyManager.class); |
| 487 | // Unregister all previous callbacks |
| 488 | for (int phoneId = 0; phoneId < mTelephonyCallbacks.length; phoneId++) { |
| 489 | PhoneAppCallback callback = mTelephonyCallbacks[phoneId]; |
| 490 | if (callback != null) { |
| 491 | tm.createForSubscriptionId(callback.getSubId()) |
| 492 | .unregisterTelephonyCallback(callback); |
| 493 | mTelephonyCallbacks[phoneId] = null; |
| 494 | } |
| 495 | } |
| 496 | // Register callbacks for all active modems |
| 497 | for (int phoneId = 0; phoneId < activeModems; phoneId++) { |
| 498 | int sub = PhoneFactory.getPhone(phoneId).getSubId(); |
| 499 | PhoneAppCallback callback = new PhoneAppCallback(sub); |
| 500 | tm.createForSubscriptionId(sub).registerTelephonyCallback( |
| 501 | TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post, |
| 502 | callback); |
| 503 | mTelephonyCallbacks[phoneId] = callback; |
Jordan Liu | 06bdef1 | 2021-03-24 17:25:46 -0700 | [diff] [blame] | 504 | } |
Lei Liu | 863eac0 | 2020-06-24 20:12:55 +0800 | [diff] [blame] | 505 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | }; |
| 509 | |
| 510 | public PhoneGlobals(Context context) { |
| 511 | super(context); |
| 512 | sMe = this; |
joonhunshin | 051ab23 | 2024-02-06 02:21:46 +0000 | [diff] [blame] | 513 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 514 | if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { |
| 515 | mSettingsObserver = new SettingsObserver(context, mHandler); |
| 516 | } |
| 517 | } else { |
| 518 | mSettingsObserver = new SettingsObserver(context, mHandler); |
| 519 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | public void onCreate() { |
| 523 | if (VDBG) Log.v(LOG_TAG, "onCreate()..."); |
| 524 | |
| 525 | ContentResolver resolver = getContentResolver(); |
| 526 | |
Tomasz Wasilczyk | a856441 | 2024-05-23 13:30:23 -0700 | [diff] [blame] | 527 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 528 | && !getResources().getBoolean( |
| 529 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
joonhunshin | 051ab23 | 2024-02-06 02:21:46 +0000 | [diff] [blame] | 530 | if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { |
| 531 | Log.v(LOG_TAG, "onCreate()... but not defined FEATURE_TELEPHONY"); |
| 532 | return; |
| 533 | } |
| 534 | } |
| 535 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 536 | // Initialize the shim from frameworks/opt/telephony into packages/services/Telephony. |
| 537 | TelephonyLocalConnection.setInstance(new LocalConnectionImpl(this)); |
| 538 | |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 539 | TelephonyManager tm = getSystemService(TelephonyManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 540 | // Cache the "voice capable" flag. |
| 541 | // This flag currently comes from a resource (which is |
| 542 | // overrideable on a per-product basis): |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 543 | sVoiceCapable = tm.isVoiceCapable(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 544 | // ...but this might eventually become a PackageManager "system |
| 545 | // feature" instead, in which case we'd do something like: |
| 546 | // sVoiceCapable = |
| 547 | // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS); |
| 548 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 549 | if (mCM == null) { |
Nathan Harold | f9df6ea | 2019-03-08 11:54:22 -0800 | [diff] [blame] | 550 | // Initialize AnomalyReporter early so that it can be used |
| 551 | AnomalyReporter.initialize(this); |
Nathan Harold | 0db5c5e | 2019-01-22 20:18:56 -0800 | [diff] [blame] | 552 | |
Youming Ye | 47a6adc | 2018-11-19 15:33:36 -0800 | [diff] [blame] | 553 | // Inject telephony component factory if configured using other jars. |
| 554 | XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection); |
| 555 | TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser); |
Hwangoo Park | ba21cf2 | 2022-11-30 14:34:04 +0000 | [diff] [blame] | 556 | |
| 557 | // Create DomainSelectionResolver always, but it MUST be initialized only when |
| 558 | // the device supports AOSP domain selection architecture and |
| 559 | // has new IRadio that supports its related HAL APIs. |
Hwangoo Park | bf3968c | 2024-01-19 07:49:22 +0000 | [diff] [blame] | 560 | String dssComponentName = getResources().getString( |
| 561 | R.string.config_domain_selection_service_component_name); |
| 562 | DomainSelectionResolver.make(this, dssComponentName); |
Hwangoo Park | ba21cf2 | 2022-11-30 14:34:04 +0000 | [diff] [blame] | 563 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 564 | // Initialize the telephony framework |
sangyun | 15019e0 | 2023-11-13 21:50:15 +0900 | [diff] [blame] | 565 | PhoneFactory.makeDefaultPhones(this, mFeatureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 566 | |
Hwangoo Park | ba21cf2 | 2022-11-30 14:34:04 +0000 | [diff] [blame] | 567 | // Initialize the DomainSelectionResolver after creating the Phone instance |
| 568 | // to check the Radio HAL version. |
| 569 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
Hwangoo Park | bf3968c | 2024-01-19 07:49:22 +0000 | [diff] [blame] | 570 | DomainSelectionResolver.getInstance().initialize(); |
Daniel Banta | b26e96f | 2022-10-19 23:25:35 +0000 | [diff] [blame] | 571 | // Initialize EmergencyStateTracker if domain selection is supported |
| 572 | boolean isSuplDdsSwitchRequiredForEmergencyCall = getResources() |
| 573 | .getBoolean(R.bool.config_gnss_supl_requires_default_data_for_emergency); |
jaesikkong | 127483f | 2024-10-28 08:59:32 +0000 | [diff] [blame] | 574 | int inServiceWaitTimeWhenDialEccInApm = getResources().getInteger(R.integer |
| 575 | .config_in_service_wait_timer_when_dialing_emergency_routing_ecc_in_apm); |
yongnamcha | 2980ac0 | 2024-10-11 05:13:52 +0000 | [diff] [blame] | 576 | EmergencyStateTracker.make(this, isSuplDdsSwitchRequiredForEmergencyCall, |
jaesikkong | 127483f | 2024-10-28 08:59:32 +0000 | [diff] [blame] | 577 | inServiceWaitTimeWhenDialEccInApm, mFeatureFlags); |
Hunsuk Choi | c2e3fbc | 2024-05-10 05:05:17 +0000 | [diff] [blame] | 578 | DynamicRoutingController.getInstance().initialize(this); |
Hwangoo Park | ba21cf2 | 2022-11-30 14:34:04 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 581 | // Only bring up ImsResolver if the device supports having an IMS stack. |
| 582 | if (getPackageManager().hasSystemFeature( |
| 583 | PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 584 | // Get the package name of the default IMS implementation. |
| 585 | String defaultImsMmtelPackage = getResources().getString( |
| 586 | R.string.config_ims_mmtel_package); |
| 587 | String defaultImsRcsPackage = getResources().getString( |
| 588 | R.string.config_ims_rcs_package); |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 589 | ImsResolver.make(this, defaultImsMmtelPackage, |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 590 | defaultImsRcsPackage, PhoneFactory.getPhones().length, |
joonhunshin | 4244167 | 2024-04-26 01:26:14 +0000 | [diff] [blame] | 591 | new ImsFeatureBinderRepository(), mFeatureFlags); |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 592 | ImsResolver.getInstance().initialize(); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 593 | |
| 594 | // With the IMS phone created, load static config.xml values from the phone process |
| 595 | // so that it can be provided to the ImsPhoneCallTracker. |
| 596 | for (Phone p : PhoneFactory.getPhones()) { |
| 597 | Phone imsPhone = p.getImsPhone(); |
| 598 | if (imsPhone != null && imsPhone instanceof ImsPhone) { |
| 599 | ImsPhone theImsPhone = (ImsPhone) imsPhone; |
| 600 | if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) { |
| 601 | ImsPhoneCallTracker ict = (ImsPhoneCallTracker) |
| 602 | theImsPhone.getCallTracker(); |
| 603 | |
| 604 | ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config(); |
| 605 | config.isD2DCommunicationSupported = getResources().getBoolean( |
| 606 | R.bool.config_use_device_to_device_communication); |
| 607 | ict.setConfig(config); |
| 608 | } |
| 609 | } |
| 610 | } |
Jack Yu | 4a0c538 | 2024-09-05 23:03:20 -0700 | [diff] [blame] | 611 | RcsProvisioningMonitor.make(this, mFeatureFlags); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 612 | } |
| 613 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 614 | // Start TelephonyDebugService After the default phone is created. |
| 615 | Intent intent = new Intent(this, TelephonyDebugService.class); |
| 616 | startService(intent); |
| 617 | |
| 618 | mCM = CallManager.getInstance(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 619 | |
| 620 | // Create the NotificationMgr singleton, which is used to display |
| 621 | // status bar icons and control other status bar behavior. |
| 622 | notificationMgr = NotificationMgr.init(this); |
| 623 | |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 624 | // Create the SatelliteController singleton, which acts as a backend service for |
| 625 | // {@link android.telephony.satellite.SatelliteManager}. |
sangyun | 15019e0 | 2023-11-13 21:50:15 +0900 | [diff] [blame] | 626 | SatelliteController.make(this, mFeatureFlags); |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 627 | |
Anthony Lee | 03ebdfc | 2015-07-27 08:12:02 -0700 | [diff] [blame] | 628 | // Create an instance of CdmaPhoneCallState and initialize it to IDLE |
| 629 | cdmaPhoneCallState = new CdmaPhoneCallState(); |
| 630 | cdmaPhoneCallState.CdmaPhoneCallStateInit(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 631 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 632 | // before registering for phone state changes |
| 633 | mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 634 | mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG); |
| 635 | // lock used to keep the processor awake, when we don't care for the display. |
| 636 | mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK |
| 637 | | PowerManager.ON_AFTER_RELEASE, LOG_TAG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 638 | |
| 639 | mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); |
| 640 | |
sangyun | 15019e0 | 2023-11-13 21:50:15 +0900 | [diff] [blame] | 641 | phoneMgr = PhoneInterfaceManager.init(this, mFeatureFlags); |
Santos Cordon | 406c034 | 2013-08-28 00:07:47 -0700 | [diff] [blame] | 642 | |
joonhunshin | 2c33ed9 | 2023-12-12 14:29:23 +0000 | [diff] [blame] | 643 | imsRcsController = ImsRcsController.init(this, mFeatureFlags); |
James.cf Lin | af3183c | 2019-10-24 00:59:00 +0800 | [diff] [blame] | 644 | |
joonhunshin | 21a8681 | 2023-12-10 08:21:25 +0000 | [diff] [blame] | 645 | configLoader = CarrierConfigLoader.init(this, mFeatureFlags); |
Brad Ebinger | 6c53e7f | 2023-01-27 16:26:44 -0800 | [diff] [blame] | 646 | |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 647 | if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 648 | mImsStateCallbackController = |
joonhunshin | 7da71b8 | 2024-07-17 05:20:47 +0000 | [diff] [blame] | 649 | ImsStateCallbackController.make(this, PhoneFactory.getPhones().length, |
| 650 | mFeatureFlags); |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 651 | mTelephonyRcsService = new TelephonyRcsService(this, |
joonhunshin | d9dfe8d | 2024-02-05 09:08:06 +0000 | [diff] [blame] | 652 | PhoneFactory.getPhones().length, mFeatureFlags); |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 653 | mTelephonyRcsService.initialize(); |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 654 | imsRcsController.setRcsService(mTelephonyRcsService); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 655 | mImsProvisioningController = |
joonhunshin | 711a887 | 2024-03-19 10:04:08 +0000 | [diff] [blame] | 656 | ImsProvisioningController.make(this, PhoneFactory.getPhones().length, |
| 657 | mFeatureFlags); |
James.cf Lin | c9f35a4 | 2020-01-15 02:35:22 +0800 | [diff] [blame] | 658 | } |
| 659 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 660 | // Create the CallNotifier singleton, which handles |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 661 | // asynchronous events from the telephony layer (like |
| 662 | // launching the incoming-call UI when an incoming call comes |
| 663 | // in.) |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 664 | notifier = CallNotifier.init(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 665 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 666 | PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 667 | |
| 668 | // register for MMI/USSD |
| 669 | mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null); |
| 670 | |
Qiong Liu | cc3fe81 | 2019-09-23 15:25:44 +0800 | [diff] [blame] | 671 | // Initialize cell status using current airplane mode. |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 672 | handleAirplaneModeChange( |
| 673 | Settings.Global.getInt( |
| 674 | getContentResolver(), |
| 675 | Settings.Global.AIRPLANE_MODE_ON, |
| 676 | AIRPLANE_OFF) |
| 677 | == AIRPLANE_ON); |
Qiong Liu | cc3fe81 | 2019-09-23 15:25:44 +0800 | [diff] [blame] | 678 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 679 | // Register for misc other intent broadcasts. |
| 680 | IntentFilter intentFilter = |
| 681 | new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 682 | intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
| 683 | intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 684 | intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 685 | intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); |
| 686 | intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 687 | registerReceiver(mReceiver, intentFilter); |
Jack Yu | ec14422 | 2023-12-13 16:03:03 -0800 | [diff] [blame] | 688 | int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId(); |
| 689 | if (SubscriptionManager.isValidSubscriptionId(defaultDataSubId)) { |
| 690 | if (VDBG) { |
| 691 | Log.v(LOG_TAG, "Loaded initial default data sub: " + defaultDataSubId); |
sangyun | 15019e0 | 2023-11-13 21:50:15 +0900 | [diff] [blame] | 692 | } |
Jack Yu | ec14422 | 2023-12-13 16:03:03 -0800 | [diff] [blame] | 693 | mDefaultDataSubId = defaultDataSubId; |
| 694 | registerSettingsObserver(); |
| 695 | updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED); |
sangyun | dce559b | 2023-09-11 10:25:55 +0900 | [diff] [blame] | 696 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 697 | |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 698 | PhoneConfigurationManager.registerForMultiSimConfigChange( |
| 699 | mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED, null); |
| 700 | |
| 701 | mTelephonyCallbacks = new PhoneAppCallback[tm.getSupportedModemCount()]; |
Fangyuan Li | 7f5c275 | 2022-06-29 18:02:31 +0800 | [diff] [blame] | 702 | if (tm.getSupportedModemCount() > 0) { |
| 703 | for (Phone phone : PhoneFactory.getPhones()) { |
| 704 | int subId = phone.getSubId(); |
| 705 | PhoneAppCallback callback = new PhoneAppCallback(subId); |
| 706 | tm.createForSubscriptionId(subId).registerTelephonyCallback( |
| 707 | TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post, callback); |
| 708 | mTelephonyCallbacks[phone.getPhoneId()] = callback; |
| 709 | } |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 710 | } |
Ta-wei Yen | f0a71bc | 2017-05-17 12:28:28 -0700 | [diff] [blame] | 711 | mCarrierVvmPackageInstalledReceiver.register(this); |
| 712 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 713 | //set the default values for the preferences in the phone. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 714 | PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 717 | // XXX pre-load the SimProvider so that it's ready |
| 718 | resolver.getType(Uri.parse("content://icc/adn")); |
| 719 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 720 | // TODO: Register for Cdma Information Records |
| 721 | // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null); |
| 722 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 723 | // Read HAC settings and configure audio hardware |
| 724 | if (getResources().getBoolean(R.bool.hac_enabled)) { |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 725 | int hac = android.provider.Settings.System.getInt( |
| 726 | getContentResolver(), |
| 727 | android.provider.Settings.System.HEARING_AID, |
| 728 | 0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 729 | AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
Jordan Liu | f71aeef | 2019-08-21 11:46:09 -0700 | [diff] [blame] | 730 | audioManager.setParameters( |
| 731 | SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED |
| 732 | ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 733 | } |
Siim Sammul | 182d61b | 2021-05-04 16:01:42 +0100 | [diff] [blame] | 734 | |
| 735 | // Start tracking Binder latency for the phone process. |
| 736 | mBinderCallsSettingsObserver = new BinderCallsStats.SettingsObserver( |
| 737 | getApplicationContext(), |
Siim Sammul | a695009 | 2021-06-22 17:14:03 +0100 | [diff] [blame] | 738 | new BinderCallsStats( |
| 739 | new BinderCallsStats.Injector(), |
| 740 | com.android.internal.os.BinderLatencyProto.Dims.TELEPHONY)); |
Santos Cordon | ff506f5 | 2013-11-21 19:13:19 -0800 | [diff] [blame] | 741 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 742 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 743 | /** |
| 744 | * Returns the singleton instance of the PhoneApp. |
| 745 | */ |
Sailesh Nepal | 1eaf22b | 2014-02-22 17:00:49 -0800 | [diff] [blame] | 746 | public static PhoneGlobals getInstance() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 747 | if (sMe == null) { |
| 748 | throw new IllegalStateException("No PhoneGlobals here!"); |
| 749 | } |
| 750 | return sMe; |
| 751 | } |
| 752 | |
| 753 | /** |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 754 | * Returns the default phone. |
| 755 | * |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 756 | * WARNING: This method should be used carefully, now that there may be multiple phones. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 757 | */ |
Andrew Lee | 83383e4 | 2014-10-31 12:42:28 -0700 | [diff] [blame] | 758 | public static Phone getPhone() { |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 759 | return PhoneFactory.getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 762 | public static Phone getPhone(int subId) { |
| 763 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 764 | } |
| 765 | |
Santos Cordon | de10b75 | 2013-09-19 04:11:33 -0700 | [diff] [blame] | 766 | /* package */ CallManager getCallManager() { |
| 767 | return mCM; |
| 768 | } |
| 769 | |
Chris Manton | 4e9fa91 | 2015-06-19 11:26:57 -0700 | [diff] [blame] | 770 | public PersistableBundle getCarrierConfig() { |
Shishir Agrawal | d3480e0 | 2016-01-25 13:05:49 -0800 | [diff] [blame] | 771 | return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId()); |
Jonathan Basseri | 89b0ab4 | 2015-05-01 10:52:40 -0700 | [diff] [blame] | 772 | } |
| 773 | |
Chris Manton | 4e9fa91 | 2015-06-19 11:26:57 -0700 | [diff] [blame] | 774 | public PersistableBundle getCarrierConfigForSubId(int subId) { |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 775 | return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(), |
| 776 | getAttributionTag()); |
Junda Liu | 605148f | 2015-04-28 15:23:40 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 779 | private void registerSettingsObserver() { |
| 780 | mSettingsObserver.unobserve(); |
| 781 | String dataRoamingSetting = Settings.Global.DATA_ROAMING; |
| 782 | String mobileDataSetting = Settings.Global.MOBILE_DATA; |
| 783 | if (TelephonyManager.getDefault().getSimCount() > 1) { |
| 784 | int subId = mDefaultDataSubId; |
| 785 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 786 | dataRoamingSetting += subId; |
| 787 | mobileDataSetting += subId; |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | // Listen for user data roaming setting changed event |
| 792 | mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting), |
| 793 | EVENT_DATA_ROAMING_SETTINGS_CHANGED); |
| 794 | |
| 795 | // Listen for mobile data setting changed event |
| 796 | mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting), |
| 797 | EVENT_MOBILE_DATA_SETTINGS_CHANGED); |
| 798 | } |
| 799 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 800 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 801 | * Sets the activity responsible for un-PUK-blocking the device |
| 802 | * so that we may close it when we receive a positive result. |
| 803 | * mPUKEntryActivity is also used to indicate to the device that |
| 804 | * we are trying to un-PUK-lock the phone. In other words, iff |
| 805 | * it is NOT null, then we are trying to unlock and waiting for |
| 806 | * the SIM to move to READY state. |
| 807 | * |
| 808 | * @param activity is the activity to close when PUK has |
| 809 | * finished unlocking. Can be set to null to indicate the unlock |
| 810 | * or SIM READYing process is over. |
| 811 | */ |
| 812 | void setPukEntryActivity(Activity activity) { |
Tyler Gunn | 3fc09c0 | 2020-05-08 16:35:55 -0700 | [diff] [blame] | 813 | Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity")); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 814 | mPUKEntryActivity = activity; |
| 815 | } |
| 816 | |
| 817 | Activity getPUKEntryActivity() { |
| 818 | return mPUKEntryActivity; |
| 819 | } |
| 820 | |
| 821 | /** |
| 822 | * Sets the dialog responsible for notifying the user of un-PUK- |
| 823 | * blocking - SIM READYing progress, so that we may dismiss it |
| 824 | * when we receive a positive result. |
| 825 | * |
| 826 | * @param dialog indicates the progress dialog informing the user |
| 827 | * of the state of the device. Dismissed upon completion of |
| 828 | * READYing process |
| 829 | */ |
| 830 | void setPukEntryProgressDialog(ProgressDialog dialog) { |
Tyler Gunn | 3fc09c0 | 2020-05-08 16:35:55 -0700 | [diff] [blame] | 831 | Log.i(LOG_TAG, "setPukEntryProgressDialog - set to " |
| 832 | + (dialog == null ? "null" : "activity")); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 833 | mPUKEntryProgressDialog = dialog; |
| 834 | } |
| 835 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 836 | KeyguardManager getKeyguardManager() { |
| 837 | return mKeyguardManager; |
| 838 | } |
| 839 | |
| 840 | private void onMMIComplete(AsyncResult r) { |
| 841 | if (VDBG) Log.d(LOG_TAG, "onMMIComplete()..."); |
| 842 | MmiCode mmiCode = (MmiCode) r.result; |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 843 | PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 844 | } |
| 845 | |
fionaxu | 8012697 | 2017-02-01 17:01:26 -0800 | [diff] [blame] | 846 | private void initForNewRadioTechnology() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 847 | if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology..."); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 848 | notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 851 | private void handleAirplaneModeChange(boolean isAirplaneNewlyOn) { |
Sarah Chin | 9ec6e1e | 2022-08-10 13:29:40 -0700 | [diff] [blame] | 852 | Log.i(LOG_TAG, "handleAirplaneModeChange: isAirplaneNewlyOn=" + isAirplaneNewlyOn); |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 853 | int cellState = |
| 854 | Settings.Global.getInt( |
| 855 | getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG); |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 856 | switch (cellState) { |
| 857 | case PhoneConstants.CELL_OFF_FLAG: |
Sarah Chin | 9ec6e1e | 2022-08-10 13:29:40 -0700 | [diff] [blame] | 858 | // Airplane mode does not affect the cell radio if user has turned it off. |
| 859 | Log.i(LOG_TAG, "Ignore airplane mode change due to cell off."); |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 860 | break; |
| 861 | case PhoneConstants.CELL_ON_FLAG: |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 862 | maybeTurnCellOff(isAirplaneNewlyOn); |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 863 | break; |
| 864 | case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG: |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 865 | maybeTurnCellOn(isAirplaneNewlyOn); |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 866 | break; |
| 867 | } |
Hall Liu | 7f56e1a | 2019-07-10 14:41:14 -0700 | [diff] [blame] | 868 | for (Phone phone : PhoneFactory.getPhones()) { |
| 869 | phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn); |
| 870 | } |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | /* |
| 874 | * Returns true if the radio must be turned off when entering airplane mode. |
| 875 | */ |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 876 | private boolean isCellOffInAirplaneMode() { |
| 877 | String airplaneModeRadios = |
| 878 | Settings.Global.getString( |
| 879 | getContentResolver(), Settings.Global.AIRPLANE_MODE_RADIOS); |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 880 | return airplaneModeRadios == null |
| 881 | || airplaneModeRadios.contains(Settings.Global.RADIO_CELL); |
| 882 | } |
| 883 | |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 884 | private void setRadioPowerOff() { |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 885 | Log.i(LOG_TAG, "Turning radio off - airplane"); |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 886 | Settings.Global.putInt( |
| 887 | getContentResolver(), |
| 888 | Settings.Global.CELL_ON, |
| 889 | PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG); |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 890 | Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0); |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 891 | TelephonyProperties.airplane_mode_on(true); // true means int value 1 |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 892 | PhoneUtils.setRadioPower(false); |
Ling Ma | 317906d | 2022-12-05 15:58:14 -0800 | [diff] [blame] | 893 | clearCacheOnRadioOff(); |
| 894 | } |
| 895 | |
| 896 | /** Clear fields on power off radio **/ |
| 897 | private void clearCacheOnRadioOff() { |
| 898 | // Re-show is-roaming notifications after APM mode |
sangyun | 1c1918a | 2023-11-13 22:37:50 +0900 | [diff] [blame] | 899 | if (mFeatureFlags.reorganizeRoamingNotification()) { |
| 900 | mShownNotificationReasons.clear(); |
| 901 | } else { |
| 902 | mPrevRoamingOperatorNumerics.clear(); |
| 903 | } |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 904 | } |
| 905 | |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 906 | private void setRadioPowerOn() { |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 907 | Log.i(LOG_TAG, "Turning radio on - airplane"); |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 908 | Settings.Global.putInt( |
| 909 | getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG); |
| 910 | Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1); |
Meng Wang | 6130762 | 2019-10-23 14:08:43 -0700 | [diff] [blame] | 911 | TelephonyProperties.airplane_mode_on(false); // false means int value 0 |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 912 | PhoneUtils.setRadioPower(true); |
| 913 | } |
| 914 | |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 915 | private void maybeTurnCellOff(boolean isAirplaneNewlyOn) { |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 916 | if (isAirplaneNewlyOn) { |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 917 | // If we are trying to turn off the radio, make sure there are no active |
| 918 | // emergency calls. If there are, switch airplane mode back to off. |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 919 | TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE); |
Tyler Gunn | 900d8fd | 2018-09-21 09:22:12 -0700 | [diff] [blame] | 920 | |
| 921 | if (tm != null && tm.isInEmergencyCall()) { |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 922 | // Switch airplane mode back to off. |
Jordan Liu | 0e819b1 | 2019-08-28 15:33:05 -0700 | [diff] [blame] | 923 | ConnectivityManager cm = |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 924 | (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); |
Jordan Liu | 0e819b1 | 2019-08-28 15:33:05 -0700 | [diff] [blame] | 925 | cm.setAirplaneMode(false); |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 926 | Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG) |
| 927 | .show(); |
| 928 | Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off"); |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 929 | } else if (isCellOffInAirplaneMode()) { |
| 930 | setRadioPowerOff(); |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 931 | } else { |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 932 | Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off"); |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 933 | } |
Sarah Chin | 9ec6e1e | 2022-08-10 13:29:40 -0700 | [diff] [blame] | 934 | } else { |
| 935 | Log.i(LOG_TAG, "Ignoring airplane mode: not newly on"); |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 939 | private void maybeTurnCellOn(boolean isAirplaneNewlyOn) { |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 940 | if (!isAirplaneNewlyOn) { |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 941 | setRadioPowerOn(); |
Sarah Chin | 9ec6e1e | 2022-08-10 13:29:40 -0700 | [diff] [blame] | 942 | } else { |
| 943 | Log.i(LOG_TAG, "Ignoring airplane mode off: radio is already on."); |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 944 | } |
| 945 | } |
| 946 | |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 947 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 948 | * Receiver for misc intent broadcasts the Phone app cares about. |
| 949 | */ |
| 950 | private class PhoneAppBroadcastReceiver extends BroadcastReceiver { |
| 951 | @Override |
| 952 | public void onReceive(Context context, Intent intent) { |
| 953 | String action = intent.getAction(); |
| 954 | if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) { |
Taesu Lee | 3dc572b | 2020-08-07 18:16:22 +0900 | [diff] [blame] | 955 | boolean airplaneMode = intent.getBooleanExtra("state", false); |
Taesu Lee | 62f826d | 2020-08-10 16:01:18 +0900 | [diff] [blame] | 956 | handleAirplaneModeChange(airplaneMode); |
Amit Mahajan | f5d92c8 | 2018-11-02 17:44:40 -0700 | [diff] [blame] | 957 | } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { |
| 958 | // re-register as it may be a new IccCard |
| 959 | int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, |
| 960 | SubscriptionManager.INVALID_PHONE_INDEX); |
| 961 | if (SubscriptionManager.isValidPhoneId(phoneId)) { |
| 962 | PhoneUtils.unregisterIccStatus(mHandler, phoneId); |
| 963 | PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId); |
| 964 | } |
Nazish Tabassum | 160d211 | 2019-12-23 17:31:33 +0530 | [diff] [blame] | 965 | String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); |
| 966 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED, |
| 967 | new EventSimStateChangedBag(phoneId, iccStatus))); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 968 | } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) { |
| 969 | String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY); |
fionaxu | 8012697 | 2017-02-01 17:01:26 -0800 | [diff] [blame] | 970 | Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active."); |
| 971 | initForNewRadioTechnology(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 972 | } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) { |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 973 | int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0); |
Srikanth Chintala | 079912a | 2016-03-03 16:35:01 +0530 | [diff] [blame] | 974 | phoneInEcm = PhoneFactory.getPhone(phoneId); |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 975 | Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId); |
| 976 | if (phoneInEcm != null) { |
| 977 | if (TelephonyCapabilities.supportsEcm(phoneInEcm)) { |
| 978 | Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp."); |
| 979 | // Start Emergency Callback Mode service |
Daniel Bright | 30efde4 | 2020-01-09 22:11:15 -0800 | [diff] [blame] | 980 | if (intent.getBooleanExtra( |
| 981 | TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) { |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 982 | context.startService(new Intent(context, |
| 983 | EmergencyCallbackModeService.class)); |
| 984 | } else { |
| 985 | phoneInEcm = null; |
| 986 | } |
| 987 | } else { |
| 988 | // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED |
| 989 | // on a device that doesn't support ECM in the first place. |
| 990 | Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but " |
| 991 | + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName()); |
| 992 | phoneInEcm = null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 993 | } |
| 994 | } else { |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 995 | Log.w(LOG_TAG, "phoneInEcm is null."); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 996 | } |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 997 | } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) { |
| 998 | // Roaming status could be overridden by carrier config, so we need to update it. |
| 999 | if (VDBG) Log.v(LOG_TAG, "carrier config changed."); |
sangyun | 1c1918a | 2023-11-13 22:37:50 +0900 | [diff] [blame] | 1000 | if (mFeatureFlags.reorganizeRoamingNotification()) { |
| 1001 | updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED); |
| 1002 | } else { |
| 1003 | updateDataRoamingStatusForFeatureDisabled(null); |
| 1004 | } |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 1005 | updateLimitedSimFunctionForDualSim(); |
Lei Liu | 863eac0 | 2020-06-24 20:12:55 +0800 | [diff] [blame] | 1006 | int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, |
| 1007 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
| 1008 | if (SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1009 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED, |
| 1010 | new Integer(subId))); |
| 1011 | } |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 1012 | } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) { |
| 1013 | // We also need to pay attention when default data subscription changes. |
| 1014 | if (VDBG) Log.v(LOG_TAG, "default data sub changed."); |
| 1015 | mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId(); |
| 1016 | registerSettingsObserver(); |
| 1017 | Phone phone = getPhone(mDefaultDataSubId); |
| 1018 | if (phone != null) { |
sangyun | 1c1918a | 2023-11-13 22:37:50 +0900 | [diff] [blame] | 1019 | if (mFeatureFlags.reorganizeRoamingNotification()) { |
| 1020 | updateDataRoamingStatus( |
| 1021 | ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED); |
| 1022 | } else { |
| 1023 | updateDataRoamingStatusForFeatureDisabled(null); |
| 1024 | } |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 1025 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | } |
| 1029 | |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 1030 | private void handleServiceStateChanged(ServiceState serviceState, int subId) { |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 1031 | if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged"); |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 1032 | int state = serviceState.getState(); |
| 1033 | notificationMgr.updateNetworkSelection(state, subId); |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 1034 | |
Sarah Chin | 072ffb2 | 2022-05-03 17:58:59 -0700 | [diff] [blame] | 1035 | if (VDBG) { |
| 1036 | Log.v(LOG_TAG, "subId=" + subId + ", mDefaultDataSubId=" |
| 1037 | + mDefaultDataSubId + ", ss roaming=" + serviceState.getDataRoaming()); |
| 1038 | } |
| 1039 | if (subId == mDefaultDataSubId) { |
sangyun | 1c1918a | 2023-11-13 22:37:50 +0900 | [diff] [blame] | 1040 | if (mFeatureFlags.reorganizeRoamingNotification()) { |
| 1041 | updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED); |
| 1042 | } else { |
| 1043 | updateDataRoamingStatusForFeatureDisabled(serviceState.getOperatorNumeric()); |
| 1044 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1045 | } |
| 1046 | } |
| 1047 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 1048 | /** |
| 1049 | * When roaming, if mobile data cannot be established due to data roaming not enabled, we need |
| 1050 | * to notify the user so they can enable it through settings. Vise versa if the condition |
| 1051 | * changes, we need to dismiss the notification. |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 1052 | * @param notificationReason to inform which event is called for notification update. |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 1053 | */ |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 1054 | private void updateDataRoamingStatus(@RoamingNotificationReason int notificationReason) { |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 1055 | Phone phone = getPhone(mDefaultDataSubId); |
| 1056 | if (phone == null) { |
| 1057 | Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId); |
| 1058 | return; |
| 1059 | } |
| 1060 | |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1061 | ServiceState serviceState = phone.getServiceState(); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 1062 | if (serviceState == null) { |
| 1063 | Log.e(LOG_TAG, "updateDataRoamingStatus: serviceState is null"); |
| 1064 | return; |
| 1065 | } |
| 1066 | |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 1067 | List<DataDisallowedReason> disallowReasons = phone.getDataNetworkController() |
| 1068 | .getInternetDataDisallowedReasons(); |
| 1069 | |
| 1070 | if (mFeatureFlags.roamingNotificationForSingleDataNetwork()) { |
| 1071 | if (disallowReasons.contains(DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK) |
| 1072 | && disallowReasons.contains(DataDisallowedReason.ROAMING_DISABLED) |
| 1073 | && (notificationReason == ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED |
| 1074 | || notificationReason |
| 1075 | == ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED)) { |
| 1076 | // If the ONLY_ALLOWED_SINGLE_NETWORK disallow reason has not yet been removed due |
| 1077 | // to a change in mobile_data (including roaming_data) settings, update roaming |
| 1078 | // notification again after the Internet is completely disconnected to check |
| 1079 | // ONLY_ALLOWED_SINGLE_NETWORK disallow reason is removed. |
| 1080 | mWaitForInternetDisconnection.set(true); |
| 1081 | Log.d(LOG_TAG, "updateDataRoamingStatus," |
| 1082 | + " wait for internet disconnection for single data network"); |
| 1083 | } else if (!disallowReasons.contains(DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK) |
| 1084 | && mWaitForInternetDisconnection.compareAndSet(true, false)) { |
| 1085 | // If the ONLY_ALLOWED_SINGLE_NETWORK disallow reason has been removed, |
| 1086 | // no longer wait for Internet disconnection. |
| 1087 | Log.d(LOG_TAG, "updateDataRoamingStatus," |
| 1088 | + " cancel to wait for internet disconnection for single data network"); |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | updateDataRoamingStatus(notificationReason, disallowReasons, serviceState); |
| 1093 | } |
| 1094 | |
| 1095 | /** |
| 1096 | * When roaming, if mobile data cannot be established due to data roaming not enabled, we need |
| 1097 | * to notify the user so they can enable it through settings. Vise versa if the condition |
| 1098 | * changes, we need to dismiss the notification. |
| 1099 | * @param notificationReason to inform which event is called for notification update. |
| 1100 | * @param disallowReasons List of reasons why internet data is not allowed. An empty list if |
| 1101 | * internet is allowed. |
| 1102 | * @param serviceState Service state from phone |
| 1103 | */ |
| 1104 | private void updateDataRoamingStatus(@RoamingNotificationReason int notificationReason, |
| 1105 | List<DataDisallowedReason> disallowReasons, ServiceState serviceState) { |
| 1106 | |
| 1107 | if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus"); |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1108 | String roamingNumeric = serviceState.getOperatorNumeric(); |
| 1109 | String roamingNumericReason = "RoamingNumeric=" + roamingNumeric; |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 1110 | String callingReason = "CallingReason=" + notificationReason; |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1111 | boolean dataIsNowRoaming = serviceState.getDataRoaming(); |
Jack Yu | 3e2ac6e | 2022-03-26 13:59:45 -0700 | [diff] [blame] | 1112 | boolean dataAllowed; |
| 1113 | boolean notAllowedDueToRoamingOff; |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 1114 | dataAllowed = disallowReasons.isEmpty(); |
| 1115 | notAllowedDueToRoamingOff = (disallowReasons.size() == 1 |
| 1116 | && disallowReasons.contains(DataDisallowedReason.ROAMING_DISABLED)); |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1117 | StringBuilder sb = new StringBuilder("updateDataRoamingStatus"); |
| 1118 | sb.append(" dataAllowed=").append(dataAllowed); |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 1119 | sb.append(", disallowReasons=").append(disallowReasons); |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1120 | sb.append(", dataIsNowRoaming=").append(dataIsNowRoaming); |
| 1121 | sb.append(", ").append(roamingNumericReason); |
| 1122 | sb.append(", ").append(callingReason); |
| 1123 | mDataRoamingNotifLog.log(sb.toString()); |
Ling Ma | 317906d | 2022-12-05 15:58:14 -0800 | [diff] [blame] | 1124 | if (VDBG) { |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1125 | Log.v(LOG_TAG, sb.toString()); |
Ling Ma | 317906d | 2022-12-05 15:58:14 -0800 | [diff] [blame] | 1126 | } |
Jack Yu | 3e2ac6e | 2022-03-26 13:59:45 -0700 | [diff] [blame] | 1127 | |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1128 | // Determine if a given roaming numeric has never been shown. |
| 1129 | boolean shownInThisNumeric = false; |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 1130 | if (notificationReason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED |
| 1131 | || notificationReason == ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED) { |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1132 | shownInThisNumeric = mShownNotificationReasons.contains(roamingNumericReason); |
| 1133 | } |
| 1134 | // Determine if a notification has never been shown by given calling reason. |
| 1135 | boolean shownForThisReason = mShownNotificationReasons.contains(callingReason); |
| 1136 | |
Jack Yu | 3e2ac6e | 2022-03-26 13:59:45 -0700 | [diff] [blame] | 1137 | if (!dataAllowed && notAllowedDueToRoamingOff) { |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1138 | if (!shownInThisNumeric && roamingNumeric != null) { |
| 1139 | mShownNotificationReasons.add(roamingNumericReason); |
| 1140 | } |
| 1141 | if (!shownForThisReason |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 1142 | && notificationReason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) { |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1143 | mShownNotificationReasons.add(callingReason); |
Ling Ma | 4e15c32 | 2022-12-07 11:20:53 -0800 | [diff] [blame] | 1144 | } |
Jordan Liu | ff2ccd7 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 1145 | // No need to show it again if we never cancelled it explicitly. |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1146 | if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_DISCONNECTED) { |
| 1147 | return; |
| 1148 | } |
| 1149 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 1150 | // If the only reason of no data is data roaming disabled, then we notify the user |
| 1151 | // so the user can turn on data roaming. |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1152 | if (!shownInThisNumeric && !shownForThisReason) { |
| 1153 | updateDataRoamingNotification(ROAMING_NOTIFICATION_DISCONNECTED); |
| 1154 | } else { |
| 1155 | // Don't show roaming notification if we've already shown for this MccMnc |
| 1156 | Log.d(LOG_TAG, "Skip roaming disconnected notification since already" |
| 1157 | + " shownInThisNumeric=" + shownInThisNumeric |
| 1158 | + " shownForThisReason=" + shownForThisReason); |
| 1159 | // Dismiss notification if the other notification is shown. |
| 1160 | if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) { |
| 1161 | updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION); |
| 1162 | } |
| 1163 | } |
| 1164 | } else if (dataAllowed && dataIsNowRoaming) { |
| 1165 | if (!shownInThisNumeric && roamingNumeric != null) { |
| 1166 | mShownNotificationReasons.add(roamingNumericReason); |
| 1167 | } |
| 1168 | if (!shownForThisReason |
sangyun | d2cfeaa | 2024-03-31 12:20:40 +0900 | [diff] [blame] | 1169 | && notificationReason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) { |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1170 | mShownNotificationReasons.add(callingReason); |
| 1171 | } |
Sarah Chin | 37b3907 | 2023-11-05 13:28:21 -0800 | [diff] [blame] | 1172 | boolean shouldShowRoamingNotification = shouldShowRoamingNotification(roamingNumeric); |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1173 | // No need to show it again if we never cancelled it explicitly. |
| 1174 | if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_CONNECTED) { |
Ling Ma | 4e15c32 | 2022-12-07 11:20:53 -0800 | [diff] [blame] | 1175 | return; |
| 1176 | } |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1177 | |
| 1178 | // Inform users that roaming charges may apply. |
Sarah Chin | 37b3907 | 2023-11-05 13:28:21 -0800 | [diff] [blame] | 1179 | if (!shownInThisNumeric && !shownForThisReason && shouldShowRoamingNotification) { |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1180 | updateDataRoamingNotification(ROAMING_NOTIFICATION_CONNECTED); |
| 1181 | } else { |
| 1182 | // Don't show roaming notification if we've already shown for this MccMnc or |
| 1183 | // disabled from carrier config. |
| 1184 | Log.d(LOG_TAG, "Skip roaming connected notification since already" |
| 1185 | + " shownInThisNumeric:" + shownInThisNumeric |
| 1186 | + " shownForThisReason:" + shownForThisReason |
Sarah Chin | 37b3907 | 2023-11-05 13:28:21 -0800 | [diff] [blame] | 1187 | + " shouldShowRoamingNotification:" + shouldShowRoamingNotification); |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1188 | // Dismiss notification if the other notification is shown. |
| 1189 | if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) { |
| 1190 | updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION); |
| 1191 | } |
| 1192 | } |
| 1193 | } else if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) { |
Jordan Liu | ff2ccd7 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 1194 | // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED |
| 1195 | // is not the only data disable reason. In this case we dismiss the notification we |
| 1196 | // showed earlier. |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1197 | updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION); |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 1198 | } |
| 1199 | } |
| 1200 | |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1201 | private void updateDataRoamingNotification(@RoamingNotification int roamingNotification) { |
| 1202 | int event; |
| 1203 | switch (roamingNotification) { |
| 1204 | case ROAMING_NOTIFICATION_NO_NOTIFICATION: |
| 1205 | Log.d(LOG_TAG, "Dismiss roaming notification"); |
| 1206 | mDataRoamingNotifLog.log("Hide roaming."); |
| 1207 | event = EVENT_DATA_ROAMING_OK; |
| 1208 | break; |
| 1209 | case ROAMING_NOTIFICATION_CONNECTED: |
| 1210 | Log.d(LOG_TAG, "Show roaming connected notification"); |
| 1211 | mDataRoamingNotifLog.log("Show roaming on."); |
| 1212 | event = EVENT_DATA_ROAMING_CONNECTED; |
| 1213 | break; |
| 1214 | case ROAMING_NOTIFICATION_DISCONNECTED: |
| 1215 | Log.d(LOG_TAG, "Show roaming disconnected notification"); |
| 1216 | mDataRoamingNotifLog.log("Show roaming off."); |
| 1217 | event = EVENT_DATA_ROAMING_DISCONNECTED; |
| 1218 | break; |
| 1219 | default: |
| 1220 | Log.d(LOG_TAG, "Should never reach here."); |
| 1221 | mDataRoamingNotifLog.log("Should never reach here."); |
| 1222 | return; |
| 1223 | } |
| 1224 | mCurrentRoamingNotification = roamingNotification; |
| 1225 | mHandler.obtainMessage(event, mDefaultDataSubId, 0).sendToTarget(); |
| 1226 | } |
| 1227 | |
| 1228 | private @RoamingNotification int getCurrentRoamingNotification() { |
| 1229 | return mCurrentRoamingNotification; |
| 1230 | } |
| 1231 | |
sangyun | 1c1918a | 2023-11-13 22:37:50 +0900 | [diff] [blame] | 1232 | // For reorganize_roaming_notification feature disabled. |
| 1233 | /** |
| 1234 | * When roaming, if mobile data cannot be established due to data roaming not enabled, we need |
| 1235 | * to notify the user so they can enable it through settings. Vise versa if the condition |
| 1236 | * changes, we need to dismiss the notification. |
| 1237 | * @param roamingOperatorNumeric The operator numeric for the current roaming. {@code null} if |
| 1238 | * the current roaming operator numeric didn't change. |
| 1239 | */ |
| 1240 | private void updateDataRoamingStatusForFeatureDisabled( |
| 1241 | @Nullable String roamingOperatorNumeric) { |
| 1242 | if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatusForFeatureDisabled"); |
| 1243 | Phone phone = getPhone(mDefaultDataSubId); |
| 1244 | if (phone == null) { |
| 1245 | Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId); |
| 1246 | return; |
| 1247 | } |
| 1248 | |
| 1249 | boolean dataAllowed; |
| 1250 | boolean notAllowedDueToRoamingOff; |
| 1251 | List<DataDisallowedReason> reasons = phone.getDataNetworkController() |
| 1252 | .getInternetDataDisallowedReasons(); |
| 1253 | dataAllowed = reasons.isEmpty(); |
| 1254 | notAllowedDueToRoamingOff = (reasons.size() == 1 |
| 1255 | && reasons.contains(DataDisallowedReason.ROAMING_DISABLED)); |
| 1256 | mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons |
| 1257 | + ", roamingOperatorNumeric=" + roamingOperatorNumeric); |
| 1258 | if (VDBG) { |
| 1259 | Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons |
| 1260 | + ", roamingOperatorNumeric=" + roamingOperatorNumeric); |
| 1261 | } |
| 1262 | |
| 1263 | if (!dataAllowed && notAllowedDueToRoamingOff) { |
| 1264 | // Don't show roaming notification if we've already shown for this MccMnc |
| 1265 | if (roamingOperatorNumeric != null |
| 1266 | && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) { |
| 1267 | Log.d(LOG_TAG, "Skip roaming disconnected notification since already shown in " |
| 1268 | + "MccMnc " + roamingOperatorNumeric); |
| 1269 | return; |
| 1270 | } |
| 1271 | // No need to show it again if we never cancelled it explicitly. |
| 1272 | if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return; |
| 1273 | // If the only reason of no data is data roaming disabled, then we notify the user |
| 1274 | // so the user can turn on data roaming. |
| 1275 | mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED; |
| 1276 | Log.d(LOG_TAG, "Show roaming disconnected notification"); |
| 1277 | mDataRoamingNotifLog.log("Show roaming off."); |
| 1278 | Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED); |
| 1279 | msg.arg1 = mDefaultDataSubId; |
| 1280 | msg.sendToTarget(); |
| 1281 | } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)) { |
sangyun | 5abbf7e | 2024-02-01 00:47:30 +0900 | [diff] [blame] | 1282 | if (!shouldShowRoamingNotification(roamingOperatorNumeric != null |
| 1283 | ? roamingOperatorNumeric : phone.getServiceState().getOperatorNumeric())) { |
Sarah Chin | 37b3907 | 2023-11-05 13:28:21 -0800 | [diff] [blame] | 1284 | Log.d(LOG_TAG, "Skip showing roaming connected notification."); |
| 1285 | return; |
| 1286 | } |
sangyun | 1c1918a | 2023-11-13 22:37:50 +0900 | [diff] [blame] | 1287 | // Don't show roaming notification if we've already shown for this MccMnc |
| 1288 | if (roamingOperatorNumeric != null |
| 1289 | && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) { |
| 1290 | Log.d(LOG_TAG, "Skip roaming connected notification since already shown in " |
| 1291 | + "MccMnc " + roamingOperatorNumeric); |
| 1292 | return; |
| 1293 | } |
| 1294 | // No need to show it again if we never cancelled it explicitly, or carrier config |
| 1295 | // indicates this is not needed. |
| 1296 | if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return; |
| 1297 | mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED; |
| 1298 | Log.d(LOG_TAG, "Show roaming connected notification"); |
| 1299 | mDataRoamingNotifLog.log("Show roaming on."); |
| 1300 | Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED); |
| 1301 | msg.arg1 = mDefaultDataSubId; |
| 1302 | msg.sendToTarget(); |
| 1303 | } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) { |
| 1304 | // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED |
| 1305 | // is not the only data disable reason. In this case we dismiss the notification we |
| 1306 | // showed earlier. |
| 1307 | mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION; |
| 1308 | Log.d(LOG_TAG, "Dismiss roaming notification"); |
| 1309 | mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed); |
| 1310 | mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK); |
| 1311 | } |
| 1312 | } |
| 1313 | |
Jordan Liu | ff2ccd7 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 1314 | /** |
| 1315 | * |
| 1316 | * @param subId to check roaming on |
| 1317 | * @return whether we have transitioned to dataRoaming |
| 1318 | */ |
| 1319 | private boolean dataIsNowRoaming(int subId) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 1320 | return getPhone(subId).getServiceState().getDataRoaming(); |
Jordan Liu | ff2ccd7 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
Sarah Chin | 37b3907 | 2023-11-05 13:28:21 -0800 | [diff] [blame] | 1323 | private boolean shouldShowRoamingNotification(String roamingNumeric) { |
| 1324 | PersistableBundle config = getCarrierConfigForSubId(mDefaultDataSubId); |
| 1325 | boolean showRoamingNotification = config.getBoolean( |
| 1326 | CarrierConfigManager.KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL); |
| 1327 | |
| 1328 | if (TextUtils.isEmpty(roamingNumeric) || !mFeatureFlags.hideRoamingIcon()) { |
| 1329 | Log.d(LOG_TAG, "shouldShowRoamingNotification: roamingNumeric=" + roamingNumeric |
| 1330 | + ", hideRoaming=" + mFeatureFlags.hideRoamingIcon()); |
| 1331 | return showRoamingNotification; |
| 1332 | } |
| 1333 | |
| 1334 | String[] includedMccMncs = config.getStringArray(CarrierConfigManager |
| 1335 | .KEY_DATA_CONNECTED_ROAMING_NOTIFICATION_INCLUDED_MCC_MNCS_STRING_ARRAY); |
| 1336 | if (includedMccMncs != null) { |
| 1337 | for (String mccMnc : includedMccMncs) { |
| 1338 | if (roamingNumeric.equals(mccMnc)) { |
| 1339 | Log.d(LOG_TAG, "shouldShowRoamingNotification: show for MCC/MNC " + mccMnc); |
| 1340 | return showRoamingNotification; |
| 1341 | } |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | String[] excludedMccs = config.getStringArray(CarrierConfigManager |
| 1346 | .KEY_DATA_CONNECTED_ROAMING_NOTIFICATION_EXCLUDED_MCCS_STRING_ARRAY); |
| 1347 | String roamingMcc = roamingNumeric.length() < 3 ? "" : roamingNumeric.substring(0, 3); |
| 1348 | if (excludedMccs != null && !TextUtils.isEmpty(roamingMcc)) { |
| 1349 | for (String mcc : excludedMccs) { |
| 1350 | if (roamingMcc.equals(mcc)) { |
| 1351 | Log.d(LOG_TAG, "shouldShowRoamingNotification: ignore for MCC " + mcc); |
| 1352 | return false; |
| 1353 | } |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | if (showRoamingNotification) { |
| 1358 | Log.d(LOG_TAG, "shouldShowRoamingNotification: show for numeric " + roamingNumeric); |
| 1359 | } |
| 1360 | return showRoamingNotification; |
| 1361 | } |
| 1362 | |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 1363 | private void updateLimitedSimFunctionForDualSim() { |
| 1364 | if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim"); |
| 1365 | // check conditions to display limited SIM function notification under dual SIM |
| 1366 | SubscriptionManager subMgr = (SubscriptionManager) getSystemService( |
| 1367 | Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 1368 | List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false); |
| 1369 | if (subList != null && subList.size() > 1) { |
| 1370 | CarrierConfigManager configMgr = (CarrierConfigManager) |
| 1371 | getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| 1372 | for (SubscriptionInfo info : subList) { |
| 1373 | PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId()); |
| 1374 | if (b != null) { |
| 1375 | if (b.getBoolean(CarrierConfigManager |
| 1376 | .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) { |
| 1377 | notificationMgr.showLimitedSimFunctionWarningNotification( |
| 1378 | info.getSubscriptionId(), |
| 1379 | info.getDisplayName().toString()); |
| 1380 | } else { |
| 1381 | notificationMgr.dismissLimitedSimFunctionWarningNotification( |
| 1382 | info.getSubscriptionId()); |
| 1383 | } |
| 1384 | } |
| 1385 | } |
| 1386 | } else { |
| 1387 | // cancel notifications for all subs |
| 1388 | notificationMgr.dismissLimitedSimFunctionWarningNotification( |
| 1389 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
| 1390 | } |
| 1391 | notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs(); |
| 1392 | |
| 1393 | } |
| 1394 | |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 1395 | public Phone getPhoneInEcm() { |
| 1396 | return phoneInEcm; |
| 1397 | } |
| 1398 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1399 | /** |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 1400 | * Triggers a refresh of the message waiting (voicemail) indicator. |
| 1401 | * |
| 1402 | * @param subId the subscription id we should refresh the notification for. |
| 1403 | */ |
| 1404 | public void refreshMwiIndicator(int subId) { |
| 1405 | notificationMgr.refreshMwi(subId); |
| 1406 | } |
| 1407 | |
| 1408 | /** |
Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1409 | * Called when the network selection on the subscription {@code subId} is changed by the user. |
| 1410 | * |
| 1411 | * @param subId the subscription id. |
| 1412 | */ |
| 1413 | public void onNetworkSelectionChanged(int subId) { |
| 1414 | Phone phone = getPhone(subId); |
| 1415 | if (phone != null) { |
| 1416 | notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId); |
| 1417 | } else { |
| 1418 | Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId); |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | /** |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 1423 | * @return whether the device supports RCS User Capability Exchange or not. |
| 1424 | */ |
| 1425 | public boolean getDeviceUceEnabled() { |
| 1426 | return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled(); |
| 1427 | } |
| 1428 | |
| 1429 | /** |
| 1430 | * Set the device supports RCS User Capability Exchange. |
| 1431 | * @param isEnabled true if the device supports UCE. |
| 1432 | */ |
| 1433 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 1434 | if (mTelephonyRcsService != null) { |
| 1435 | mTelephonyRcsService.setDeviceUceEnabled(isEnabled); |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | /** |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 1440 | * Dump the state of the object, add calls to other objects as desired. |
| 1441 | * |
| 1442 | * @param fd File descriptor |
| 1443 | * @param printWriter Print writer |
| 1444 | * @param args Arguments |
| 1445 | */ |
| 1446 | public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) { |
| 1447 | IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " "); |
| 1448 | pw.println("------- PhoneGlobals -------"); |
| 1449 | pw.increaseIndent(); |
sangyun | 15019e0 | 2023-11-13 21:50:15 +0900 | [diff] [blame] | 1450 | pw.println("FeatureFlags:"); |
| 1451 | pw.increaseIndent(); |
sangyun | 1c1918a | 2023-11-13 22:37:50 +0900 | [diff] [blame] | 1452 | pw.println("reorganizeRoamingNotification=" |
| 1453 | + mFeatureFlags.reorganizeRoamingNotification()); |
sangyun | d5f37ab | 2023-11-13 22:52:28 +0900 | [diff] [blame] | 1454 | pw.println("dismissNetworkSelectionNotificationOnSimDisable=" |
| 1455 | + mFeatureFlags.dismissNetworkSelectionNotificationOnSimDisable()); |
sangyun | 15019e0 | 2023-11-13 21:50:15 +0900 | [diff] [blame] | 1456 | pw.decreaseIndent(); |
sangyun | 1c1918a | 2023-11-13 22:37:50 +0900 | [diff] [blame] | 1457 | if (mFeatureFlags.reorganizeRoamingNotification()) { |
| 1458 | pw.println("mCurrentRoamingNotification=" + mCurrentRoamingNotification); |
| 1459 | } else { |
| 1460 | pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification); |
| 1461 | } |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 1462 | pw.println("mDefaultDataSubId=" + mDefaultDataSubId); |
Keun young Park | debb853 | 2019-05-30 16:35:27 -0700 | [diff] [blame] | 1463 | pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable()); |
sangyun | 35f23f8 | 2023-07-18 01:37:53 +0900 | [diff] [blame] | 1464 | pw.println("mDataRoamingNotifLog:"); |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 1465 | pw.increaseIndent(); |
| 1466 | mDataRoamingNotifLog.dump(fd, pw, args); |
| 1467 | pw.decreaseIndent(); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1468 | pw.println("ImsResolver:"); |
| 1469 | pw.increaseIndent(); |
| 1470 | try { |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 1471 | if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1472 | } catch (Exception e) { |
| 1473 | e.printStackTrace(); |
| 1474 | } |
| 1475 | pw.decreaseIndent(); |
Brad Ebinger | a68a497 | 2020-01-30 17:31:23 -0800 | [diff] [blame] | 1476 | pw.println("RcsService:"); |
| 1477 | try { |
| 1478 | if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args); |
| 1479 | } catch (Exception e) { |
| 1480 | e.printStackTrace(); |
| 1481 | } |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 1482 | pw.println("ImsStateCallbackController:"); |
| 1483 | try { |
| 1484 | if (mImsStateCallbackController != null) mImsStateCallbackController.dump(pw); |
| 1485 | } catch (Exception e) { |
| 1486 | e.printStackTrace(); |
| 1487 | } |
Hwangoo Park | ba21cf2 | 2022-11-30 14:34:04 +0000 | [diff] [blame] | 1488 | pw.println("DomainSelectionResolver:"); |
| 1489 | pw.increaseIndent(); |
| 1490 | try { |
| 1491 | if (DomainSelectionResolver.getInstance() != null) { |
| 1492 | DomainSelectionResolver.getInstance().dump(fd, pw, args); |
| 1493 | } |
| 1494 | } catch (Exception e) { |
| 1495 | e.printStackTrace(); |
| 1496 | } |
| 1497 | pw.decreaseIndent(); |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 1498 | pw.decreaseIndent(); |
sangyun | 1c1918a | 2023-11-13 22:37:50 +0900 | [diff] [blame] | 1499 | if (mFeatureFlags.reorganizeRoamingNotification()) { |
| 1500 | pw.println("mShownNotificationReasons=" + mShownNotificationReasons); |
| 1501 | } else { |
| 1502 | pw.println("mPrevRoamingOperatorNumerics:" + mPrevRoamingOperatorNumerics); |
| 1503 | } |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 1504 | pw.println("------- End PhoneGlobals -------"); |
| 1505 | } |
Aishwarya Mallampati | 05483bf | 2024-10-08 21:42:52 +0000 | [diff] [blame] | 1506 | |
| 1507 | private boolean skipDataRoamingDisconnectedNotificationInSatelliteMode(int subId) { |
| 1508 | SatelliteController satelliteController = SatelliteController.getInstance(); |
| 1509 | if (satelliteController.isSatelliteEnabledOrBeingEnabled()) { |
| 1510 | Log.d(LOG_TAG, "skipDataRoamingDisconnected - skip notification as " |
| 1511 | + "satellite is enabled or being enabled"); |
| 1512 | return true; |
| 1513 | } |
| 1514 | |
| 1515 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 1516 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1517 | ServiceState serviceState = phone.getServiceState(); |
| 1518 | if (serviceState != null && serviceState.isUsingNonTerrestrialNetwork()) { |
| 1519 | Log.d(LOG_TAG, "skipDataRoamingDisconnected - isUsingNtn"); |
| 1520 | List<Integer> capabilities = |
| 1521 | satelliteController.getCapabilitiesForCarrierRoamingSatelliteMode(phone); |
| 1522 | if (!capabilities.contains(NetworkRegistrationInfo.SERVICE_TYPE_DATA)) { |
| 1523 | // Skip data roaming disconnected notification as device is connected to |
| 1524 | // non-terrestrial network that does not support data. |
| 1525 | Log.d(LOG_TAG, "skipDataRoamingDisconnected - skip notification as " |
| 1526 | + "NTN does not support data"); |
| 1527 | return true; |
| 1528 | } |
| 1529 | } |
| 1530 | |
| 1531 | Log.d(LOG_TAG, "skipDataRoamingDisconnected - do not skip notification."); |
| 1532 | return false; |
| 1533 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1534 | } |