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