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