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