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