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; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 44 | import android.telephony.CarrierConfigManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.telephony.ServiceState; |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 46 | import android.telephony.SubscriptionManager; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 47 | import android.telephony.TelephonyManager; |
| 48 | import android.util.LocalLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.util.Log; |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 50 | import android.widget.Toast; |
Ta-wei Yen | b29425b | 2016-09-21 17:28:14 -0700 | [diff] [blame] | 51 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import com.android.internal.telephony.Call; |
| 53 | import com.android.internal.telephony.CallManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import com.android.internal.telephony.IccCardConstants; |
| 55 | import com.android.internal.telephony.MmiCode; |
| 56 | import com.android.internal.telephony.Phone; |
| 57 | import com.android.internal.telephony.PhoneConstants; |
| 58 | import com.android.internal.telephony.PhoneFactory; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 59 | import com.android.internal.telephony.SettingsObserver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 60 | import com.android.internal.telephony.TelephonyCapabilities; |
| 61 | import com.android.internal.telephony.TelephonyIntents; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 62 | import com.android.internal.telephony.dataconnection.DataConnectionReasons; |
| 63 | import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType; |
| 64 | import com.android.internal.util.IndentingPrintWriter; |
Santos Cordon | 352ff65 | 2014-05-30 01:41:45 -0700 | [diff] [blame] | 65 | import com.android.phone.common.CallLogAsync; |
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 | 533c6c1 | 2017-08-02 11:38:48 -0700 | [diff] [blame^] | 68 | import com.android.services.telephony.sip.SipBroadcastReceiver; |
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 | |
| 137 | // A few important fields we expose to the rest of the package |
| 138 | // directly (rather than thru set/get methods) for efficiency. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 139 | CallController callController; |
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 | |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 147 | private CallGatewayManager callGatewayManager; |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 148 | private Phone phoneInEcm; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 149 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 150 | static boolean sVoiceCapable = true; |
| 151 | |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 152 | // TODO: Remove, no longer used. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 153 | CdmaPhoneCallState cdmaPhoneCallState; |
| 154 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 155 | // The currently-active PUK entry activity and progress dialog. |
| 156 | // Normally, these are the Emergency Dialer and the subsequent |
| 157 | // progress dialog. null if there is are no such objects in |
| 158 | // the foreground. |
| 159 | private Activity mPUKEntryActivity; |
| 160 | private ProgressDialog mPUKEntryProgressDialog; |
| 161 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 162 | private boolean mNoDataDueToRoaming = false; |
Jack Yu | 953f935 | 2017-05-18 14:41:06 -0700 | [diff] [blame] | 163 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 164 | private WakeState mWakeState = WakeState.SLEEP; |
| 165 | |
| 166 | private PowerManager mPowerManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 167 | private PowerManager.WakeLock mWakeLock; |
| 168 | private PowerManager.WakeLock mPartialWakeLock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 169 | private KeyguardManager mKeyguardManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 170 | |
| 171 | private UpdateLock mUpdateLock; |
| 172 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 173 | private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
| 174 | private final LocalLog mDataRoamingNotifLog = new LocalLog(50); |
| 175 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 176 | // Broadcast receiver for various intent broadcasts (see onCreate()) |
| 177 | private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver(); |
Brad Ebinger | 533c6c1 | 2017-08-02 11:38:48 -0700 | [diff] [blame^] | 178 | // Broadcast receiver for SIP based intents (see onCreate()) |
| 179 | private final SipBroadcastReceiver mSipBroadcastReceiver = new SipBroadcastReceiver(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 180 | |
Ta-wei Yen | f0a71bc | 2017-05-17 12:28:28 -0700 | [diff] [blame] | 181 | private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver = |
| 182 | new CarrierVvmPackageInstalledReceiver(); |
| 183 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 184 | private final SettingsObserver mSettingsObserver; |
| 185 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 186 | Handler mHandler = new Handler() { |
| 187 | @Override |
| 188 | public void handleMessage(Message msg) { |
| 189 | PhoneConstants.State phoneState; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 190 | if (VDBG) Log.v(LOG_TAG, "event=" + msg.what); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 191 | switch (msg.what) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 | // TODO: This event should be handled by the lock screen, just |
| 193 | // like the "SIM missing" and "Sim locked" cases (bug 1804111). |
| 194 | case EVENT_SIM_NETWORK_LOCKED: |
Jonathan Basseri | 9504c6b | 2015-06-04 14:23:32 -0700 | [diff] [blame] | 195 | if (getCarrierConfig().getBoolean( |
| 196 | CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 197 | // Some products don't have the concept of a "SIM network lock" |
| 198 | Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; " |
| 199 | + "not showing 'SIM network unlock' PIN entry screen"); |
| 200 | } else { |
| 201 | // Normal case: show the "SIM network unlock" PIN entry screen. |
| 202 | // The user won't be able to do anything else until |
| 203 | // they enter a valid SIM network PIN. |
| 204 | Log.i(LOG_TAG, "show sim depersonal panel"); |
Tyler Gunn | 52a3707 | 2015-08-24 14:23:19 -0700 | [diff] [blame] | 205 | IccNetworkDepersonalizationPanel.showDialog(); |
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: |
| 210 | notificationMgr.showDataDisconnectedRoaming(); |
| 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. |
| 229 | if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) { |
| 230 | // when the right event is triggered and there |
| 231 | // are UI objects in the foreground, we close |
| 232 | // them to display the lock panel. |
| 233 | if (mPUKEntryActivity != null) { |
| 234 | mPUKEntryActivity.finish(); |
| 235 | mPUKEntryActivity = null; |
| 236 | } |
| 237 | if (mPUKEntryProgressDialog != null) { |
| 238 | mPUKEntryProgressDialog.dismiss(); |
| 239 | mPUKEntryProgressDialog = null; |
| 240 | } |
| 241 | } |
| 242 | break; |
| 243 | |
| 244 | case EVENT_UNSOL_CDMA_INFO_RECORD: |
| 245 | //TODO: handle message here; |
| 246 | break; |
Brad Ebinger | 3fa4346 | 2016-04-12 16:06:48 -0700 | [diff] [blame] | 247 | case EVENT_RESTART_SIP: |
| 248 | // This should only run if the Phone process crashed and was restarted. We do |
| 249 | // not want this running if the device is still in the FBE encrypted state. |
| 250 | // This is the same procedure that is triggered in the SipBroadcastReceiver |
| 251 | // upon BOOT_COMPLETED. |
| 252 | UserManager userManager = UserManager.get(sMe); |
| 253 | if (userManager != null && userManager.isUserUnlocked()) { |
| 254 | SipUtil.startSipService(); |
| 255 | } |
| 256 | break; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 257 | case EVENT_DATA_ROAMING_SETTINGS_CHANGED: |
| 258 | case EVENT_MOBILE_DATA_SETTINGS_CHANGED: |
| 259 | updateDataRoamingStatus(); |
| 260 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | }; |
| 264 | |
| 265 | public PhoneGlobals(Context context) { |
| 266 | super(context); |
| 267 | sMe = this; |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 268 | mSettingsObserver = new SettingsObserver(context, mHandler); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | public void onCreate() { |
| 272 | if (VDBG) Log.v(LOG_TAG, "onCreate()..."); |
| 273 | |
| 274 | ContentResolver resolver = getContentResolver(); |
| 275 | |
| 276 | // Cache the "voice capable" flag. |
| 277 | // This flag currently comes from a resource (which is |
| 278 | // overrideable on a per-product basis): |
| 279 | sVoiceCapable = |
| 280 | getResources().getBoolean(com.android.internal.R.bool.config_voice_capable); |
| 281 | // ...but this might eventually become a PackageManager "system |
| 282 | // feature" instead, in which case we'd do something like: |
| 283 | // sVoiceCapable = |
| 284 | // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS); |
| 285 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 286 | if (mCM == null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 287 | // Initialize the telephony framework |
| 288 | PhoneFactory.makeDefaultPhones(this); |
| 289 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 290 | // Start TelephonyDebugService After the default phone is created. |
| 291 | Intent intent = new Intent(this, TelephonyDebugService.class); |
| 292 | startService(intent); |
| 293 | |
| 294 | mCM = CallManager.getInstance(); |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 295 | for (Phone phone : PhoneFactory.getPhones()) { |
| 296 | mCM.registerPhone(phone); |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 297 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 298 | |
| 299 | // Create the NotificationMgr singleton, which is used to display |
| 300 | // status bar icons and control other status bar behavior. |
| 301 | notificationMgr = NotificationMgr.init(this); |
| 302 | |
Brad Ebinger | 3fa4346 | 2016-04-12 16:06:48 -0700 | [diff] [blame] | 303 | // If PhoneGlobals has crashed and is being restarted, then restart. |
| 304 | mHandler.sendEmptyMessage(EVENT_RESTART_SIP); |
| 305 | |
Anthony Lee | 03ebdfc | 2015-07-27 08:12:02 -0700 | [diff] [blame] | 306 | // Create an instance of CdmaPhoneCallState and initialize it to IDLE |
| 307 | cdmaPhoneCallState = new CdmaPhoneCallState(); |
| 308 | cdmaPhoneCallState.CdmaPhoneCallStateInit(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 309 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 310 | // before registering for phone state changes |
| 311 | mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 312 | mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG); |
| 313 | // lock used to keep the processor awake, when we don't care for the display. |
| 314 | mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK |
| 315 | | PowerManager.ON_AFTER_RELEASE, LOG_TAG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 316 | |
| 317 | mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); |
| 318 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 319 | // Get UpdateLock to suppress system-update related events (e.g. dialog show-up) |
| 320 | // during phone calls. |
| 321 | mUpdateLock = new UpdateLock("phone"); |
| 322 | |
| 323 | if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock); |
| 324 | |
| 325 | CallLogger callLogger = new CallLogger(this, new CallLogAsync()); |
| 326 | |
Jay Shrauner | 21a7534 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 327 | callGatewayManager = CallGatewayManager.getInstance(); |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 328 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 329 | // Create the CallController singleton, which is the interface |
| 330 | // to the telephony layer for user-initiated telephony functionality |
| 331 | // (like making outgoing calls.) |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 332 | callController = CallController.init(this, callLogger, callGatewayManager); |
| 333 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 334 | // Create the CallerInfoCache singleton, which remembers custom ring tone and |
| 335 | // send-to-voicemail settings. |
| 336 | // |
| 337 | // The asynchronous caching will start just after this call. |
| 338 | callerInfoCache = CallerInfoCache.init(this); |
| 339 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 340 | phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone()); |
Santos Cordon | 406c034 | 2013-08-28 00:07:47 -0700 | [diff] [blame] | 341 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 342 | configLoader = CarrierConfigLoader.init(this); |
| 343 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 344 | // Create the CallNotifier singleton, which handles |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 345 | // asynchronous events from the telephony layer (like |
| 346 | // launching the incoming-call UI when an incoming call comes |
| 347 | // in.) |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 348 | notifier = CallNotifier.init(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 349 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 350 | PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 351 | |
| 352 | // register for MMI/USSD |
| 353 | mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null); |
| 354 | |
| 355 | // register connection tracking to PhoneUtils |
| 356 | PhoneUtils.initializeConnectionHandler(mCM); |
| 357 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 358 | // Register for misc other intent broadcasts. |
| 359 | IntentFilter intentFilter = |
| 360 | new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 361 | intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
| 362 | intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED); |
| 363 | intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
| 364 | intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 365 | intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); |
| 366 | intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 367 | registerReceiver(mReceiver, intentFilter); |
| 368 | |
Brad Ebinger | 533c6c1 | 2017-08-02 11:38:48 -0700 | [diff] [blame^] | 369 | IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED); |
| 370 | sipIntentFilter.addAction(SipManager.ACTION_SIP_INCOMING_CALL); |
| 371 | sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP); |
| 372 | sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED); |
| 373 | sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PHONE); |
| 374 | registerReceiver(mSipBroadcastReceiver, sipIntentFilter); |
| 375 | |
Ta-wei Yen | f0a71bc | 2017-05-17 12:28:28 -0700 | [diff] [blame] | 376 | mCarrierVvmPackageInstalledReceiver.register(this); |
| 377 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 378 | //set the default values for the preferences in the phone. |
pkanwar | d702e54 | 2017-02-08 15:44:54 -0800 | [diff] [blame] | 379 | PreferenceManager.setDefaultValues(this, R.xml.network_setting_fragment, false); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 380 | |
| 381 | PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false); |
| 382 | |
| 383 | // Make sure the audio mode (along with some |
| 384 | // audio-mode-related state of our own) is initialized |
| 385 | // correctly, given the current state of the phone. |
| 386 | PhoneUtils.setAudioMode(mCM); |
| 387 | } |
| 388 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 389 | // XXX pre-load the SimProvider so that it's ready |
| 390 | resolver.getType(Uri.parse("content://icc/adn")); |
| 391 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 392 | // TODO: Register for Cdma Information Records |
| 393 | // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null); |
| 394 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 395 | // Read HAC settings and configure audio hardware |
| 396 | if (getResources().getBoolean(R.bool.hac_enabled)) { |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 397 | int hac = android.provider.Settings.System.getInt( |
| 398 | getContentResolver(), |
| 399 | android.provider.Settings.System.HEARING_AID, |
| 400 | 0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 401 | AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
Andrew Lee | fb7f92e | 2015-02-26 16:23:32 -0800 | [diff] [blame] | 402 | audioManager.setParameter(SettingsConstants.HAC_KEY, |
| 403 | hac == SettingsConstants.HAC_ENABLED |
| 404 | ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 405 | } |
Santos Cordon | ff506f5 | 2013-11-21 19:13:19 -0800 | [diff] [blame] | 406 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 407 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 408 | /** |
| 409 | * Returns the singleton instance of the PhoneApp. |
| 410 | */ |
Sailesh Nepal | 1eaf22b | 2014-02-22 17:00:49 -0800 | [diff] [blame] | 411 | public static PhoneGlobals getInstance() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 412 | if (sMe == null) { |
| 413 | throw new IllegalStateException("No PhoneGlobals here!"); |
| 414 | } |
| 415 | return sMe; |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * Returns the singleton instance of the PhoneApp if running as the |
| 420 | * primary user, otherwise null. |
| 421 | */ |
| 422 | static PhoneGlobals getInstanceIfPrimary() { |
| 423 | return sMe; |
| 424 | } |
| 425 | |
| 426 | /** |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 427 | * Returns the default phone. |
| 428 | * |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 429 | * 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] | 430 | */ |
Andrew Lee | 83383e4 | 2014-10-31 12:42:28 -0700 | [diff] [blame] | 431 | public static Phone getPhone() { |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 432 | return PhoneFactory.getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 435 | public static Phone getPhone(int subId) { |
| 436 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Santos Cordon | de10b75 | 2013-09-19 04:11:33 -0700 | [diff] [blame] | 439 | /* package */ CallManager getCallManager() { |
| 440 | return mCM; |
| 441 | } |
| 442 | |
Chris Manton | 4e9fa91 | 2015-06-19 11:26:57 -0700 | [diff] [blame] | 443 | public PersistableBundle getCarrierConfig() { |
Shishir Agrawal | d3480e0 | 2016-01-25 13:05:49 -0800 | [diff] [blame] | 444 | return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId()); |
Jonathan Basseri | 89b0ab4 | 2015-05-01 10:52:40 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Chris Manton | 4e9fa91 | 2015-06-19 11:26:57 -0700 | [diff] [blame] | 447 | public PersistableBundle getCarrierConfigForSubId(int subId) { |
Jonathan Basseri | 89b0ab4 | 2015-05-01 10:52:40 -0700 | [diff] [blame] | 448 | return configLoader.getConfigForSubId(subId); |
Junda Liu | 605148f | 2015-04-28 15:23:40 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 451 | private void registerSettingsObserver() { |
| 452 | mSettingsObserver.unobserve(); |
| 453 | String dataRoamingSetting = Settings.Global.DATA_ROAMING; |
| 454 | String mobileDataSetting = Settings.Global.MOBILE_DATA; |
| 455 | if (TelephonyManager.getDefault().getSimCount() > 1) { |
| 456 | int subId = mDefaultDataSubId; |
| 457 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 458 | dataRoamingSetting += subId; |
| 459 | mobileDataSetting += subId; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | // Listen for user data roaming setting changed event |
| 464 | mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting), |
| 465 | EVENT_DATA_ROAMING_SETTINGS_CHANGED); |
| 466 | |
| 467 | // Listen for mobile data setting changed event |
| 468 | mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting), |
| 469 | EVENT_MOBILE_DATA_SETTINGS_CHANGED); |
| 470 | } |
| 471 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 472 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 473 | * Sets the activity responsible for un-PUK-blocking the device |
| 474 | * so that we may close it when we receive a positive result. |
| 475 | * mPUKEntryActivity is also used to indicate to the device that |
| 476 | * we are trying to un-PUK-lock the phone. In other words, iff |
| 477 | * it is NOT null, then we are trying to unlock and waiting for |
| 478 | * the SIM to move to READY state. |
| 479 | * |
| 480 | * @param activity is the activity to close when PUK has |
| 481 | * finished unlocking. Can be set to null to indicate the unlock |
| 482 | * or SIM READYing process is over. |
| 483 | */ |
| 484 | void setPukEntryActivity(Activity activity) { |
| 485 | mPUKEntryActivity = activity; |
| 486 | } |
| 487 | |
| 488 | Activity getPUKEntryActivity() { |
| 489 | return mPUKEntryActivity; |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Sets the dialog responsible for notifying the user of un-PUK- |
| 494 | * blocking - SIM READYing progress, so that we may dismiss it |
| 495 | * when we receive a positive result. |
| 496 | * |
| 497 | * @param dialog indicates the progress dialog informing the user |
| 498 | * of the state of the device. Dismissed upon completion of |
| 499 | * READYing process |
| 500 | */ |
| 501 | void setPukEntryProgressDialog(ProgressDialog dialog) { |
| 502 | mPUKEntryProgressDialog = dialog; |
| 503 | } |
| 504 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 505 | /** |
| 506 | * Controls whether or not the screen is allowed to sleep. |
| 507 | * |
| 508 | * Once sleep is allowed (WakeState is SLEEP), it will rely on the |
| 509 | * settings for the poke lock to determine when to timeout and let |
| 510 | * the device sleep {@link PhoneGlobals#setScreenTimeout}. |
| 511 | * |
| 512 | * @param ws tells the device to how to wake. |
| 513 | */ |
| 514 | /* package */ void requestWakeState(WakeState ws) { |
| 515 | if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")..."); |
| 516 | synchronized (this) { |
| 517 | if (mWakeState != ws) { |
| 518 | switch (ws) { |
| 519 | case PARTIAL: |
| 520 | // acquire the processor wake lock, and release the FULL |
| 521 | // lock if it is being held. |
| 522 | mPartialWakeLock.acquire(); |
| 523 | if (mWakeLock.isHeld()) { |
| 524 | mWakeLock.release(); |
| 525 | } |
| 526 | break; |
| 527 | case FULL: |
| 528 | // acquire the full wake lock, and release the PARTIAL |
| 529 | // lock if it is being held. |
| 530 | mWakeLock.acquire(); |
| 531 | if (mPartialWakeLock.isHeld()) { |
| 532 | mPartialWakeLock.release(); |
| 533 | } |
| 534 | break; |
| 535 | case SLEEP: |
| 536 | default: |
| 537 | // release both the PARTIAL and FULL locks. |
| 538 | if (mWakeLock.isHeld()) { |
| 539 | mWakeLock.release(); |
| 540 | } |
| 541 | if (mPartialWakeLock.isHeld()) { |
| 542 | mPartialWakeLock.release(); |
| 543 | } |
| 544 | break; |
| 545 | } |
| 546 | mWakeState = ws; |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | /** |
| 552 | * If we are not currently keeping the screen on, then poke the power |
| 553 | * manager to wake up the screen for the user activity timeout duration. |
| 554 | */ |
| 555 | /* package */ void wakeUpScreen() { |
| 556 | synchronized (this) { |
| 557 | if (mWakeState == WakeState.SLEEP) { |
| 558 | if (DBG) Log.d(LOG_TAG, "pulse screen lock"); |
Dianne Hackborn | 148769b | 2015-07-13 17:55:47 -0700 | [diff] [blame] | 559 | mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | /** |
| 565 | * Sets the wake state and screen timeout based on the current state |
| 566 | * of the phone, and the current state of the in-call UI. |
| 567 | * |
| 568 | * This method is a "UI Policy" wrapper around |
| 569 | * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}. |
| 570 | * |
| 571 | * It's safe to call this method regardless of the state of the Phone |
| 572 | * (e.g. whether or not it's idle), and regardless of the state of the |
| 573 | * Phone UI (e.g. whether or not the InCallScreen is active.) |
| 574 | */ |
| 575 | /* package */ void updateWakeState() { |
| 576 | PhoneConstants.State state = mCM.getState(); |
| 577 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 578 | // True if the speakerphone is in use. (If so, we *always* use |
| 579 | // the default timeout. Since the user is obviously not holding |
| 580 | // the phone up to his/her face, we don't need to worry about |
| 581 | // false touches, and thus don't need to turn the screen off so |
| 582 | // aggressively.) |
| 583 | // Note that we need to make a fresh call to this method any |
| 584 | // time the speaker state changes. (That happens in |
| 585 | // PhoneUtils.turnOnSpeaker().) |
| 586 | boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this); |
| 587 | |
| 588 | // TODO (bug 1440854): The screen timeout *might* also need to |
| 589 | // depend on the bluetooth state, but this isn't as clear-cut as |
| 590 | // the speaker state (since while using BT it's common for the |
| 591 | // user to put the phone straight into a pocket, in which case the |
| 592 | // timeout should probably still be short.) |
| 593 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 594 | // Decide whether to force the screen on or not. |
| 595 | // |
| 596 | // Force the screen to be on if the phone is ringing or dialing, |
| 597 | // or if we're displaying the "Call ended" UI for a connection in |
| 598 | // the "disconnected" state. |
| 599 | // However, if the phone is disconnected while the user is in the |
| 600 | // middle of selecting a quick response message, we should not force |
| 601 | // the screen to be on. |
| 602 | // |
| 603 | boolean isRinging = (state == PhoneConstants.State.RINGING); |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 604 | boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING); |
Jay Shrauner | 6fe8fd6 | 2013-09-16 19:39:30 -0700 | [diff] [blame] | 605 | boolean keepScreenOn = isRinging || isDialing; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 606 | // keepScreenOn == true means we'll hold a full wake lock: |
| 607 | requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP); |
| 608 | } |
| 609 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 610 | KeyguardManager getKeyguardManager() { |
| 611 | return mKeyguardManager; |
| 612 | } |
| 613 | |
| 614 | private void onMMIComplete(AsyncResult r) { |
| 615 | if (VDBG) Log.d(LOG_TAG, "onMMIComplete()..."); |
| 616 | MmiCode mmiCode = (MmiCode) r.result; |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 617 | PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 618 | } |
| 619 | |
fionaxu | 8012697 | 2017-02-01 17:01:26 -0800 | [diff] [blame] | 620 | private void initForNewRadioTechnology() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 621 | if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology..."); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 622 | notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 625 | private void handleAirplaneModeChange(Context context, int newMode) { |
| 626 | int cellState = Settings.Global.getInt(context.getContentResolver(), |
| 627 | Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG); |
| 628 | boolean isAirplaneNewlyOn = (newMode == 1); |
| 629 | switch (cellState) { |
| 630 | case PhoneConstants.CELL_OFF_FLAG: |
| 631 | // Airplane mode does not affect the cell radio if user |
| 632 | // has turned it off. |
| 633 | break; |
| 634 | case PhoneConstants.CELL_ON_FLAG: |
| 635 | maybeTurnCellOff(context, isAirplaneNewlyOn); |
| 636 | break; |
| 637 | case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG: |
| 638 | maybeTurnCellOn(context, isAirplaneNewlyOn); |
| 639 | break; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | /* |
| 644 | * Returns true if the radio must be turned off when entering airplane mode. |
| 645 | */ |
| 646 | private boolean isCellOffInAirplaneMode(Context context) { |
| 647 | String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(), |
| 648 | Settings.Global.AIRPLANE_MODE_RADIOS); |
| 649 | return airplaneModeRadios == null |
| 650 | || airplaneModeRadios.contains(Settings.Global.RADIO_CELL); |
| 651 | } |
| 652 | |
| 653 | private void setRadioPowerOff(Context context) { |
| 654 | Log.i(LOG_TAG, "Turning radio off - airplane"); |
| 655 | Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON, |
| 656 | PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG); |
Sooraj Sasindran | 798bafa | 2017-04-03 22:49:00 -0700 | [diff] [blame] | 657 | SystemProperties.set("persist.radio.airplane_mode_on", "1"); |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 658 | Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0); |
| 659 | PhoneUtils.setRadioPower(false); |
| 660 | } |
| 661 | |
| 662 | private void setRadioPowerOn(Context context) { |
| 663 | Log.i(LOG_TAG, "Turning radio on - airplane"); |
| 664 | Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON, |
| 665 | PhoneConstants.CELL_ON_FLAG); |
| 666 | Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, |
| 667 | 1); |
Sooraj Sasindran | 798bafa | 2017-04-03 22:49:00 -0700 | [diff] [blame] | 668 | SystemProperties.set("persist.radio.airplane_mode_on", "0"); |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 669 | PhoneUtils.setRadioPower(true); |
| 670 | } |
| 671 | |
| 672 | private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) { |
| 673 | if (isAirplaneNewlyOn) { |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 674 | // If we are trying to turn off the radio, make sure there are no active |
| 675 | // emergency calls. If there are, switch airplane mode back to off. |
| 676 | if (PhoneUtils.isInEmergencyCall(mCM)) { |
| 677 | // Switch airplane mode back to off. |
| 678 | ConnectivityManager.from(this).setAirplaneMode(false); |
| 679 | Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG) |
| 680 | .show(); |
| 681 | Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off"); |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 682 | } else if (isCellOffInAirplaneMode(context)) { |
| 683 | setRadioPowerOff(context); |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 684 | } else { |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 685 | 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] | 686 | } |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | |
| 690 | private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) { |
| 691 | if (!isAirplaneNewlyOn) { |
| 692 | setRadioPowerOn(context); |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 696 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 697 | * Receiver for misc intent broadcasts the Phone app cares about. |
| 698 | */ |
| 699 | private class PhoneAppBroadcastReceiver extends BroadcastReceiver { |
| 700 | @Override |
| 701 | public void onReceive(Context context, Intent intent) { |
| 702 | String action = intent.getAction(); |
| 703 | if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) { |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 704 | int airplaneMode = Settings.Global.getInt(getContentResolver(), |
| 705 | Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF); |
| 706 | // Treat any non-OFF values as ON. |
| 707 | if (airplaneMode != AIRPLANE_OFF) { |
| 708 | airplaneMode = AIRPLANE_ON; |
| 709 | } |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame] | 710 | handleAirplaneModeChange(context, airplaneMode); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 711 | } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) && |
| 712 | (mPUKEntryActivity != null)) { |
| 713 | // if an attempt to un-PUK-lock the device was made, while we're |
| 714 | // receiving this state change notification, notify the handler. |
| 715 | // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has |
| 716 | // been attempted. |
| 717 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED, |
| 718 | intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE))); |
| 719 | } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) { |
| 720 | String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY); |
fionaxu | 8012697 | 2017-02-01 17:01:26 -0800 | [diff] [blame] | 721 | Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active."); |
| 722 | initForNewRadioTechnology(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 723 | } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) { |
| 724 | handleServiceStateChanged(intent); |
| 725 | } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) { |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 726 | int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0); |
Srikanth Chintala | 079912a | 2016-03-03 16:35:01 +0530 | [diff] [blame] | 727 | phoneInEcm = PhoneFactory.getPhone(phoneId); |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 728 | Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId); |
| 729 | if (phoneInEcm != null) { |
| 730 | if (TelephonyCapabilities.supportsEcm(phoneInEcm)) { |
| 731 | Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp."); |
| 732 | // Start Emergency Callback Mode service |
| 733 | if (intent.getBooleanExtra("phoneinECMState", false)) { |
| 734 | context.startService(new Intent(context, |
| 735 | EmergencyCallbackModeService.class)); |
| 736 | } else { |
| 737 | phoneInEcm = null; |
| 738 | } |
| 739 | } else { |
| 740 | // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED |
| 741 | // on a device that doesn't support ECM in the first place. |
| 742 | Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but " |
| 743 | + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName()); |
| 744 | phoneInEcm = null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 745 | } |
| 746 | } else { |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 747 | Log.w(LOG_TAG, "phoneInEcm is null."); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 748 | } |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 749 | } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) { |
| 750 | // Roaming status could be overridden by carrier config, so we need to update it. |
| 751 | if (VDBG) Log.v(LOG_TAG, "carrier config changed."); |
| 752 | updateDataRoamingStatus(); |
| 753 | } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) { |
| 754 | // We also need to pay attention when default data subscription changes. |
| 755 | if (VDBG) Log.v(LOG_TAG, "default data sub changed."); |
| 756 | mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId(); |
| 757 | registerSettingsObserver(); |
| 758 | Phone phone = getPhone(mDefaultDataSubId); |
| 759 | if (phone != null) { |
| 760 | updateDataRoamingStatus(); |
| 761 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 766 | private void handleServiceStateChanged(Intent intent) { |
| 767 | /** |
| 768 | * This used to handle updating EriTextWidgetProvider this routine |
| 769 | * and and listening for ACTION_SERVICE_STATE_CHANGED intents could |
| 770 | * be removed. But leaving just in case it might be needed in the near |
| 771 | * future. |
| 772 | */ |
| 773 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 774 | if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 775 | // If service just returned, start sending out the queued messages |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 776 | Bundle extras = intent.getExtras(); |
| 777 | if (extras != null) { |
| 778 | ServiceState ss = ServiceState.newFromBundle(extras); |
| 779 | if (ss != null) { |
| 780 | int state = ss.getState(); |
Jayachandran C | 2ef9a48 | 2017-05-12 22:07:47 -0700 | [diff] [blame] | 781 | int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, |
| 782 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
| 783 | notificationMgr.updateNetworkSelection(state, subId); |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 784 | |
| 785 | if (VDBG) { |
| 786 | Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId=" |
| 787 | + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming()); |
| 788 | } |
| 789 | if (subId == mDefaultDataSubId) { |
| 790 | updateDataRoamingStatus(); |
| 791 | } |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 792 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 793 | } |
| 794 | } |
| 795 | |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 796 | /** |
| 797 | * When roaming, if mobile data cannot be established due to data roaming not enabled, we need |
| 798 | * to notify the user so they can enable it through settings. Vise versa if the condition |
| 799 | * changes, we need to dismiss the notification. |
| 800 | */ |
| 801 | private void updateDataRoamingStatus() { |
| 802 | if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus"); |
| 803 | Phone phone = getPhone(mDefaultDataSubId); |
| 804 | if (phone == null) { |
| 805 | Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId); |
| 806 | return; |
| 807 | } |
| 808 | |
| 809 | DataConnectionReasons reasons = new DataConnectionReasons(); |
| 810 | boolean dataAllowed = phone.isDataAllowed(reasons); |
| 811 | mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons); |
| 812 | if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons); |
| 813 | if (!mNoDataDueToRoaming |
| 814 | && !dataAllowed |
| 815 | && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) { |
| 816 | // If the only reason of no data is data roaming disabled, then we notify the user |
| 817 | // so the user can turn on data roaming. |
| 818 | mNoDataDueToRoaming = true; |
| 819 | Log.d(LOG_TAG, "Show roaming disconnected notification"); |
| 820 | mDataRoamingNotifLog.log("Show"); |
| 821 | mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_DISCONNECTED); |
| 822 | } else if (mNoDataDueToRoaming && (dataAllowed |
| 823 | || !reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED))) { |
| 824 | // Otherwise dismiss the notification we showed earlier. |
| 825 | mNoDataDueToRoaming = false; |
| 826 | Log.d(LOG_TAG, "Dismiss roaming disconnected notification"); |
| 827 | mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons); |
| 828 | mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK); |
| 829 | } |
| 830 | } |
| 831 | |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 832 | public Phone getPhoneInEcm() { |
| 833 | return phoneInEcm; |
| 834 | } |
| 835 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 836 | /** |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 837 | * Triggers a refresh of the message waiting (voicemail) indicator. |
| 838 | * |
| 839 | * @param subId the subscription id we should refresh the notification for. |
| 840 | */ |
| 841 | public void refreshMwiIndicator(int subId) { |
| 842 | notificationMgr.refreshMwi(subId); |
| 843 | } |
| 844 | |
| 845 | /** |
Nancy Chen | bb49d41 | 2015-07-23 13:54:16 -0700 | [diff] [blame] | 846 | * Dismisses the message waiting (voicemail) indicator. |
| 847 | * |
| 848 | * @param subId the subscription id we should dismiss the notification for. |
| 849 | */ |
| 850 | public void clearMwiIndicator(int subId) { |
Ta-wei Yen | 6310668 | 2016-07-11 14:11:27 -0700 | [diff] [blame] | 851 | // Setting voiceMessageCount to 0 will remove the current notification and clear the system |
| 852 | // cached value. |
Ta-wei Yen | 7df340d | 2016-07-25 10:59:53 -0700 | [diff] [blame] | 853 | Phone phone = getPhone(subId); |
| 854 | if (phone == null) { |
| 855 | Log.w(LOG_TAG, "clearMwiIndicator on null phone, subId:" + subId); |
| 856 | } else { |
| 857 | phone.setVoiceMessageCount(0); |
| 858 | } |
Nancy Chen | bb49d41 | 2015-07-23 13:54:16 -0700 | [diff] [blame] | 859 | } |
Ta-wei Yen | b29425b | 2016-09-21 17:28:14 -0700 | [diff] [blame] | 860 | |
| 861 | /** |
| 862 | * Enables or disables the visual voicemail check for message waiting indicator. Default value |
| 863 | * is true. MWI is the traditional voicemail notification which should be suppressed if visual |
| 864 | * voicemail is active. {@link NotificationMgr#updateMwi(int, boolean, boolean)} currently |
| 865 | * checks the {@link android.provider.VoicemailContract.Status#CONFIGURATION_STATE} to suppress |
| 866 | * the MWI, but there are several issues. b/31229016 is a bug that when the device boots the |
| 867 | * configuration state will be cleared and the MWI for voicemail that arrives when the device |
| 868 | * is offline will be cleared, even if the account cannot be activated. A full solution will be |
| 869 | * adding a setMwiEnabled() method and stop checking the configuration state, but that is too |
| 870 | * risky at this moment. This is a temporary workaround to shut down the configuration state |
| 871 | * check if visual voicemail cannot be activated. |
| 872 | * <p>TODO(twyen): implement the setMwiEnabled() mentioned above. |
| 873 | * |
| 874 | * @param subId the account to set the enabled state |
| 875 | */ |
| 876 | public void setShouldCheckVisualVoicemailConfigurationForMwi(int subId, boolean enabled) { |
| 877 | notificationMgr.setShouldCheckVisualVoicemailConfigurationForMwi(subId, enabled); |
| 878 | } |
Jack Yu | 1a2fc35 | 2017-07-14 17:14:37 -0700 | [diff] [blame] | 879 | |
| 880 | /** |
| 881 | * Dump the state of the object, add calls to other objects as desired. |
| 882 | * |
| 883 | * @param fd File descriptor |
| 884 | * @param printWriter Print writer |
| 885 | * @param args Arguments |
| 886 | */ |
| 887 | public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) { |
| 888 | IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " "); |
| 889 | pw.println("------- PhoneGlobals -------"); |
| 890 | pw.increaseIndent(); |
| 891 | pw.println("mNoDataDueToRoaming=" + mNoDataDueToRoaming); |
| 892 | pw.println("mDefaultDataSubId=" + mDefaultDataSubId); |
| 893 | pw.println("mDataRoamingNotifLog:"); |
| 894 | pw.increaseIndent(); |
| 895 | mDataRoamingNotifLog.dump(fd, pw, args); |
| 896 | pw.decreaseIndent(); |
| 897 | pw.decreaseIndent(); |
| 898 | pw.println("------- End PhoneGlobals -------"); |
| 899 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 900 | } |