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