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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.os.Handler; |
| 38 | import android.os.IBinder; |
| 39 | import android.os.IPowerManager; |
| 40 | import android.os.Message; |
| 41 | import android.os.PowerManager; |
| 42 | import android.os.RemoteException; |
| 43 | import android.os.ServiceManager; |
| 44 | import android.os.SystemClock; |
| 45 | import android.os.SystemProperties; |
| 46 | import android.os.UpdateLock; |
| 47 | import android.os.UserHandle; |
| 48 | import android.preference.PreferenceManager; |
| 49 | import android.provider.Settings.System; |
| 50 | import android.telephony.ServiceState; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.util.Log; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | |
| 53 | import com.android.internal.telephony.Call; |
| 54 | import com.android.internal.telephony.CallManager; |
| 55 | import com.android.internal.telephony.IccCard; |
| 56 | import com.android.internal.telephony.IccCardConstants; |
| 57 | import com.android.internal.telephony.MmiCode; |
| 58 | import com.android.internal.telephony.Phone; |
| 59 | import com.android.internal.telephony.PhoneConstants; |
| 60 | import com.android.internal.telephony.PhoneFactory; |
| 61 | import com.android.internal.telephony.TelephonyCapabilities; |
| 62 | import com.android.internal.telephony.TelephonyIntents; |
| 63 | import com.android.internal.telephony.cdma.TtyIntent; |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 64 | import com.android.phone.WiredHeadsetManager.WiredHeadsetListener; |
Santos Cordon | 352ff65 | 2014-05-30 01:41:45 -0700 | [diff] [blame] | 65 | import com.android.phone.common.CallLogAsync; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 66 | import com.android.server.sip.SipService; |
| 67 | |
| 68 | /** |
| 69 | * Global state for the telephony subsystem when running in the primary |
| 70 | * phone process. |
| 71 | */ |
Santos Cordon | fc30981 | 2013-08-20 18:33:16 -0700 | [diff] [blame] | 72 | public class PhoneGlobals extends ContextWrapper implements WiredHeadsetListener { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 73 | /* package */ static final String LOG_TAG = "PhoneApp"; |
| 74 | |
| 75 | /** |
| 76 | * Phone app-wide debug level: |
| 77 | * 0 - no debug logging |
| 78 | * 1 - normal debug logging if ro.debuggable is set (which is true in |
| 79 | * "eng" and "userdebug" builds but not "user" builds) |
| 80 | * 2 - ultra-verbose debug logging |
| 81 | * |
| 82 | * Most individual classes in the phone app have a local DBG constant, |
| 83 | * typically set to |
| 84 | * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1) |
| 85 | * or else |
| 86 | * (PhoneApp.DBG_LEVEL >= 2) |
| 87 | * depending on the desired verbosity. |
| 88 | * |
| 89 | * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 ************* |
| 90 | */ |
| 91 | /* package */ static final int DBG_LEVEL = 0; |
| 92 | |
| 93 | private static final boolean DBG = |
| 94 | (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); |
| 95 | private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 96 | |
| 97 | // Message codes; see mHandler below. |
| 98 | private static final int EVENT_SIM_NETWORK_LOCKED = 3; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 99 | private static final int EVENT_SIM_STATE_CHANGED = 8; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 100 | private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10; |
| 101 | private static final int EVENT_DATA_ROAMING_OK = 11; |
| 102 | private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12; |
| 103 | private static final int EVENT_DOCK_STATE_CHANGED = 13; |
| 104 | private static final int EVENT_TTY_PREFERRED_MODE_CHANGED = 14; |
| 105 | private static final int EVENT_TTY_MODE_GET = 15; |
| 106 | private static final int EVENT_TTY_MODE_SET = 16; |
| 107 | private static final int EVENT_START_SIP_SERVICE = 17; |
| 108 | |
| 109 | // The MMI codes are also used by the InCallScreen. |
| 110 | public static final int MMI_INITIATE = 51; |
| 111 | public static final int MMI_COMPLETE = 52; |
| 112 | public static final int MMI_CANCEL = 53; |
| 113 | // Don't use message codes larger than 99 here; those are reserved for |
| 114 | // the individual Activities of the Phone UI. |
| 115 | |
| 116 | /** |
| 117 | * Allowable values for the wake lock code. |
| 118 | * SLEEP means the device can be put to sleep. |
| 119 | * PARTIAL means wake the processor, but we display can be kept off. |
| 120 | * FULL means wake both the processor and the display. |
| 121 | */ |
| 122 | public enum WakeState { |
| 123 | SLEEP, |
| 124 | PARTIAL, |
| 125 | FULL |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Intent Action used for hanging up the current call from Notification bar. This will |
| 130 | * choose first ringing call, first active call, or first background call (typically in |
| 131 | * HOLDING state). |
| 132 | */ |
| 133 | public static final String ACTION_HANG_UP_ONGOING_CALL = |
| 134 | "com.android.phone.ACTION_HANG_UP_ONGOING_CALL"; |
| 135 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 136 | private static PhoneGlobals sMe; |
| 137 | |
| 138 | // A few important fields we expose to the rest of the package |
| 139 | // directly (rather than thru set/get methods) for efficiency. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | CallController callController; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | CallManager mCM; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 142 | CallNotifier notifier; |
| 143 | CallerInfoCache callerInfoCache; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 144 | NotificationMgr notificationMgr; |
| 145 | Phone phone; |
| 146 | PhoneInterfaceManager phoneMgr; |
| 147 | |
Santos Cordon | 9b7bac7 | 2013-08-06 08:04:52 -0700 | [diff] [blame] | 148 | private AudioRouter audioRouter; |
Santos Cordon | 27a3c1f | 2013-08-06 07:49:27 -0700 | [diff] [blame] | 149 | private BluetoothManager bluetoothManager; |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 150 | private CallGatewayManager callGatewayManager; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 151 | private CallStateMonitor callStateMonitor; |
| 152 | private IBluetoothHeadsetPhone mBluetoothPhone; |
| 153 | private Ringer ringer; |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 154 | private WiredHeadsetManager wiredHeadsetManager; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 155 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 156 | static int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 157 | static boolean sVoiceCapable = true; |
| 158 | |
| 159 | // Internal PhoneApp Call state tracker |
| 160 | CdmaPhoneCallState cdmaPhoneCallState; |
| 161 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 162 | // The currently-active PUK entry activity and progress dialog. |
| 163 | // Normally, these are the Emergency Dialer and the subsequent |
| 164 | // progress dialog. null if there is are no such objects in |
| 165 | // the foreground. |
| 166 | private Activity mPUKEntryActivity; |
| 167 | private ProgressDialog mPUKEntryProgressDialog; |
| 168 | |
| 169 | private boolean mIsSimPinEnabled; |
| 170 | private String mCachedSimPin; |
| 171 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 172 | // True if we are beginning a call, but the phone state has not changed yet |
| 173 | private boolean mBeginningCall; |
| 174 | |
| 175 | // Last phone state seen by updatePhoneState() |
| 176 | private PhoneConstants.State mLastPhoneState = PhoneConstants.State.IDLE; |
| 177 | |
| 178 | private WakeState mWakeState = WakeState.SLEEP; |
| 179 | |
| 180 | private PowerManager mPowerManager; |
| 181 | private IPowerManager mPowerManagerService; |
| 182 | private PowerManager.WakeLock mWakeLock; |
| 183 | private PowerManager.WakeLock mPartialWakeLock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 184 | private KeyguardManager mKeyguardManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 185 | |
| 186 | private UpdateLock mUpdateLock; |
| 187 | |
| 188 | // Broadcast receiver for various intent broadcasts (see onCreate()) |
| 189 | private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver(); |
| 190 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 191 | /** boolean indicating restoring mute state on InCallScreen.onResume() */ |
| 192 | private boolean mShouldRestoreMuteOnInCallResume; |
| 193 | |
| 194 | /** |
| 195 | * The singleton OtaUtils instance used for OTASP calls. |
| 196 | * |
| 197 | * The OtaUtils instance is created lazily the first time we need to |
| 198 | * make an OTASP call, regardless of whether it's an interactive or |
| 199 | * non-interactive OTASP call. |
| 200 | */ |
| 201 | public OtaUtils otaUtils; |
| 202 | |
| 203 | // Following are the CDMA OTA information Objects used during OTA Call. |
| 204 | // cdmaOtaProvisionData object store static OTA information that needs |
| 205 | // to be maintained even during Slider open/close scenarios. |
| 206 | // cdmaOtaConfigData object stores configuration info to control visiblity |
| 207 | // of each OTA Screens. |
| 208 | // cdmaOtaScreenState object store OTA Screen State information. |
| 209 | public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData; |
| 210 | public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData; |
| 211 | public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState; |
| 212 | public OtaUtils.CdmaOtaInCallScreenUiState cdmaOtaInCallScreenUiState; |
| 213 | |
| 214 | // TTY feature enabled on this platform |
| 215 | private boolean mTtyEnabled; |
| 216 | // Current TTY operating mode selected by user |
| 217 | private int mPreferredTtyMode = Phone.TTY_MODE_OFF; |
| 218 | |
| 219 | /** |
| 220 | * Set the restore mute state flag. Used when we are setting the mute state |
| 221 | * OUTSIDE of user interaction {@link PhoneUtils#startNewCall(Phone)} |
| 222 | */ |
| 223 | /*package*/void setRestoreMuteOnInCallResume (boolean mode) { |
| 224 | mShouldRestoreMuteOnInCallResume = mode; |
| 225 | } |
| 226 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 227 | Handler mHandler = new Handler() { |
| 228 | @Override |
| 229 | public void handleMessage(Message msg) { |
| 230 | PhoneConstants.State phoneState; |
| 231 | switch (msg.what) { |
| 232 | // Starts the SIP service. It's a no-op if SIP API is not supported |
| 233 | // on the deivce. |
| 234 | // TODO: Having the phone process host the SIP service is only |
| 235 | // temporary. Will move it to a persistent communication process |
| 236 | // later. |
| 237 | case EVENT_START_SIP_SERVICE: |
| 238 | SipService.start(getApplicationContext()); |
| 239 | break; |
| 240 | |
| 241 | // TODO: This event should be handled by the lock screen, just |
| 242 | // like the "SIM missing" and "Sim locked" cases (bug 1804111). |
| 243 | case EVENT_SIM_NETWORK_LOCKED: |
| 244 | if (getResources().getBoolean(R.bool.ignore_sim_network_locked_events)) { |
| 245 | // Some products don't have the concept of a "SIM network lock" |
| 246 | Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; " |
| 247 | + "not showing 'SIM network unlock' PIN entry screen"); |
| 248 | } else { |
| 249 | // Normal case: show the "SIM network unlock" PIN entry screen. |
| 250 | // The user won't be able to do anything else until |
| 251 | // they enter a valid SIM network PIN. |
| 252 | Log.i(LOG_TAG, "show sim depersonal panel"); |
| 253 | IccNetworkDepersonalizationPanel ndpPanel = |
| 254 | new IccNetworkDepersonalizationPanel(PhoneGlobals.getInstance()); |
| 255 | ndpPanel.show(); |
| 256 | } |
| 257 | break; |
| 258 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 259 | case EVENT_DATA_ROAMING_DISCONNECTED: |
| 260 | notificationMgr.showDataDisconnectedRoaming(); |
| 261 | break; |
| 262 | |
| 263 | case EVENT_DATA_ROAMING_OK: |
| 264 | notificationMgr.hideDataDisconnectedRoaming(); |
| 265 | break; |
| 266 | |
| 267 | case MMI_COMPLETE: |
| 268 | onMMIComplete((AsyncResult) msg.obj); |
| 269 | break; |
| 270 | |
| 271 | case MMI_CANCEL: |
| 272 | PhoneUtils.cancelMmiCode(phone); |
| 273 | break; |
| 274 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 275 | case EVENT_SIM_STATE_CHANGED: |
| 276 | // Marks the event where the SIM goes into ready state. |
| 277 | // Right now, this is only used for the PUK-unlocking |
| 278 | // process. |
| 279 | if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) { |
| 280 | // when the right event is triggered and there |
| 281 | // are UI objects in the foreground, we close |
| 282 | // them to display the lock panel. |
| 283 | if (mPUKEntryActivity != null) { |
| 284 | mPUKEntryActivity.finish(); |
| 285 | mPUKEntryActivity = null; |
| 286 | } |
| 287 | if (mPUKEntryProgressDialog != null) { |
| 288 | mPUKEntryProgressDialog.dismiss(); |
| 289 | mPUKEntryProgressDialog = null; |
| 290 | } |
| 291 | } |
| 292 | break; |
| 293 | |
| 294 | case EVENT_UNSOL_CDMA_INFO_RECORD: |
| 295 | //TODO: handle message here; |
| 296 | break; |
| 297 | |
| 298 | case EVENT_DOCK_STATE_CHANGED: |
| 299 | // If the phone is docked/undocked during a call, and no wired or BT headset |
| 300 | // is connected: turn on/off the speaker accordingly. |
| 301 | boolean inDockMode = false; |
| 302 | if (mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) { |
| 303 | inDockMode = true; |
| 304 | } |
| 305 | if (VDBG) Log.d(LOG_TAG, "received EVENT_DOCK_STATE_CHANGED. Phone inDock = " |
| 306 | + inDockMode); |
| 307 | |
| 308 | phoneState = mCM.getState(); |
| 309 | if (phoneState == PhoneConstants.State.OFFHOOK && |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 310 | !wiredHeadsetManager.isHeadsetPlugged() && |
| 311 | !bluetoothManager.isBluetoothHeadsetAudioOn()) { |
| 312 | audioRouter.setSpeaker(inDockMode); |
| 313 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 314 | PhoneUtils.turnOnSpeaker(getApplicationContext(), inDockMode, true); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 315 | } |
| 316 | break; |
| 317 | |
| 318 | case EVENT_TTY_PREFERRED_MODE_CHANGED: |
| 319 | // TTY mode is only applied if a headset is connected |
| 320 | int ttyMode; |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 321 | if (wiredHeadsetManager.isHeadsetPlugged()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 322 | ttyMode = mPreferredTtyMode; |
| 323 | } else { |
| 324 | ttyMode = Phone.TTY_MODE_OFF; |
| 325 | } |
| 326 | phone.setTTYMode(ttyMode, mHandler.obtainMessage(EVENT_TTY_MODE_SET)); |
| 327 | break; |
| 328 | |
| 329 | case EVENT_TTY_MODE_GET: |
| 330 | handleQueryTTYModeResponse(msg); |
| 331 | break; |
| 332 | |
| 333 | case EVENT_TTY_MODE_SET: |
| 334 | handleSetTTYModeResponse(msg); |
| 335 | break; |
| 336 | } |
| 337 | } |
| 338 | }; |
| 339 | |
| 340 | public PhoneGlobals(Context context) { |
| 341 | super(context); |
| 342 | sMe = this; |
| 343 | } |
| 344 | |
| 345 | public void onCreate() { |
| 346 | if (VDBG) Log.v(LOG_TAG, "onCreate()..."); |
| 347 | |
| 348 | ContentResolver resolver = getContentResolver(); |
| 349 | |
| 350 | // Cache the "voice capable" flag. |
| 351 | // This flag currently comes from a resource (which is |
| 352 | // overrideable on a per-product basis): |
| 353 | sVoiceCapable = |
| 354 | getResources().getBoolean(com.android.internal.R.bool.config_voice_capable); |
| 355 | // ...but this might eventually become a PackageManager "system |
| 356 | // feature" instead, in which case we'd do something like: |
| 357 | // sVoiceCapable = |
| 358 | // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS); |
| 359 | |
| 360 | if (phone == null) { |
| 361 | // Initialize the telephony framework |
| 362 | PhoneFactory.makeDefaultPhones(this); |
| 363 | |
| 364 | // Get the default phone |
| 365 | phone = PhoneFactory.getDefaultPhone(); |
| 366 | |
| 367 | // Start TelephonyDebugService After the default phone is created. |
| 368 | Intent intent = new Intent(this, TelephonyDebugService.class); |
| 369 | startService(intent); |
| 370 | |
| 371 | mCM = CallManager.getInstance(); |
| 372 | mCM.registerPhone(phone); |
| 373 | |
| 374 | // Create the NotificationMgr singleton, which is used to display |
| 375 | // status bar icons and control other status bar behavior. |
| 376 | notificationMgr = NotificationMgr.init(this); |
| 377 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 378 | mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE); |
| 379 | |
| 380 | int phoneType = phone.getPhoneType(); |
| 381 | |
| 382 | if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { |
| 383 | // Create an instance of CdmaPhoneCallState and initialize it to IDLE |
| 384 | cdmaPhoneCallState = new CdmaPhoneCallState(); |
| 385 | cdmaPhoneCallState.CdmaPhoneCallStateInit(); |
| 386 | } |
| 387 | |
| 388 | if (BluetoothAdapter.getDefaultAdapter() != null) { |
| 389 | // Start BluetoothPhoneService even if device is not voice capable. |
| 390 | // The device can still support VOIP. |
| 391 | startService(new Intent(this, BluetoothPhoneService.class)); |
| 392 | bindService(new Intent(this, BluetoothPhoneService.class), |
| 393 | mBluetoothPhoneConnection, 0); |
| 394 | } else { |
| 395 | // Device is not bluetooth capable |
| 396 | mBluetoothPhone = null; |
| 397 | } |
| 398 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 399 | // before registering for phone state changes |
| 400 | mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 401 | mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG); |
| 402 | // lock used to keep the processor awake, when we don't care for the display. |
| 403 | mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK |
| 404 | | PowerManager.ON_AFTER_RELEASE, LOG_TAG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 405 | |
| 406 | mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); |
| 407 | |
| 408 | // get a handle to the service so that we can use it later when we |
| 409 | // want to set the poke lock. |
| 410 | mPowerManagerService = IPowerManager.Stub.asInterface( |
| 411 | ServiceManager.getService("power")); |
| 412 | |
| 413 | // Get UpdateLock to suppress system-update related events (e.g. dialog show-up) |
| 414 | // during phone calls. |
| 415 | mUpdateLock = new UpdateLock("phone"); |
| 416 | |
| 417 | if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock); |
| 418 | |
| 419 | CallLogger callLogger = new CallLogger(this, new CallLogAsync()); |
| 420 | |
Jay Shrauner | 21a7534 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 421 | callGatewayManager = CallGatewayManager.getInstance(); |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 422 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 423 | // Create the CallController singleton, which is the interface |
| 424 | // to the telephony layer for user-initiated telephony functionality |
| 425 | // (like making outgoing calls.) |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 426 | callController = CallController.init(this, callLogger, callGatewayManager); |
| 427 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 428 | // Create the CallerInfoCache singleton, which remembers custom ring tone and |
| 429 | // send-to-voicemail settings. |
| 430 | // |
| 431 | // The asynchronous caching will start just after this call. |
| 432 | callerInfoCache = CallerInfoCache.init(this); |
| 433 | |
| 434 | // Monitors call activity from the telephony layer |
| 435 | callStateMonitor = new CallStateMonitor(mCM); |
| 436 | |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 437 | // Manages wired headset state |
| 438 | wiredHeadsetManager = new WiredHeadsetManager(this); |
| 439 | wiredHeadsetManager.addWiredHeadsetListener(this); |
| 440 | |
Santos Cordon | 2c2d3cf | 2013-08-08 03:53:47 -0700 | [diff] [blame] | 441 | // Bluetooth manager |
Sailesh Nepal | 23d9ed7 | 2014-07-03 09:40:26 -0700 | [diff] [blame^] | 442 | bluetoothManager = new BluetoothManager(); |
Santos Cordon | 2c2d3cf | 2013-08-08 03:53:47 -0700 | [diff] [blame] | 443 | |
| 444 | ringer = Ringer.init(this, bluetoothManager); |
| 445 | |
Santos Cordon | 9b7bac7 | 2013-08-06 08:04:52 -0700 | [diff] [blame] | 446 | // Audio router |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 447 | audioRouter = new AudioRouter(this, bluetoothManager, wiredHeadsetManager, mCM); |
Santos Cordon | 9b7bac7 | 2013-08-06 08:04:52 -0700 | [diff] [blame] | 448 | |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 449 | phoneMgr = PhoneInterfaceManager.init(this, phone); |
Santos Cordon | 406c034 | 2013-08-28 00:07:47 -0700 | [diff] [blame] | 450 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 451 | // Create the CallNotifer singleton, which handles |
| 452 | // asynchronous events from the telephony layer (like |
| 453 | // launching the incoming-call UI when an incoming call comes |
| 454 | // in.) |
Santos Cordon | 27a3c1f | 2013-08-06 07:49:27 -0700 | [diff] [blame] | 455 | notifier = CallNotifier.init(this, phone, ringer, callLogger, callStateMonitor, |
Sailesh Nepal | 23d9ed7 | 2014-07-03 09:40:26 -0700 | [diff] [blame^] | 456 | bluetoothManager); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 457 | |
| 458 | // register for ICC status |
| 459 | IccCard sim = phone.getIccCard(); |
| 460 | if (sim != null) { |
| 461 | if (VDBG) Log.v(LOG_TAG, "register for ICC status"); |
| 462 | sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null); |
| 463 | } |
| 464 | |
| 465 | // register for MMI/USSD |
| 466 | mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null); |
| 467 | |
| 468 | // register connection tracking to PhoneUtils |
| 469 | PhoneUtils.initializeConnectionHandler(mCM); |
| 470 | |
| 471 | // Read platform settings for TTY feature |
| 472 | mTtyEnabled = getResources().getBoolean(R.bool.tty_enabled); |
| 473 | |
| 474 | // Register for misc other intent broadcasts. |
| 475 | IntentFilter intentFilter = |
| 476 | new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 477 | intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 478 | intentFilter.addAction(Intent.ACTION_DOCK_EVENT); |
| 479 | intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
| 480 | intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED); |
| 481 | intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
| 482 | intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); |
| 483 | if (mTtyEnabled) { |
| 484 | intentFilter.addAction(TtyIntent.TTY_PREFERRED_MODE_CHANGE_ACTION); |
| 485 | } |
| 486 | intentFilter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
| 487 | registerReceiver(mReceiver, intentFilter); |
| 488 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 489 | //set the default values for the preferences in the phone. |
| 490 | PreferenceManager.setDefaultValues(this, R.xml.network_setting, false); |
| 491 | |
| 492 | PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false); |
| 493 | |
| 494 | // Make sure the audio mode (along with some |
| 495 | // audio-mode-related state of our own) is initialized |
| 496 | // correctly, given the current state of the phone. |
| 497 | PhoneUtils.setAudioMode(mCM); |
| 498 | } |
| 499 | |
| 500 | if (TelephonyCapabilities.supportsOtasp(phone)) { |
| 501 | cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData(); |
| 502 | cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData(); |
| 503 | cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState(); |
| 504 | cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState(); |
| 505 | } |
| 506 | |
| 507 | // XXX pre-load the SimProvider so that it's ready |
| 508 | resolver.getType(Uri.parse("content://icc/adn")); |
| 509 | |
| 510 | // start with the default value to set the mute state. |
| 511 | mShouldRestoreMuteOnInCallResume = false; |
| 512 | |
| 513 | // TODO: Register for Cdma Information Records |
| 514 | // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null); |
| 515 | |
| 516 | // Read TTY settings and store it into BP NV. |
| 517 | // AP owns (i.e. stores) the TTY setting in AP settings database and pushes the setting |
| 518 | // to BP at power up (BP does not need to make the TTY setting persistent storage). |
| 519 | // This way, there is a single owner (i.e AP) for the TTY setting in the phone. |
| 520 | if (mTtyEnabled) { |
| 521 | mPreferredTtyMode = android.provider.Settings.Secure.getInt( |
| 522 | phone.getContext().getContentResolver(), |
| 523 | android.provider.Settings.Secure.PREFERRED_TTY_MODE, |
| 524 | Phone.TTY_MODE_OFF); |
| 525 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_TTY_PREFERRED_MODE_CHANGED, 0)); |
| 526 | } |
| 527 | // Read HAC settings and configure audio hardware |
| 528 | if (getResources().getBoolean(R.bool.hac_enabled)) { |
| 529 | int hac = android.provider.Settings.System.getInt(phone.getContext().getContentResolver(), |
| 530 | android.provider.Settings.System.HEARING_AID, |
| 531 | 0); |
| 532 | AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
| 533 | audioManager.setParameter(CallFeaturesSetting.HAC_KEY, hac != 0 ? |
| 534 | CallFeaturesSetting.HAC_VAL_ON : |
| 535 | CallFeaturesSetting.HAC_VAL_OFF); |
| 536 | } |
Santos Cordon | ff506f5 | 2013-11-21 19:13:19 -0800 | [diff] [blame] | 537 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 538 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 539 | /** |
| 540 | * Returns the singleton instance of the PhoneApp. |
| 541 | */ |
Sailesh Nepal | 1eaf22b | 2014-02-22 17:00:49 -0800 | [diff] [blame] | 542 | public static PhoneGlobals getInstance() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 543 | if (sMe == null) { |
| 544 | throw new IllegalStateException("No PhoneGlobals here!"); |
| 545 | } |
| 546 | return sMe; |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * Returns the singleton instance of the PhoneApp if running as the |
| 551 | * primary user, otherwise null. |
| 552 | */ |
| 553 | static PhoneGlobals getInstanceIfPrimary() { |
| 554 | return sMe; |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * Returns the Phone associated with this instance |
| 559 | */ |
| 560 | static Phone getPhone() { |
| 561 | return getInstance().phone; |
| 562 | } |
| 563 | |
| 564 | Ringer getRinger() { |
| 565 | return ringer; |
| 566 | } |
| 567 | |
| 568 | IBluetoothHeadsetPhone getBluetoothPhoneService() { |
| 569 | return mBluetoothPhone; |
| 570 | } |
| 571 | |
Santos Cordon | 27a3c1f | 2013-08-06 07:49:27 -0700 | [diff] [blame] | 572 | /* package */ BluetoothManager getBluetoothManager() { |
| 573 | return bluetoothManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 576 | /* package */ WiredHeadsetManager getWiredHeadsetManager() { |
| 577 | return wiredHeadsetManager; |
| 578 | } |
| 579 | |
| 580 | /* package */ AudioRouter getAudioRouter() { |
| 581 | return audioRouter; |
| 582 | } |
| 583 | |
Santos Cordon | de10b75 | 2013-09-19 04:11:33 -0700 | [diff] [blame] | 584 | /* package */ CallManager getCallManager() { |
| 585 | return mCM; |
| 586 | } |
| 587 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 588 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 589 | * Returns PendingIntent for hanging up ongoing phone call. This will typically be used from |
| 590 | * Notification context. |
| 591 | */ |
| 592 | /* package */ static PendingIntent createHangUpOngoingCallPendingIntent(Context context) { |
| 593 | Intent intent = new Intent(PhoneGlobals.ACTION_HANG_UP_ONGOING_CALL, null, |
| 594 | context, NotificationBroadcastReceiver.class); |
| 595 | return PendingIntent.getBroadcast(context, 0, intent, 0); |
| 596 | } |
| 597 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 598 | boolean isSimPinEnabled() { |
| 599 | return mIsSimPinEnabled; |
| 600 | } |
| 601 | |
| 602 | boolean authenticateAgainstCachedSimPin(String pin) { |
| 603 | return (mCachedSimPin != null && mCachedSimPin.equals(pin)); |
| 604 | } |
| 605 | |
| 606 | void setCachedSimPin(String pin) { |
| 607 | mCachedSimPin = pin; |
| 608 | } |
| 609 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 610 | /** |
| 611 | * Handles OTASP-related events from the telephony layer. |
| 612 | * |
| 613 | * While an OTASP call is active, the CallNotifier forwards |
| 614 | * OTASP-related telephony events to this method. |
| 615 | */ |
| 616 | void handleOtaspEvent(Message msg) { |
| 617 | if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")..."); |
| 618 | |
| 619 | if (otaUtils == null) { |
| 620 | // We shouldn't be getting OTASP events without ever |
| 621 | // having started the OTASP call in the first place! |
| 622 | Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! " |
| 623 | + "message = " + msg); |
| 624 | return; |
| 625 | } |
| 626 | |
| 627 | otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj); |
| 628 | } |
| 629 | |
| 630 | /** |
| 631 | * Similarly, handle the disconnect event of an OTASP call |
| 632 | * by forwarding it to the OtaUtils instance. |
| 633 | */ |
| 634 | /* package */ void handleOtaspDisconnect() { |
| 635 | if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()..."); |
| 636 | |
| 637 | if (otaUtils == null) { |
| 638 | // We shouldn't be getting OTASP events without ever |
| 639 | // having started the OTASP call in the first place! |
| 640 | Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!"); |
| 641 | return; |
| 642 | } |
| 643 | |
| 644 | otaUtils.onOtaspDisconnect(); |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * Sets the activity responsible for un-PUK-blocking the device |
| 649 | * so that we may close it when we receive a positive result. |
| 650 | * mPUKEntryActivity is also used to indicate to the device that |
| 651 | * we are trying to un-PUK-lock the phone. In other words, iff |
| 652 | * it is NOT null, then we are trying to unlock and waiting for |
| 653 | * the SIM to move to READY state. |
| 654 | * |
| 655 | * @param activity is the activity to close when PUK has |
| 656 | * finished unlocking. Can be set to null to indicate the unlock |
| 657 | * or SIM READYing process is over. |
| 658 | */ |
| 659 | void setPukEntryActivity(Activity activity) { |
| 660 | mPUKEntryActivity = activity; |
| 661 | } |
| 662 | |
| 663 | Activity getPUKEntryActivity() { |
| 664 | return mPUKEntryActivity; |
| 665 | } |
| 666 | |
| 667 | /** |
| 668 | * Sets the dialog responsible for notifying the user of un-PUK- |
| 669 | * blocking - SIM READYing progress, so that we may dismiss it |
| 670 | * when we receive a positive result. |
| 671 | * |
| 672 | * @param dialog indicates the progress dialog informing the user |
| 673 | * of the state of the device. Dismissed upon completion of |
| 674 | * READYing process |
| 675 | */ |
| 676 | void setPukEntryProgressDialog(ProgressDialog dialog) { |
| 677 | mPUKEntryProgressDialog = dialog; |
| 678 | } |
| 679 | |
| 680 | ProgressDialog getPUKEntryProgressDialog() { |
| 681 | return mPUKEntryProgressDialog; |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * Controls whether or not the screen is allowed to sleep. |
| 686 | * |
| 687 | * Once sleep is allowed (WakeState is SLEEP), it will rely on the |
| 688 | * settings for the poke lock to determine when to timeout and let |
| 689 | * the device sleep {@link PhoneGlobals#setScreenTimeout}. |
| 690 | * |
| 691 | * @param ws tells the device to how to wake. |
| 692 | */ |
| 693 | /* package */ void requestWakeState(WakeState ws) { |
| 694 | if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")..."); |
| 695 | synchronized (this) { |
| 696 | if (mWakeState != ws) { |
| 697 | switch (ws) { |
| 698 | case PARTIAL: |
| 699 | // acquire the processor wake lock, and release the FULL |
| 700 | // lock if it is being held. |
| 701 | mPartialWakeLock.acquire(); |
| 702 | if (mWakeLock.isHeld()) { |
| 703 | mWakeLock.release(); |
| 704 | } |
| 705 | break; |
| 706 | case FULL: |
| 707 | // acquire the full wake lock, and release the PARTIAL |
| 708 | // lock if it is being held. |
| 709 | mWakeLock.acquire(); |
| 710 | if (mPartialWakeLock.isHeld()) { |
| 711 | mPartialWakeLock.release(); |
| 712 | } |
| 713 | break; |
| 714 | case SLEEP: |
| 715 | default: |
| 716 | // release both the PARTIAL and FULL locks. |
| 717 | if (mWakeLock.isHeld()) { |
| 718 | mWakeLock.release(); |
| 719 | } |
| 720 | if (mPartialWakeLock.isHeld()) { |
| 721 | mPartialWakeLock.release(); |
| 722 | } |
| 723 | break; |
| 724 | } |
| 725 | mWakeState = ws; |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * If we are not currently keeping the screen on, then poke the power |
| 732 | * manager to wake up the screen for the user activity timeout duration. |
| 733 | */ |
| 734 | /* package */ void wakeUpScreen() { |
| 735 | synchronized (this) { |
| 736 | if (mWakeState == WakeState.SLEEP) { |
| 737 | if (DBG) Log.d(LOG_TAG, "pulse screen lock"); |
| 738 | mPowerManager.wakeUp(SystemClock.uptimeMillis()); |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | /** |
| 744 | * Sets the wake state and screen timeout based on the current state |
| 745 | * of the phone, and the current state of the in-call UI. |
| 746 | * |
| 747 | * This method is a "UI Policy" wrapper around |
| 748 | * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}. |
| 749 | * |
| 750 | * It's safe to call this method regardless of the state of the Phone |
| 751 | * (e.g. whether or not it's idle), and regardless of the state of the |
| 752 | * Phone UI (e.g. whether or not the InCallScreen is active.) |
| 753 | */ |
| 754 | /* package */ void updateWakeState() { |
| 755 | PhoneConstants.State state = mCM.getState(); |
| 756 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 757 | // True if the speakerphone is in use. (If so, we *always* use |
| 758 | // the default timeout. Since the user is obviously not holding |
| 759 | // the phone up to his/her face, we don't need to worry about |
| 760 | // false touches, and thus don't need to turn the screen off so |
| 761 | // aggressively.) |
| 762 | // Note that we need to make a fresh call to this method any |
| 763 | // time the speaker state changes. (That happens in |
| 764 | // PhoneUtils.turnOnSpeaker().) |
| 765 | boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this); |
| 766 | |
| 767 | // TODO (bug 1440854): The screen timeout *might* also need to |
| 768 | // depend on the bluetooth state, but this isn't as clear-cut as |
| 769 | // the speaker state (since while using BT it's common for the |
| 770 | // user to put the phone straight into a pocket, in which case the |
| 771 | // timeout should probably still be short.) |
| 772 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 773 | // Decide whether to force the screen on or not. |
| 774 | // |
| 775 | // Force the screen to be on if the phone is ringing or dialing, |
| 776 | // or if we're displaying the "Call ended" UI for a connection in |
| 777 | // the "disconnected" state. |
| 778 | // However, if the phone is disconnected while the user is in the |
| 779 | // middle of selecting a quick response message, we should not force |
| 780 | // the screen to be on. |
| 781 | // |
| 782 | boolean isRinging = (state == PhoneConstants.State.RINGING); |
| 783 | boolean isDialing = (phone.getForegroundCall().getState() == Call.State.DIALING); |
Jay Shrauner | 6fe8fd6 | 2013-09-16 19:39:30 -0700 | [diff] [blame] | 784 | boolean keepScreenOn = isRinging || isDialing; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 785 | // keepScreenOn == true means we'll hold a full wake lock: |
| 786 | requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP); |
| 787 | } |
| 788 | |
| 789 | /** |
| 790 | * Manually pokes the PowerManager's userActivity method. Since we |
| 791 | * set the {@link WindowManager.LayoutParams#INPUT_FEATURE_DISABLE_USER_ACTIVITY} |
| 792 | * flag while the InCallScreen is active when there is no proximity sensor, |
| 793 | * we need to do this for touch events that really do count as user activity |
| 794 | * (like pressing any onscreen UI elements.) |
| 795 | */ |
| 796 | /* package */ void pokeUserActivity() { |
| 797 | if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()..."); |
| 798 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
| 799 | } |
| 800 | |
| 801 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 802 | * Notifies the phone app when the phone state changes. |
| 803 | * |
Santos Cordon | fc30981 | 2013-08-20 18:33:16 -0700 | [diff] [blame] | 804 | * This method will updates various states inside Phone app (e.g. update-lock state, etc.) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 805 | */ |
| 806 | /* package */ void updatePhoneState(PhoneConstants.State state) { |
| 807 | if (state != mLastPhoneState) { |
| 808 | mLastPhoneState = state; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 809 | |
| 810 | // Try to acquire or release UpdateLock. |
| 811 | // |
| 812 | // Watch out: we don't release the lock here when the screen is still in foreground. |
| 813 | // At that time InCallScreen will release it on onPause(). |
| 814 | if (state != PhoneConstants.State.IDLE) { |
| 815 | // UpdateLock is a recursive lock, while we may get "acquire" request twice and |
| 816 | // "release" request once for a single call (RINGING + OFFHOOK and IDLE). |
| 817 | // We need to manually ensure the lock is just acquired once for each (and this |
| 818 | // will prevent other possible buggy situations too). |
| 819 | if (!mUpdateLock.isHeld()) { |
| 820 | mUpdateLock.acquire(); |
| 821 | } |
| 822 | } else { |
Jay Shrauner | a5d1321 | 2013-09-19 13:37:43 -0700 | [diff] [blame] | 823 | if (mUpdateLock.isHeld()) { |
Jay Shrauner | 6fe8fd6 | 2013-09-16 19:39:30 -0700 | [diff] [blame] | 824 | mUpdateLock.release(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 825 | } |
| 826 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 827 | } |
| 828 | } |
| 829 | |
| 830 | /* package */ PhoneConstants.State getPhoneState() { |
| 831 | return mLastPhoneState; |
| 832 | } |
| 833 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 834 | KeyguardManager getKeyguardManager() { |
| 835 | return mKeyguardManager; |
| 836 | } |
| 837 | |
| 838 | private void onMMIComplete(AsyncResult r) { |
| 839 | if (VDBG) Log.d(LOG_TAG, "onMMIComplete()..."); |
| 840 | MmiCode mmiCode = (MmiCode) r.result; |
| 841 | PhoneUtils.displayMMIComplete(phone, getInstance(), mmiCode, null, null); |
| 842 | } |
| 843 | |
| 844 | private void initForNewRadioTechnology() { |
| 845 | if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology..."); |
| 846 | |
| 847 | if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 848 | // Create an instance of CdmaPhoneCallState and initialize it to IDLE |
| 849 | cdmaPhoneCallState = new CdmaPhoneCallState(); |
| 850 | cdmaPhoneCallState.CdmaPhoneCallStateInit(); |
| 851 | } |
| 852 | if (TelephonyCapabilities.supportsOtasp(phone)) { |
| 853 | //create instances of CDMA OTA data classes |
| 854 | if (cdmaOtaProvisionData == null) { |
| 855 | cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData(); |
| 856 | } |
| 857 | if (cdmaOtaConfigData == null) { |
| 858 | cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData(); |
| 859 | } |
| 860 | if (cdmaOtaScreenState == null) { |
| 861 | cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState(); |
| 862 | } |
| 863 | if (cdmaOtaInCallScreenUiState == null) { |
| 864 | cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState(); |
| 865 | } |
| 866 | } else { |
| 867 | //Clean up OTA data in GSM/UMTS. It is valid only for CDMA |
| 868 | clearOtaState(); |
| 869 | } |
| 870 | |
| 871 | ringer.updateRingerContextAfterRadioTechnologyChange(this.phone); |
| 872 | notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange(); |
| 873 | callStateMonitor.updateAfterRadioTechnologyChange(); |
| 874 | |
| 875 | if (mBluetoothPhone != null) { |
| 876 | try { |
| 877 | mBluetoothPhone.updateBtHandsfreeAfterRadioTechnologyChange(); |
| 878 | } catch (RemoteException e) { |
| 879 | Log.e(LOG_TAG, Log.getStackTraceString(new Throwable())); |
| 880 | } |
| 881 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 882 | |
| 883 | // Update registration for ICC status after radio technology change |
| 884 | IccCard sim = phone.getIccCard(); |
| 885 | if (sim != null) { |
| 886 | if (DBG) Log.d(LOG_TAG, "Update registration for ICC status..."); |
| 887 | |
| 888 | //Register all events new to the new active phone |
| 889 | sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null); |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | |
| 894 | /** |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 895 | * This is called when the wired headset state changes. |
| 896 | */ |
| 897 | @Override |
| 898 | public void onWiredHeadsetConnection(boolean pluggedIn) { |
| 899 | PhoneConstants.State phoneState = mCM.getState(); |
| 900 | |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 901 | // Force TTY state update according to new headset state |
| 902 | if (mTtyEnabled) { |
| 903 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_TTY_PREFERRED_MODE_CHANGED, 0)); |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 908 | * Receiver for misc intent broadcasts the Phone app cares about. |
| 909 | */ |
| 910 | private class PhoneAppBroadcastReceiver extends BroadcastReceiver { |
| 911 | @Override |
| 912 | public void onReceive(Context context, Intent intent) { |
| 913 | String action = intent.getAction(); |
| 914 | if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) { |
| 915 | boolean enabled = System.getInt(getContentResolver(), |
| 916 | System.AIRPLANE_MODE_ON, 0) == 0; |
| 917 | phone.setRadioPower(enabled); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 918 | } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) { |
| 919 | if (VDBG) Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED"); |
| 920 | if (VDBG) Log.d(LOG_TAG, "- state: " + intent.getStringExtra(PhoneConstants.STATE_KEY)); |
| 921 | if (VDBG) Log.d(LOG_TAG, "- reason: " |
| 922 | + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY)); |
| 923 | |
| 924 | // The "data disconnected due to roaming" notification is shown |
| 925 | // if (a) you have the "data roaming" feature turned off, and |
| 926 | // (b) you just lost data connectivity because you're roaming. |
| 927 | boolean disconnectedDueToRoaming = |
| 928 | !phone.getDataRoamingEnabled() |
| 929 | && "DISCONNECTED".equals(intent.getStringExtra(PhoneConstants.STATE_KEY)) |
| 930 | && Phone.REASON_ROAMING_ON.equals( |
| 931 | intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY)); |
| 932 | mHandler.sendEmptyMessage(disconnectedDueToRoaming |
| 933 | ? EVENT_DATA_ROAMING_DISCONNECTED |
| 934 | : EVENT_DATA_ROAMING_OK); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 935 | } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) && |
| 936 | (mPUKEntryActivity != null)) { |
| 937 | // if an attempt to un-PUK-lock the device was made, while we're |
| 938 | // receiving this state change notification, notify the handler. |
| 939 | // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has |
| 940 | // been attempted. |
| 941 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED, |
| 942 | intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE))); |
| 943 | } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) { |
| 944 | String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY); |
| 945 | Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active."); |
| 946 | initForNewRadioTechnology(); |
| 947 | } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) { |
| 948 | handleServiceStateChanged(intent); |
| 949 | } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) { |
| 950 | if (TelephonyCapabilities.supportsEcm(phone)) { |
| 951 | Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp."); |
| 952 | // Start Emergency Callback Mode service |
| 953 | if (intent.getBooleanExtra("phoneinECMState", false)) { |
| 954 | context.startService(new Intent(context, |
| 955 | EmergencyCallbackModeService.class)); |
| 956 | } |
| 957 | } else { |
| 958 | // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED |
| 959 | // on a device that doesn't support ECM in the first place. |
| 960 | Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, " |
| 961 | + "but ECM isn't supported for phone: " + phone.getPhoneName()); |
| 962 | } |
| 963 | } else if (action.equals(Intent.ACTION_DOCK_EVENT)) { |
| 964 | mDockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 965 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 966 | if (VDBG) Log.d(LOG_TAG, "ACTION_DOCK_EVENT -> mDockState = " + mDockState); |
| 967 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_DOCK_STATE_CHANGED, 0)); |
| 968 | } else if (action.equals(TtyIntent.TTY_PREFERRED_MODE_CHANGE_ACTION)) { |
| 969 | mPreferredTtyMode = intent.getIntExtra(TtyIntent.TTY_PREFFERED_MODE, |
| 970 | Phone.TTY_MODE_OFF); |
| 971 | if (VDBG) Log.d(LOG_TAG, "mReceiver: TTY_PREFERRED_MODE_CHANGE_ACTION"); |
| 972 | if (VDBG) Log.d(LOG_TAG, " mode: " + mPreferredTtyMode); |
| 973 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_TTY_PREFERRED_MODE_CHANGED, 0)); |
| 974 | } else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { |
| 975 | int ringerMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, |
| 976 | AudioManager.RINGER_MODE_NORMAL); |
| 977 | if (ringerMode == AudioManager.RINGER_MODE_SILENT) { |
| 978 | notifier.silenceRinger(); |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | } |
| 983 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 984 | /** |
| 985 | * Accepts broadcast Intents which will be prepared by {@link NotificationMgr} and thus |
| 986 | * sent from framework's notification mechanism (which is outside Phone context). |
| 987 | * This should be visible from outside, but shouldn't be in "exported" state. |
| 988 | * |
| 989 | * TODO: If possible merge this into PhoneAppBroadcastReceiver. |
| 990 | */ |
| 991 | public static class NotificationBroadcastReceiver extends BroadcastReceiver { |
| 992 | @Override |
| 993 | public void onReceive(Context context, Intent intent) { |
| 994 | String action = intent.getAction(); |
| 995 | // TODO: use "if (VDBG)" here. |
| 996 | Log.d(LOG_TAG, "Broadcast from Notification: " + action); |
| 997 | |
| 998 | if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) { |
| 999 | PhoneUtils.hangup(PhoneGlobals.getInstance().mCM); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1000 | } else { |
| 1001 | Log.w(LOG_TAG, "Received hang-up request from notification," |
| 1002 | + " but there's no call the system can hang up."); |
| 1003 | } |
| 1004 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | private void handleServiceStateChanged(Intent intent) { |
| 1008 | /** |
| 1009 | * This used to handle updating EriTextWidgetProvider this routine |
| 1010 | * and and listening for ACTION_SERVICE_STATE_CHANGED intents could |
| 1011 | * be removed. But leaving just in case it might be needed in the near |
| 1012 | * future. |
| 1013 | */ |
| 1014 | |
| 1015 | // If service just returned, start sending out the queued messages |
| 1016 | ServiceState ss = ServiceState.newFromBundle(intent.getExtras()); |
| 1017 | |
| 1018 | if (ss != null) { |
| 1019 | int state = ss.getState(); |
| 1020 | notificationMgr.updateNetworkSelection(state); |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | public boolean isOtaCallInActiveState() { |
| 1025 | boolean otaCallActive = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1026 | if (VDBG) Log.d(LOG_TAG, "- isOtaCallInActiveState " + otaCallActive); |
| 1027 | return otaCallActive; |
| 1028 | } |
| 1029 | |
| 1030 | public boolean isOtaCallInEndState() { |
| 1031 | boolean otaCallEnded = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1032 | if (VDBG) Log.d(LOG_TAG, "- isOtaCallInEndState " + otaCallEnded); |
| 1033 | return otaCallEnded; |
| 1034 | } |
| 1035 | |
| 1036 | // it is safe to call clearOtaState() even if the InCallScreen isn't active |
| 1037 | public void clearOtaState() { |
| 1038 | if (DBG) Log.d(LOG_TAG, "- clearOtaState ..."); |
Jay Shrauner | 6fe8fd6 | 2013-09-16 19:39:30 -0700 | [diff] [blame] | 1039 | if (otaUtils != null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1040 | otaUtils.cleanOtaScreen(true); |
| 1041 | if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen"); |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active |
| 1046 | public void dismissOtaDialogs() { |
| 1047 | if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ..."); |
Jay Shrauner | 6fe8fd6 | 2013-09-16 19:39:30 -0700 | [diff] [blame] | 1048 | if (otaUtils != null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1049 | otaUtils.dismissAllOtaDialogs(); |
| 1050 | if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs"); |
| 1051 | } |
| 1052 | } |
| 1053 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1054 | private void handleQueryTTYModeResponse(Message msg) { |
| 1055 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1056 | if (ar.exception != null) { |
| 1057 | if (DBG) Log.d(LOG_TAG, "handleQueryTTYModeResponse: Error getting TTY state."); |
| 1058 | } else { |
| 1059 | if (DBG) Log.d(LOG_TAG, |
| 1060 | "handleQueryTTYModeResponse: TTY enable state successfully queried."); |
| 1061 | |
| 1062 | int ttymode = ((int[]) ar.result)[0]; |
| 1063 | if (DBG) Log.d(LOG_TAG, "handleQueryTTYModeResponse:ttymode=" + ttymode); |
| 1064 | |
| 1065 | Intent ttyModeChanged = new Intent(TtyIntent.TTY_ENABLED_CHANGE_ACTION); |
| 1066 | ttyModeChanged.putExtra("ttyEnabled", ttymode != Phone.TTY_MODE_OFF); |
| 1067 | sendBroadcastAsUser(ttyModeChanged, UserHandle.ALL); |
| 1068 | |
| 1069 | String audioTtyMode; |
| 1070 | switch (ttymode) { |
| 1071 | case Phone.TTY_MODE_FULL: |
| 1072 | audioTtyMode = "tty_full"; |
| 1073 | break; |
| 1074 | case Phone.TTY_MODE_VCO: |
| 1075 | audioTtyMode = "tty_vco"; |
| 1076 | break; |
| 1077 | case Phone.TTY_MODE_HCO: |
| 1078 | audioTtyMode = "tty_hco"; |
| 1079 | break; |
| 1080 | case Phone.TTY_MODE_OFF: |
| 1081 | default: |
| 1082 | audioTtyMode = "tty_off"; |
| 1083 | break; |
| 1084 | } |
| 1085 | AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
| 1086 | audioManager.setParameters("tty_mode="+audioTtyMode); |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | private void handleSetTTYModeResponse(Message msg) { |
| 1091 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1092 | |
| 1093 | if (ar.exception != null) { |
| 1094 | if (DBG) Log.d (LOG_TAG, |
| 1095 | "handleSetTTYModeResponse: Error setting TTY mode, ar.exception" |
| 1096 | + ar.exception); |
| 1097 | } |
| 1098 | phone.queryTTYMode(mHandler.obtainMessage(EVENT_TTY_MODE_GET)); |
| 1099 | } |
| 1100 | |
| 1101 | /** |
| 1102 | * "Call origin" may be used by Contacts app to specify where the phone call comes from. |
| 1103 | * Currently, the only permitted value for this extra is {@link #ALLOWED_EXTRA_CALL_ORIGIN}. |
| 1104 | * Any other value will be ignored, to make sure that malicious apps can't trick the in-call |
| 1105 | * UI into launching some random other app after a call ends. |
| 1106 | * |
| 1107 | * TODO: make this more generic. Note that we should let the "origin" specify its package |
| 1108 | * while we are now assuming it is "com.android.contacts" |
| 1109 | */ |
| 1110 | public static final String EXTRA_CALL_ORIGIN = "com.android.phone.CALL_ORIGIN"; |
| 1111 | private static final String DEFAULT_CALL_ORIGIN_PACKAGE = "com.android.dialer"; |
| 1112 | private static final String ALLOWED_EXTRA_CALL_ORIGIN = |
| 1113 | "com.android.dialer.DialtactsActivity"; |
| 1114 | /** |
| 1115 | * Used to determine if the preserved call origin is fresh enough. |
| 1116 | */ |
| 1117 | private static final long CALL_ORIGIN_EXPIRATION_MILLIS = 30 * 1000; |
| 1118 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1119 | /** Service connection */ |
| 1120 | private final ServiceConnection mBluetoothPhoneConnection = new ServiceConnection() { |
| 1121 | |
| 1122 | /** Handle the task of binding the local object to the service */ |
| 1123 | public void onServiceConnected(ComponentName className, IBinder service) { |
| 1124 | Log.i(LOG_TAG, "Headset phone created, binding local service."); |
| 1125 | mBluetoothPhone = IBluetoothHeadsetPhone.Stub.asInterface(service); |
| 1126 | } |
| 1127 | |
| 1128 | /** Handle the task of cleaning up the local binding */ |
| 1129 | public void onServiceDisconnected(ComponentName className) { |
| 1130 | Log.i(LOG_TAG, "Headset phone disconnected, cleaning local binding."); |
| 1131 | mBluetoothPhone = null; |
| 1132 | } |
| 1133 | }; |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 1134 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1135 | } |