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