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