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; |
| 31 | import android.os.AsyncResult; |
Junda Liu | 605148f | 2015-04-28 15:23:40 -0700 | [diff] [blame] | 32 | import android.os.Bundle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 33 | import android.os.Handler; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 34 | import android.os.Message; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 35 | import android.os.PersistableBundle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 36 | import android.os.PowerManager; |
Brad Ebinger | 3fa4346 | 2016-04-12 16:06:48 -0700 | [diff] [blame] | 37 | import android.os.ServiceManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.os.SystemClock; |
| 39 | import android.os.SystemProperties; |
Brad Ebinger | 3fa4346 | 2016-04-12 16:06:48 -0700 | [diff] [blame] | 40 | import android.os.SystemService; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.UpdateLock; |
Brad Ebinger | 3fa4346 | 2016-04-12 16:06:48 -0700 | [diff] [blame] | 42 | import android.os.UserManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | import android.preference.PreferenceManager; |
Sanket Padawe | 4c69923 | 2016-02-09 11:07:22 -0800 | [diff] [blame] | 44 | import android.provider.Settings; |
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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.util.Log; |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 49 | import android.widget.Toast; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | |
| 51 | import com.android.internal.telephony.Call; |
| 52 | import com.android.internal.telephony.CallManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import com.android.internal.telephony.IccCardConstants; |
| 54 | import com.android.internal.telephony.MmiCode; |
| 55 | import com.android.internal.telephony.Phone; |
| 56 | import com.android.internal.telephony.PhoneConstants; |
| 57 | import com.android.internal.telephony.PhoneFactory; |
| 58 | import com.android.internal.telephony.TelephonyCapabilities; |
| 59 | import com.android.internal.telephony.TelephonyIntents; |
Santos Cordon | 352ff65 | 2014-05-30 01:41:45 -0700 | [diff] [blame] | 60 | import com.android.phone.common.CallLogAsync; |
Andrew Lee | fb7f92e | 2015-02-26 16:23:32 -0800 | [diff] [blame] | 61 | import com.android.phone.settings.SettingsConstants; |
Brad Ebinger | 3fa4346 | 2016-04-12 16:06:48 -0700 | [diff] [blame] | 62 | import com.android.server.sip.SipService; |
Santos Cordon | 76aaf48 | 2015-04-08 10:58:27 -0700 | [diff] [blame] | 63 | import com.android.services.telephony.activation.SimActivationManager; |
Brad Ebinger | 3fa4346 | 2016-04-12 16:06:48 -0700 | [diff] [blame] | 64 | import com.android.services.telephony.sip.SipUtil; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * Global state for the telephony subsystem when running in the primary |
| 68 | * phone process. |
| 69 | */ |
Sailesh Nepal | bf90054 | 2014-07-15 16:18:32 -0700 | [diff] [blame] | 70 | public class PhoneGlobals extends ContextWrapper { |
Andrew Lee | 83383e4 | 2014-10-31 12:42:28 -0700 | [diff] [blame] | 71 | public static final String LOG_TAG = "PhoneApp"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Phone app-wide debug level: |
| 75 | * 0 - no debug logging |
| 76 | * 1 - normal debug logging if ro.debuggable is set (which is true in |
| 77 | * "eng" and "userdebug" builds but not "user" builds) |
| 78 | * 2 - ultra-verbose debug logging |
| 79 | * |
| 80 | * Most individual classes in the phone app have a local DBG constant, |
| 81 | * typically set to |
| 82 | * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1) |
| 83 | * or else |
| 84 | * (PhoneApp.DBG_LEVEL >= 2) |
| 85 | * depending on the desired verbosity. |
| 86 | * |
| 87 | * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 ************* |
| 88 | */ |
Andrew Lee | 88b51e2 | 2014-10-29 15:48:51 -0700 | [diff] [blame] | 89 | public static final int DBG_LEVEL = 0; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 90 | |
| 91 | private static final boolean DBG = |
| 92 | (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); |
| 93 | private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 94 | |
| 95 | // Message codes; see mHandler below. |
| 96 | private static final int EVENT_SIM_NETWORK_LOCKED = 3; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 97 | private static final int EVENT_SIM_STATE_CHANGED = 8; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 98 | private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10; |
| 99 | private static final int EVENT_DATA_ROAMING_OK = 11; |
| 100 | private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12; |
Brad Ebinger | 3fa4346 | 2016-04-12 16:06:48 -0700 | [diff] [blame] | 101 | private static final int EVENT_RESTART_SIP = 13; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 102 | |
| 103 | // The MMI codes are also used by the InCallScreen. |
| 104 | public static final int MMI_INITIATE = 51; |
| 105 | public static final int MMI_COMPLETE = 52; |
| 106 | public static final int MMI_CANCEL = 53; |
| 107 | // Don't use message codes larger than 99 here; those are reserved for |
| 108 | // the individual Activities of the Phone UI. |
| 109 | |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 110 | public static final int AIRPLANE_ON = 1; |
| 111 | public static final int AIRPLANE_OFF = 0; |
| 112 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 113 | /** |
| 114 | * Allowable values for the wake lock code. |
| 115 | * SLEEP means the device can be put to sleep. |
| 116 | * PARTIAL means wake the processor, but we display can be kept off. |
| 117 | * FULL means wake both the processor and the display. |
| 118 | */ |
| 119 | public enum WakeState { |
| 120 | SLEEP, |
| 121 | PARTIAL, |
| 122 | FULL |
| 123 | } |
| 124 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | private static PhoneGlobals sMe; |
| 126 | |
| 127 | // A few important fields we expose to the rest of the package |
| 128 | // directly (rather than thru set/get methods) for efficiency. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | CallController callController; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 130 | CallManager mCM; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 131 | CallNotifier notifier; |
| 132 | CallerInfoCache callerInfoCache; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 133 | NotificationMgr notificationMgr; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 134 | public PhoneInterfaceManager phoneMgr; |
Santos Cordon | 76aaf48 | 2015-04-08 10:58:27 -0700 | [diff] [blame] | 135 | public SimActivationManager simActivationManager; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 136 | CarrierConfigLoader configLoader; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 137 | |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 138 | private CallGatewayManager callGatewayManager; |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 139 | private Phone phoneInEcm; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 140 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | static boolean sVoiceCapable = true; |
| 142 | |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 143 | // TODO: Remove, no longer used. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 144 | CdmaPhoneCallState cdmaPhoneCallState; |
| 145 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 146 | // The currently-active PUK entry activity and progress dialog. |
| 147 | // Normally, these are the Emergency Dialer and the subsequent |
| 148 | // progress dialog. null if there is are no such objects in |
| 149 | // the foreground. |
| 150 | private Activity mPUKEntryActivity; |
| 151 | private ProgressDialog mPUKEntryProgressDialog; |
| 152 | |
Yorke Lee | 4d2db1c | 2014-11-06 11:37:09 -0800 | [diff] [blame] | 153 | private boolean mDataDisconnectedDueToRoaming = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 154 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 155 | private WakeState mWakeState = WakeState.SLEEP; |
| 156 | |
| 157 | private PowerManager mPowerManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 158 | private PowerManager.WakeLock mWakeLock; |
| 159 | private PowerManager.WakeLock mPartialWakeLock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 160 | private KeyguardManager mKeyguardManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 161 | |
| 162 | private UpdateLock mUpdateLock; |
| 163 | |
| 164 | // Broadcast receiver for various intent broadcasts (see onCreate()) |
| 165 | private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver(); |
| 166 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 167 | /** |
| 168 | * The singleton OtaUtils instance used for OTASP calls. |
| 169 | * |
| 170 | * The OtaUtils instance is created lazily the first time we need to |
| 171 | * make an OTASP call, regardless of whether it's an interactive or |
| 172 | * non-interactive OTASP call. |
| 173 | */ |
| 174 | public OtaUtils otaUtils; |
| 175 | |
| 176 | // Following are the CDMA OTA information Objects used during OTA Call. |
| 177 | // cdmaOtaProvisionData object store static OTA information that needs |
| 178 | // to be maintained even during Slider open/close scenarios. |
| 179 | // cdmaOtaConfigData object stores configuration info to control visiblity |
| 180 | // of each OTA Screens. |
| 181 | // cdmaOtaScreenState object store OTA Screen State information. |
| 182 | public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData; |
| 183 | public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData; |
| 184 | public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState; |
| 185 | public OtaUtils.CdmaOtaInCallScreenUiState cdmaOtaInCallScreenUiState; |
| 186 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 187 | Handler mHandler = new Handler() { |
| 188 | @Override |
| 189 | public void handleMessage(Message msg) { |
| 190 | PhoneConstants.State phoneState; |
| 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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | }; |
| 260 | |
| 261 | public PhoneGlobals(Context context) { |
| 262 | super(context); |
| 263 | sMe = this; |
| 264 | } |
| 265 | |
| 266 | public void onCreate() { |
| 267 | if (VDBG) Log.v(LOG_TAG, "onCreate()..."); |
| 268 | |
| 269 | ContentResolver resolver = getContentResolver(); |
| 270 | |
| 271 | // Cache the "voice capable" flag. |
| 272 | // This flag currently comes from a resource (which is |
| 273 | // overrideable on a per-product basis): |
| 274 | sVoiceCapable = |
| 275 | getResources().getBoolean(com.android.internal.R.bool.config_voice_capable); |
| 276 | // ...but this might eventually become a PackageManager "system |
| 277 | // feature" instead, in which case we'd do something like: |
| 278 | // sVoiceCapable = |
| 279 | // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS); |
| 280 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 281 | if (mCM == null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 282 | // Initialize the telephony framework |
| 283 | PhoneFactory.makeDefaultPhones(this); |
| 284 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 285 | // Start TelephonyDebugService After the default phone is created. |
| 286 | Intent intent = new Intent(this, TelephonyDebugService.class); |
| 287 | startService(intent); |
| 288 | |
| 289 | mCM = CallManager.getInstance(); |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 290 | for (Phone phone : PhoneFactory.getPhones()) { |
| 291 | mCM.registerPhone(phone); |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 292 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 293 | |
| 294 | // Create the NotificationMgr singleton, which is used to display |
| 295 | // status bar icons and control other status bar behavior. |
| 296 | notificationMgr = NotificationMgr.init(this); |
| 297 | |
Brad Ebinger | 3fa4346 | 2016-04-12 16:06:48 -0700 | [diff] [blame] | 298 | // If PhoneGlobals has crashed and is being restarted, then restart. |
| 299 | mHandler.sendEmptyMessage(EVENT_RESTART_SIP); |
| 300 | |
Anthony Lee | 03ebdfc | 2015-07-27 08:12:02 -0700 | [diff] [blame] | 301 | // Create an instance of CdmaPhoneCallState and initialize it to IDLE |
| 302 | cdmaPhoneCallState = new CdmaPhoneCallState(); |
| 303 | cdmaPhoneCallState.CdmaPhoneCallStateInit(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 304 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 305 | // before registering for phone state changes |
| 306 | mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 307 | mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG); |
| 308 | // lock used to keep the processor awake, when we don't care for the display. |
| 309 | mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK |
| 310 | | PowerManager.ON_AFTER_RELEASE, LOG_TAG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 311 | |
| 312 | mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); |
| 313 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 314 | // Get UpdateLock to suppress system-update related events (e.g. dialog show-up) |
| 315 | // during phone calls. |
| 316 | mUpdateLock = new UpdateLock("phone"); |
| 317 | |
| 318 | if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock); |
| 319 | |
| 320 | CallLogger callLogger = new CallLogger(this, new CallLogAsync()); |
| 321 | |
Jay Shrauner | 21a7534 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 322 | callGatewayManager = CallGatewayManager.getInstance(); |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 323 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 324 | // Create the CallController singleton, which is the interface |
| 325 | // to the telephony layer for user-initiated telephony functionality |
| 326 | // (like making outgoing calls.) |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 327 | callController = CallController.init(this, callLogger, callGatewayManager); |
| 328 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 329 | // Create the CallerInfoCache singleton, which remembers custom ring tone and |
| 330 | // send-to-voicemail settings. |
| 331 | // |
| 332 | // The asynchronous caching will start just after this call. |
| 333 | callerInfoCache = CallerInfoCache.init(this); |
| 334 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 335 | phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone()); |
Santos Cordon | 406c034 | 2013-08-28 00:07:47 -0700 | [diff] [blame] | 336 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 337 | configLoader = CarrierConfigLoader.init(this); |
| 338 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 339 | // Create the CallNotifer singleton, which handles |
| 340 | // asynchronous events from the telephony layer (like |
| 341 | // launching the incoming-call UI when an incoming call comes |
| 342 | // in.) |
Brad Ebinger | a9c6b6d | 2016-01-07 17:24:16 -0800 | [diff] [blame] | 343 | notifier = CallNotifier.init(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 344 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 345 | PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 346 | |
| 347 | // register for MMI/USSD |
| 348 | mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null); |
| 349 | |
| 350 | // register connection tracking to PhoneUtils |
| 351 | PhoneUtils.initializeConnectionHandler(mCM); |
| 352 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 353 | // Register for misc other intent broadcasts. |
| 354 | IntentFilter intentFilter = |
| 355 | new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 356 | intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 357 | intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
| 358 | intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED); |
| 359 | intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
| 360 | intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 361 | registerReceiver(mReceiver, intentFilter); |
| 362 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 363 | //set the default values for the preferences in the phone. |
| 364 | PreferenceManager.setDefaultValues(this, R.xml.network_setting, false); |
| 365 | |
| 366 | PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false); |
| 367 | |
| 368 | // Make sure the audio mode (along with some |
| 369 | // audio-mode-related state of our own) is initialized |
| 370 | // correctly, given the current state of the phone. |
| 371 | PhoneUtils.setAudioMode(mCM); |
| 372 | } |
| 373 | |
Santos Cordon | 52bc81b | 2014-10-07 19:55:12 -0700 | [diff] [blame] | 374 | cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData(); |
| 375 | cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData(); |
| 376 | cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState(); |
| 377 | cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 378 | |
Santos Cordon | 76aaf48 | 2015-04-08 10:58:27 -0700 | [diff] [blame] | 379 | simActivationManager = new SimActivationManager(); |
| 380 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 381 | // XXX pre-load the SimProvider so that it's ready |
| 382 | resolver.getType(Uri.parse("content://icc/adn")); |
| 383 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 384 | // TODO: Register for Cdma Information Records |
| 385 | // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null); |
| 386 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 387 | // Read HAC settings and configure audio hardware |
| 388 | if (getResources().getBoolean(R.bool.hac_enabled)) { |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 389 | int hac = android.provider.Settings.System.getInt( |
| 390 | getContentResolver(), |
| 391 | android.provider.Settings.System.HEARING_AID, |
| 392 | 0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 393 | AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
Andrew Lee | fb7f92e | 2015-02-26 16:23:32 -0800 | [diff] [blame] | 394 | audioManager.setParameter(SettingsConstants.HAC_KEY, |
| 395 | hac == SettingsConstants.HAC_ENABLED |
| 396 | ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 397 | } |
Santos Cordon | ff506f5 | 2013-11-21 19:13:19 -0800 | [diff] [blame] | 398 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 399 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 400 | /** |
| 401 | * Returns the singleton instance of the PhoneApp. |
| 402 | */ |
Sailesh Nepal | 1eaf22b | 2014-02-22 17:00:49 -0800 | [diff] [blame] | 403 | public static PhoneGlobals getInstance() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 404 | if (sMe == null) { |
| 405 | throw new IllegalStateException("No PhoneGlobals here!"); |
| 406 | } |
| 407 | return sMe; |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Returns the singleton instance of the PhoneApp if running as the |
| 412 | * primary user, otherwise null. |
| 413 | */ |
| 414 | static PhoneGlobals getInstanceIfPrimary() { |
| 415 | return sMe; |
| 416 | } |
| 417 | |
| 418 | /** |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 419 | * Returns the default phone. |
| 420 | * |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 421 | * 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] | 422 | */ |
Andrew Lee | 83383e4 | 2014-10-31 12:42:28 -0700 | [diff] [blame] | 423 | public static Phone getPhone() { |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 424 | return PhoneFactory.getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 427 | public static Phone getPhone(int subId) { |
| 428 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Andrew Lee | 385019f | 2014-11-24 14:19:50 -0800 | [diff] [blame] | 429 | } |
| 430 | |
Santos Cordon | de10b75 | 2013-09-19 04:11:33 -0700 | [diff] [blame] | 431 | /* package */ CallManager getCallManager() { |
| 432 | return mCM; |
| 433 | } |
| 434 | |
Chris Manton | 4e9fa91 | 2015-06-19 11:26:57 -0700 | [diff] [blame] | 435 | public PersistableBundle getCarrierConfig() { |
Shishir Agrawal | d3480e0 | 2016-01-25 13:05:49 -0800 | [diff] [blame] | 436 | return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId()); |
Jonathan Basseri | 89b0ab4 | 2015-05-01 10:52:40 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Chris Manton | 4e9fa91 | 2015-06-19 11:26:57 -0700 | [diff] [blame] | 439 | public PersistableBundle getCarrierConfigForSubId(int subId) { |
Jonathan Basseri | 89b0ab4 | 2015-05-01 10:52:40 -0700 | [diff] [blame] | 440 | return configLoader.getConfigForSubId(subId); |
Junda Liu | 605148f | 2015-04-28 15:23:40 -0700 | [diff] [blame] | 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 | * Handles OTASP-related events from the telephony layer. |
| 445 | * |
| 446 | * While an OTASP call is active, the CallNotifier forwards |
| 447 | * OTASP-related telephony events to this method. |
| 448 | */ |
| 449 | void handleOtaspEvent(Message msg) { |
| 450 | if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")..."); |
| 451 | |
| 452 | if (otaUtils == null) { |
| 453 | // We shouldn't be getting OTASP events without ever |
| 454 | // having started the OTASP call in the first place! |
| 455 | Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! " |
| 456 | + "message = " + msg); |
| 457 | return; |
| 458 | } |
| 459 | |
| 460 | otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj); |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * Similarly, handle the disconnect event of an OTASP call |
| 465 | * by forwarding it to the OtaUtils instance. |
| 466 | */ |
| 467 | /* package */ void handleOtaspDisconnect() { |
| 468 | if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()..."); |
| 469 | |
| 470 | if (otaUtils == null) { |
| 471 | // We shouldn't be getting OTASP events without ever |
| 472 | // having started the OTASP call in the first place! |
| 473 | Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!"); |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | otaUtils.onOtaspDisconnect(); |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * Sets the activity responsible for un-PUK-blocking the device |
| 482 | * so that we may close it when we receive a positive result. |
| 483 | * mPUKEntryActivity is also used to indicate to the device that |
| 484 | * we are trying to un-PUK-lock the phone. In other words, iff |
| 485 | * it is NOT null, then we are trying to unlock and waiting for |
| 486 | * the SIM to move to READY state. |
| 487 | * |
| 488 | * @param activity is the activity to close when PUK has |
| 489 | * finished unlocking. Can be set to null to indicate the unlock |
| 490 | * or SIM READYing process is over. |
| 491 | */ |
| 492 | void setPukEntryActivity(Activity activity) { |
| 493 | mPUKEntryActivity = activity; |
| 494 | } |
| 495 | |
| 496 | Activity getPUKEntryActivity() { |
| 497 | return mPUKEntryActivity; |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * Sets the dialog responsible for notifying the user of un-PUK- |
| 502 | * blocking - SIM READYing progress, so that we may dismiss it |
| 503 | * when we receive a positive result. |
| 504 | * |
| 505 | * @param dialog indicates the progress dialog informing the user |
| 506 | * of the state of the device. Dismissed upon completion of |
| 507 | * READYing process |
| 508 | */ |
| 509 | void setPukEntryProgressDialog(ProgressDialog dialog) { |
| 510 | mPUKEntryProgressDialog = dialog; |
| 511 | } |
| 512 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 513 | /** |
| 514 | * Controls whether or not the screen is allowed to sleep. |
| 515 | * |
| 516 | * Once sleep is allowed (WakeState is SLEEP), it will rely on the |
| 517 | * settings for the poke lock to determine when to timeout and let |
| 518 | * the device sleep {@link PhoneGlobals#setScreenTimeout}. |
| 519 | * |
| 520 | * @param ws tells the device to how to wake. |
| 521 | */ |
| 522 | /* package */ void requestWakeState(WakeState ws) { |
| 523 | if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")..."); |
| 524 | synchronized (this) { |
| 525 | if (mWakeState != ws) { |
| 526 | switch (ws) { |
| 527 | case PARTIAL: |
| 528 | // acquire the processor wake lock, and release the FULL |
| 529 | // lock if it is being held. |
| 530 | mPartialWakeLock.acquire(); |
| 531 | if (mWakeLock.isHeld()) { |
| 532 | mWakeLock.release(); |
| 533 | } |
| 534 | break; |
| 535 | case FULL: |
| 536 | // acquire the full wake lock, and release the PARTIAL |
| 537 | // lock if it is being held. |
| 538 | mWakeLock.acquire(); |
| 539 | if (mPartialWakeLock.isHeld()) { |
| 540 | mPartialWakeLock.release(); |
| 541 | } |
| 542 | break; |
| 543 | case SLEEP: |
| 544 | default: |
| 545 | // release both the PARTIAL and FULL locks. |
| 546 | if (mWakeLock.isHeld()) { |
| 547 | mWakeLock.release(); |
| 548 | } |
| 549 | if (mPartialWakeLock.isHeld()) { |
| 550 | mPartialWakeLock.release(); |
| 551 | } |
| 552 | break; |
| 553 | } |
| 554 | mWakeState = ws; |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * If we are not currently keeping the screen on, then poke the power |
| 561 | * manager to wake up the screen for the user activity timeout duration. |
| 562 | */ |
| 563 | /* package */ void wakeUpScreen() { |
| 564 | synchronized (this) { |
| 565 | if (mWakeState == WakeState.SLEEP) { |
| 566 | if (DBG) Log.d(LOG_TAG, "pulse screen lock"); |
Dianne Hackborn | 148769b | 2015-07-13 17:55:47 -0700 | [diff] [blame] | 567 | mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | /** |
| 573 | * Sets the wake state and screen timeout based on the current state |
| 574 | * of the phone, and the current state of the in-call UI. |
| 575 | * |
| 576 | * This method is a "UI Policy" wrapper around |
| 577 | * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}. |
| 578 | * |
| 579 | * It's safe to call this method regardless of the state of the Phone |
| 580 | * (e.g. whether or not it's idle), and regardless of the state of the |
| 581 | * Phone UI (e.g. whether or not the InCallScreen is active.) |
| 582 | */ |
| 583 | /* package */ void updateWakeState() { |
| 584 | PhoneConstants.State state = mCM.getState(); |
| 585 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 586 | // True if the speakerphone is in use. (If so, we *always* use |
| 587 | // the default timeout. Since the user is obviously not holding |
| 588 | // the phone up to his/her face, we don't need to worry about |
| 589 | // false touches, and thus don't need to turn the screen off so |
| 590 | // aggressively.) |
| 591 | // Note that we need to make a fresh call to this method any |
| 592 | // time the speaker state changes. (That happens in |
| 593 | // PhoneUtils.turnOnSpeaker().) |
| 594 | boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this); |
| 595 | |
| 596 | // TODO (bug 1440854): The screen timeout *might* also need to |
| 597 | // depend on the bluetooth state, but this isn't as clear-cut as |
| 598 | // the speaker state (since while using BT it's common for the |
| 599 | // user to put the phone straight into a pocket, in which case the |
| 600 | // timeout should probably still be short.) |
| 601 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 602 | // Decide whether to force the screen on or not. |
| 603 | // |
| 604 | // Force the screen to be on if the phone is ringing or dialing, |
| 605 | // or if we're displaying the "Call ended" UI for a connection in |
| 606 | // the "disconnected" state. |
| 607 | // However, if the phone is disconnected while the user is in the |
| 608 | // middle of selecting a quick response message, we should not force |
| 609 | // the screen to be on. |
| 610 | // |
| 611 | boolean isRinging = (state == PhoneConstants.State.RINGING); |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 612 | boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING); |
Jay Shrauner | 6fe8fd6 | 2013-09-16 19:39:30 -0700 | [diff] [blame] | 613 | boolean keepScreenOn = isRinging || isDialing; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 614 | // keepScreenOn == true means we'll hold a full wake lock: |
| 615 | requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP); |
| 616 | } |
| 617 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 618 | KeyguardManager getKeyguardManager() { |
| 619 | return mKeyguardManager; |
| 620 | } |
| 621 | |
| 622 | private void onMMIComplete(AsyncResult r) { |
| 623 | if (VDBG) Log.d(LOG_TAG, "onMMIComplete()..."); |
| 624 | MmiCode mmiCode = (MmiCode) r.result; |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 625 | PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 628 | private void initForNewRadioTechnology(int phoneId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 629 | if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology..."); |
| 630 | |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 631 | final Phone phone = PhoneFactory.getPhone(phoneId); |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 632 | if (phone == null || !TelephonyCapabilities.supportsOtasp(phone)) { |
| 633 | // Clean up OTA for non-CDMA since it is only valid for CDMA. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 634 | clearOtaState(); |
| 635 | } |
| 636 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 637 | notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame^] | 640 | private void handleAirplaneModeChange(Context context, int newMode) { |
| 641 | int cellState = Settings.Global.getInt(context.getContentResolver(), |
| 642 | Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG); |
| 643 | boolean isAirplaneNewlyOn = (newMode == 1); |
| 644 | switch (cellState) { |
| 645 | case PhoneConstants.CELL_OFF_FLAG: |
| 646 | // Airplane mode does not affect the cell radio if user |
| 647 | // has turned it off. |
| 648 | break; |
| 649 | case PhoneConstants.CELL_ON_FLAG: |
| 650 | maybeTurnCellOff(context, isAirplaneNewlyOn); |
| 651 | break; |
| 652 | case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG: |
| 653 | maybeTurnCellOn(context, isAirplaneNewlyOn); |
| 654 | break; |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | /* |
| 659 | * Returns true if the radio must be turned off when entering airplane mode. |
| 660 | */ |
| 661 | private boolean isCellOffInAirplaneMode(Context context) { |
| 662 | String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(), |
| 663 | Settings.Global.AIRPLANE_MODE_RADIOS); |
| 664 | return airplaneModeRadios == null |
| 665 | || airplaneModeRadios.contains(Settings.Global.RADIO_CELL); |
| 666 | } |
| 667 | |
| 668 | private void setRadioPowerOff(Context context) { |
| 669 | Log.i(LOG_TAG, "Turning radio off - airplane"); |
| 670 | Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON, |
| 671 | PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG); |
| 672 | Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0); |
| 673 | PhoneUtils.setRadioPower(false); |
| 674 | } |
| 675 | |
| 676 | private void setRadioPowerOn(Context context) { |
| 677 | Log.i(LOG_TAG, "Turning radio on - airplane"); |
| 678 | Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON, |
| 679 | PhoneConstants.CELL_ON_FLAG); |
| 680 | Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, |
| 681 | 1); |
| 682 | PhoneUtils.setRadioPower(true); |
| 683 | } |
| 684 | |
| 685 | private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) { |
| 686 | if (isAirplaneNewlyOn) { |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 687 | // If we are trying to turn off the radio, make sure there are no active |
| 688 | // emergency calls. If there are, switch airplane mode back to off. |
| 689 | if (PhoneUtils.isInEmergencyCall(mCM)) { |
| 690 | // Switch airplane mode back to off. |
| 691 | ConnectivityManager.from(this).setAirplaneMode(false); |
| 692 | Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG) |
| 693 | .show(); |
| 694 | Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off"); |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame^] | 695 | } else if (isCellOffInAirplaneMode(context)) { |
| 696 | setRadioPowerOff(context); |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 697 | } else { |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame^] | 698 | 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] | 699 | } |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame^] | 700 | } |
| 701 | } |
| 702 | |
| 703 | private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) { |
| 704 | if (!isAirplaneNewlyOn) { |
| 705 | setRadioPowerOn(context); |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 709 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 710 | * Receiver for misc intent broadcasts the Phone app cares about. |
| 711 | */ |
| 712 | private class PhoneAppBroadcastReceiver extends BroadcastReceiver { |
| 713 | @Override |
| 714 | public void onReceive(Context context, Intent intent) { |
| 715 | String action = intent.getAction(); |
| 716 | if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) { |
Santos Cordon | e18902f | 2016-03-22 17:16:04 -0700 | [diff] [blame] | 717 | int airplaneMode = Settings.Global.getInt(getContentResolver(), |
| 718 | Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF); |
| 719 | // Treat any non-OFF values as ON. |
| 720 | if (airplaneMode != AIRPLANE_OFF) { |
| 721 | airplaneMode = AIRPLANE_ON; |
| 722 | } |
Chris Manton | a09f363 | 2016-02-09 14:48:42 -0800 | [diff] [blame^] | 723 | handleAirplaneModeChange(context, airplaneMode); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 724 | } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) { |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 725 | int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, |
| 726 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
| 727 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 728 | String state = intent.getStringExtra(PhoneConstants.STATE_KEY); |
| 729 | if (VDBG) { |
| 730 | Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED"); |
| 731 | Log.d(LOG_TAG, "- state: " + state); |
| 732 | Log.d(LOG_TAG, "- reason: " |
| 733 | + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY)); |
| 734 | Log.d(LOG_TAG, "- subId: " + subId); |
| 735 | Log.d(LOG_TAG, "- phoneId: " + phoneId); |
| 736 | } |
| 737 | Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ? |
| 738 | PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone(); |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 739 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 740 | // The "data disconnected due to roaming" notification is shown |
| 741 | // if (a) you have the "data roaming" feature turned off, and |
| 742 | // (b) you just lost data connectivity because you're roaming. |
| 743 | boolean disconnectedDueToRoaming = |
| 744 | !phone.getDataRoamingEnabled() |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 745 | && PhoneConstants.DataState.DISCONNECTED.equals(state) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 746 | && Phone.REASON_ROAMING_ON.equals( |
| 747 | intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY)); |
Yorke Lee | 4d2db1c | 2014-11-06 11:37:09 -0800 | [diff] [blame] | 748 | if (mDataDisconnectedDueToRoaming != disconnectedDueToRoaming) { |
| 749 | mDataDisconnectedDueToRoaming = disconnectedDueToRoaming; |
| 750 | mHandler.sendEmptyMessage(disconnectedDueToRoaming |
| 751 | ? EVENT_DATA_ROAMING_DISCONNECTED : EVENT_DATA_ROAMING_OK); |
| 752 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 753 | } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) && |
| 754 | (mPUKEntryActivity != null)) { |
| 755 | // if an attempt to un-PUK-lock the device was made, while we're |
| 756 | // receiving this state change notification, notify the handler. |
| 757 | // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has |
| 758 | // been attempted. |
| 759 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED, |
| 760 | intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE))); |
| 761 | } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) { |
| 762 | String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY); |
Stuart Scott | dcf40a9 | 2014-12-09 10:45:01 -0800 | [diff] [blame] | 763 | int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, |
| 764 | SubscriptionManager.INVALID_PHONE_INDEX); |
| 765 | Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " (" + phoneId |
| 766 | + ") is active."); |
| 767 | initForNewRadioTechnology(phoneId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 768 | } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) { |
| 769 | handleServiceStateChanged(intent); |
| 770 | } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) { |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 771 | int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0); |
| 772 | phoneInEcm = getPhone(phoneId); |
| 773 | Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId); |
| 774 | if (phoneInEcm != null) { |
| 775 | if (TelephonyCapabilities.supportsEcm(phoneInEcm)) { |
| 776 | Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp."); |
| 777 | // Start Emergency Callback Mode service |
| 778 | if (intent.getBooleanExtra("phoneinECMState", false)) { |
| 779 | context.startService(new Intent(context, |
| 780 | EmergencyCallbackModeService.class)); |
| 781 | } else { |
| 782 | phoneInEcm = null; |
| 783 | } |
| 784 | } else { |
| 785 | // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED |
| 786 | // on a device that doesn't support ECM in the first place. |
| 787 | Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but " |
| 788 | + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName()); |
| 789 | phoneInEcm = null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 790 | } |
| 791 | } else { |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 792 | Log.w(LOG_TAG, "phoneInEcm is null."); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 793 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | } |
| 797 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 798 | private void handleServiceStateChanged(Intent intent) { |
| 799 | /** |
| 800 | * This used to handle updating EriTextWidgetProvider this routine |
| 801 | * and and listening for ACTION_SERVICE_STATE_CHANGED intents could |
| 802 | * be removed. But leaving just in case it might be needed in the near |
| 803 | * future. |
| 804 | */ |
| 805 | |
| 806 | // If service just returned, start sending out the queued messages |
Santos Cordon | c593d00 | 2015-06-03 15:41:15 -0700 | [diff] [blame] | 807 | Bundle extras = intent.getExtras(); |
| 808 | if (extras != null) { |
| 809 | ServiceState ss = ServiceState.newFromBundle(extras); |
| 810 | if (ss != null) { |
| 811 | int state = ss.getState(); |
| 812 | notificationMgr.updateNetworkSelection(state); |
| 813 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 814 | } |
| 815 | } |
| 816 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 817 | // it is safe to call clearOtaState() even if the InCallScreen isn't active |
| 818 | public void clearOtaState() { |
| 819 | if (DBG) Log.d(LOG_TAG, "- clearOtaState ..."); |
Jay Shrauner | 6fe8fd6 | 2013-09-16 19:39:30 -0700 | [diff] [blame] | 820 | if (otaUtils != null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 821 | otaUtils.cleanOtaScreen(true); |
| 822 | if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen"); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active |
| 827 | public void dismissOtaDialogs() { |
| 828 | if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ..."); |
Jay Shrauner | 6fe8fd6 | 2013-09-16 19:39:30 -0700 | [diff] [blame] | 829 | if (otaUtils != null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 830 | otaUtils.dismissAllOtaDialogs(); |
| 831 | if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs"); |
| 832 | } |
| 833 | } |
| 834 | |
Sandeep Kunta | de73a6a | 2014-10-15 18:45:56 +0530 | [diff] [blame] | 835 | public Phone getPhoneInEcm() { |
| 836 | return phoneInEcm; |
| 837 | } |
| 838 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 839 | /** |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 840 | * Triggers a refresh of the message waiting (voicemail) indicator. |
| 841 | * |
| 842 | * @param subId the subscription id we should refresh the notification for. |
| 843 | */ |
| 844 | public void refreshMwiIndicator(int subId) { |
| 845 | notificationMgr.refreshMwi(subId); |
| 846 | } |
| 847 | |
| 848 | /** |
Nancy Chen | bb49d41 | 2015-07-23 13:54:16 -0700 | [diff] [blame] | 849 | * Dismisses the message waiting (voicemail) indicator. |
| 850 | * |
| 851 | * @param subId the subscription id we should dismiss the notification for. |
| 852 | */ |
| 853 | public void clearMwiIndicator(int subId) { |
| 854 | notificationMgr.updateMwi(subId, false); |
| 855 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 856 | } |