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