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