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