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; |
| 26 | import android.content.ActivityNotFoundException; |
| 27 | import android.content.BroadcastReceiver; |
| 28 | import android.content.ComponentName; |
| 29 | import android.content.ContentResolver; |
| 30 | import android.content.Context; |
| 31 | import android.content.ContextWrapper; |
| 32 | import android.content.Intent; |
| 33 | import android.content.IntentFilter; |
| 34 | import android.content.ServiceConnection; |
| 35 | import android.content.res.Configuration; |
| 36 | import android.media.AudioManager; |
| 37 | import android.net.Uri; |
| 38 | import android.os.AsyncResult; |
| 39 | import android.os.Binder; |
| 40 | import android.os.Handler; |
| 41 | import android.os.IBinder; |
| 42 | import android.os.IPowerManager; |
| 43 | import android.os.Message; |
| 44 | import android.os.PowerManager; |
| 45 | import android.os.RemoteException; |
| 46 | import android.os.ServiceManager; |
| 47 | import android.os.SystemClock; |
| 48 | import android.os.SystemProperties; |
| 49 | import android.os.UpdateLock; |
| 50 | import android.os.UserHandle; |
| 51 | import android.preference.PreferenceManager; |
| 52 | import android.provider.Settings.System; |
| 53 | import android.telephony.ServiceState; |
| 54 | import android.text.TextUtils; |
| 55 | import android.util.Log; |
| 56 | import android.util.Slog; |
| 57 | import android.view.KeyEvent; |
| 58 | |
| 59 | import com.android.internal.telephony.Call; |
| 60 | import com.android.internal.telephony.CallManager; |
| 61 | import com.android.internal.telephony.IccCard; |
| 62 | import com.android.internal.telephony.IccCardConstants; |
| 63 | import com.android.internal.telephony.MmiCode; |
| 64 | import com.android.internal.telephony.Phone; |
| 65 | import com.android.internal.telephony.PhoneConstants; |
| 66 | import com.android.internal.telephony.PhoneFactory; |
| 67 | import com.android.internal.telephony.TelephonyCapabilities; |
| 68 | import com.android.internal.telephony.TelephonyIntents; |
| 69 | import com.android.internal.telephony.cdma.TtyIntent; |
| 70 | import com.android.phone.common.CallLogAsync; |
| 71 | import com.android.phone.OtaUtils.CdmaOtaScreenState; |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 72 | import com.android.phone.WiredHeadsetManager.WiredHeadsetListener; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 73 | import com.android.server.sip.SipService; |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 74 | import com.android.services.telephony.common.AudioMode; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * Global state for the telephony subsystem when running in the primary |
| 78 | * phone process. |
| 79 | */ |
Santos Cordon | fc30981 | 2013-08-20 18:33:16 -0700 | [diff] [blame] | 80 | public class PhoneGlobals extends ContextWrapper implements WiredHeadsetListener { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 81 | /* package */ static final String LOG_TAG = "PhoneApp"; |
| 82 | |
| 83 | /** |
| 84 | * Phone app-wide debug level: |
| 85 | * 0 - no debug logging |
| 86 | * 1 - normal debug logging if ro.debuggable is set (which is true in |
| 87 | * "eng" and "userdebug" builds but not "user" builds) |
| 88 | * 2 - ultra-verbose debug logging |
| 89 | * |
| 90 | * Most individual classes in the phone app have a local DBG constant, |
| 91 | * typically set to |
| 92 | * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1) |
| 93 | * or else |
| 94 | * (PhoneApp.DBG_LEVEL >= 2) |
| 95 | * depending on the desired verbosity. |
| 96 | * |
| 97 | * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 ************* |
| 98 | */ |
| 99 | /* package */ static final int DBG_LEVEL = 0; |
| 100 | |
| 101 | private static final boolean DBG = |
| 102 | (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); |
| 103 | private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 104 | |
| 105 | // Message codes; see mHandler below. |
| 106 | private static final int EVENT_SIM_NETWORK_LOCKED = 3; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 107 | private static final int EVENT_SIM_STATE_CHANGED = 8; |
| 108 | private static final int EVENT_UPDATE_INCALL_NOTIFICATION = 9; |
| 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; |
| 112 | private static final int EVENT_DOCK_STATE_CHANGED = 13; |
| 113 | private static final int EVENT_TTY_PREFERRED_MODE_CHANGED = 14; |
| 114 | private static final int EVENT_TTY_MODE_GET = 15; |
| 115 | private static final int EVENT_TTY_MODE_SET = 16; |
| 116 | private static final int EVENT_START_SIP_SERVICE = 17; |
| 117 | |
| 118 | // The MMI codes are also used by the InCallScreen. |
| 119 | public static final int MMI_INITIATE = 51; |
| 120 | public static final int MMI_COMPLETE = 52; |
| 121 | public static final int MMI_CANCEL = 53; |
| 122 | // Don't use message codes larger than 99 here; those are reserved for |
| 123 | // the individual Activities of the Phone UI. |
| 124 | |
| 125 | /** |
| 126 | * Allowable values for the wake lock code. |
| 127 | * SLEEP means the device can be put to sleep. |
| 128 | * PARTIAL means wake the processor, but we display can be kept off. |
| 129 | * FULL means wake both the processor and the display. |
| 130 | */ |
| 131 | public enum WakeState { |
| 132 | SLEEP, |
| 133 | PARTIAL, |
| 134 | FULL |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Intent Action used for hanging up the current call from Notification bar. This will |
| 139 | * choose first ringing call, first active call, or first background call (typically in |
| 140 | * HOLDING state). |
| 141 | */ |
| 142 | public static final String ACTION_HANG_UP_ONGOING_CALL = |
| 143 | "com.android.phone.ACTION_HANG_UP_ONGOING_CALL"; |
| 144 | |
| 145 | /** |
| 146 | * Intent Action used for making a phone call from Notification bar. |
| 147 | * This is for missed call notifications. |
| 148 | */ |
| 149 | public static final String ACTION_CALL_BACK_FROM_NOTIFICATION = |
| 150 | "com.android.phone.ACTION_CALL_BACK_FROM_NOTIFICATION"; |
| 151 | |
| 152 | /** |
| 153 | * Intent Action used for sending a SMS from notification bar. |
| 154 | * This is for missed call notifications. |
| 155 | */ |
| 156 | public static final String ACTION_SEND_SMS_FROM_NOTIFICATION = |
| 157 | "com.android.phone.ACTION_SEND_SMS_FROM_NOTIFICATION"; |
| 158 | |
| 159 | private static PhoneGlobals sMe; |
| 160 | |
| 161 | // A few important fields we expose to the rest of the package |
| 162 | // directly (rather than thru set/get methods) for efficiency. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 163 | CallController callController; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 164 | CallManager mCM; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 165 | CallNotifier notifier; |
| 166 | CallerInfoCache callerInfoCache; |
| 167 | InCallUiState inCallUiState; |
| 168 | NotificationMgr notificationMgr; |
| 169 | Phone phone; |
| 170 | PhoneInterfaceManager phoneMgr; |
| 171 | |
Santos Cordon | 9b7bac7 | 2013-08-06 08:04:52 -0700 | [diff] [blame] | 172 | private AudioRouter audioRouter; |
Santos Cordon | 27a3c1f | 2013-08-06 07:49:27 -0700 | [diff] [blame] | 173 | private BluetoothManager bluetoothManager; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 174 | private CallCommandService callCommandService; |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 175 | private CallGatewayManager callGatewayManager; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 176 | private CallHandlerServiceProxy callHandlerServiceProxy; |
| 177 | private CallModeler callModeler; |
| 178 | private CallStateMonitor callStateMonitor; |
Santos Cordon | 2eaff90 | 2013-08-05 04:37:55 -0700 | [diff] [blame] | 179 | private DTMFTonePlayer dtmfTonePlayer; |
Christine Chen | ee09a49 | 2013-08-06 16:02:29 -0700 | [diff] [blame] | 180 | private RejectWithTextMessageManager rejectWithTextMessageManager; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 181 | private IBluetoothHeadsetPhone mBluetoothPhone; |
| 182 | private Ringer ringer; |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 183 | private WiredHeadsetManager wiredHeadsetManager; |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 184 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 185 | static int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 186 | static boolean sVoiceCapable = true; |
| 187 | |
| 188 | // Internal PhoneApp Call state tracker |
| 189 | CdmaPhoneCallState cdmaPhoneCallState; |
| 190 | |
| 191 | // The InCallScreen instance (or null if the InCallScreen hasn't been |
| 192 | // created yet.) |
| 193 | private InCallScreen mInCallScreen; |
| 194 | |
| 195 | // The currently-active PUK entry activity and progress dialog. |
| 196 | // Normally, these are the Emergency Dialer and the subsequent |
| 197 | // progress dialog. null if there is are no such objects in |
| 198 | // the foreground. |
| 199 | private Activity mPUKEntryActivity; |
| 200 | private ProgressDialog mPUKEntryProgressDialog; |
| 201 | |
| 202 | private boolean mIsSimPinEnabled; |
| 203 | private String mCachedSimPin; |
| 204 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 205 | // True if we are beginning a call, but the phone state has not changed yet |
| 206 | private boolean mBeginningCall; |
| 207 | |
| 208 | // Last phone state seen by updatePhoneState() |
| 209 | private PhoneConstants.State mLastPhoneState = PhoneConstants.State.IDLE; |
| 210 | |
| 211 | private WakeState mWakeState = WakeState.SLEEP; |
| 212 | |
| 213 | private PowerManager mPowerManager; |
| 214 | private IPowerManager mPowerManagerService; |
| 215 | private PowerManager.WakeLock mWakeLock; |
| 216 | private PowerManager.WakeLock mPartialWakeLock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 217 | private KeyguardManager mKeyguardManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 218 | |
| 219 | private UpdateLock mUpdateLock; |
| 220 | |
| 221 | // Broadcast receiver for various intent broadcasts (see onCreate()) |
| 222 | private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver(); |
| 223 | |
| 224 | // Broadcast receiver purely for ACTION_MEDIA_BUTTON broadcasts |
| 225 | private final BroadcastReceiver mMediaButtonReceiver = new MediaButtonBroadcastReceiver(); |
| 226 | |
| 227 | /** boolean indicating restoring mute state on InCallScreen.onResume() */ |
| 228 | private boolean mShouldRestoreMuteOnInCallResume; |
| 229 | |
| 230 | /** |
| 231 | * The singleton OtaUtils instance used for OTASP calls. |
| 232 | * |
| 233 | * The OtaUtils instance is created lazily the first time we need to |
| 234 | * make an OTASP call, regardless of whether it's an interactive or |
| 235 | * non-interactive OTASP call. |
| 236 | */ |
| 237 | public OtaUtils otaUtils; |
| 238 | |
| 239 | // Following are the CDMA OTA information Objects used during OTA Call. |
| 240 | // cdmaOtaProvisionData object store static OTA information that needs |
| 241 | // to be maintained even during Slider open/close scenarios. |
| 242 | // cdmaOtaConfigData object stores configuration info to control visiblity |
| 243 | // of each OTA Screens. |
| 244 | // cdmaOtaScreenState object store OTA Screen State information. |
| 245 | public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData; |
| 246 | public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData; |
| 247 | public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState; |
| 248 | public OtaUtils.CdmaOtaInCallScreenUiState cdmaOtaInCallScreenUiState; |
| 249 | |
| 250 | // TTY feature enabled on this platform |
| 251 | private boolean mTtyEnabled; |
| 252 | // Current TTY operating mode selected by user |
| 253 | private int mPreferredTtyMode = Phone.TTY_MODE_OFF; |
| 254 | |
| 255 | /** |
| 256 | * Set the restore mute state flag. Used when we are setting the mute state |
| 257 | * OUTSIDE of user interaction {@link PhoneUtils#startNewCall(Phone)} |
| 258 | */ |
| 259 | /*package*/void setRestoreMuteOnInCallResume (boolean mode) { |
| 260 | mShouldRestoreMuteOnInCallResume = mode; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Get the restore mute state flag. |
| 265 | * This is used by the InCallScreen {@link InCallScreen#onResume()} to figure |
| 266 | * out if we need to restore the mute state for the current active call. |
| 267 | */ |
| 268 | /*package*/boolean getRestoreMuteOnInCallResume () { |
| 269 | return mShouldRestoreMuteOnInCallResume; |
| 270 | } |
| 271 | |
| 272 | Handler mHandler = new Handler() { |
| 273 | @Override |
| 274 | public void handleMessage(Message msg) { |
| 275 | PhoneConstants.State phoneState; |
| 276 | switch (msg.what) { |
| 277 | // Starts the SIP service. It's a no-op if SIP API is not supported |
| 278 | // on the deivce. |
| 279 | // TODO: Having the phone process host the SIP service is only |
| 280 | // temporary. Will move it to a persistent communication process |
| 281 | // later. |
| 282 | case EVENT_START_SIP_SERVICE: |
| 283 | SipService.start(getApplicationContext()); |
| 284 | break; |
| 285 | |
| 286 | // TODO: This event should be handled by the lock screen, just |
| 287 | // like the "SIM missing" and "Sim locked" cases (bug 1804111). |
| 288 | case EVENT_SIM_NETWORK_LOCKED: |
| 289 | if (getResources().getBoolean(R.bool.ignore_sim_network_locked_events)) { |
| 290 | // Some products don't have the concept of a "SIM network lock" |
| 291 | Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; " |
| 292 | + "not showing 'SIM network unlock' PIN entry screen"); |
| 293 | } else { |
| 294 | // Normal case: show the "SIM network unlock" PIN entry screen. |
| 295 | // The user won't be able to do anything else until |
| 296 | // they enter a valid SIM network PIN. |
| 297 | Log.i(LOG_TAG, "show sim depersonal panel"); |
| 298 | IccNetworkDepersonalizationPanel ndpPanel = |
| 299 | new IccNetworkDepersonalizationPanel(PhoneGlobals.getInstance()); |
| 300 | ndpPanel.show(); |
| 301 | } |
| 302 | break; |
| 303 | |
| 304 | case EVENT_UPDATE_INCALL_NOTIFICATION: |
| 305 | // Tell the NotificationMgr to update the "ongoing |
| 306 | // call" icon in the status bar, if necessary. |
| 307 | // Currently, this is triggered by a bluetooth headset |
| 308 | // state change (since the status bar icon needs to |
| 309 | // turn blue when bluetooth is active.) |
| 310 | if (DBG) Log.d (LOG_TAG, "- updating in-call notification from handler..."); |
| 311 | notificationMgr.updateInCallNotification(); |
| 312 | break; |
| 313 | |
| 314 | case EVENT_DATA_ROAMING_DISCONNECTED: |
| 315 | notificationMgr.showDataDisconnectedRoaming(); |
| 316 | break; |
| 317 | |
| 318 | case EVENT_DATA_ROAMING_OK: |
| 319 | notificationMgr.hideDataDisconnectedRoaming(); |
| 320 | break; |
| 321 | |
| 322 | case MMI_COMPLETE: |
| 323 | onMMIComplete((AsyncResult) msg.obj); |
| 324 | break; |
| 325 | |
| 326 | case MMI_CANCEL: |
| 327 | PhoneUtils.cancelMmiCode(phone); |
| 328 | break; |
| 329 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 330 | case EVENT_SIM_STATE_CHANGED: |
| 331 | // Marks the event where the SIM goes into ready state. |
| 332 | // Right now, this is only used for the PUK-unlocking |
| 333 | // process. |
| 334 | if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) { |
| 335 | // when the right event is triggered and there |
| 336 | // are UI objects in the foreground, we close |
| 337 | // them to display the lock panel. |
| 338 | if (mPUKEntryActivity != null) { |
| 339 | mPUKEntryActivity.finish(); |
| 340 | mPUKEntryActivity = null; |
| 341 | } |
| 342 | if (mPUKEntryProgressDialog != null) { |
| 343 | mPUKEntryProgressDialog.dismiss(); |
| 344 | mPUKEntryProgressDialog = null; |
| 345 | } |
| 346 | } |
| 347 | break; |
| 348 | |
| 349 | case EVENT_UNSOL_CDMA_INFO_RECORD: |
| 350 | //TODO: handle message here; |
| 351 | break; |
| 352 | |
| 353 | case EVENT_DOCK_STATE_CHANGED: |
| 354 | // If the phone is docked/undocked during a call, and no wired or BT headset |
| 355 | // is connected: turn on/off the speaker accordingly. |
| 356 | boolean inDockMode = false; |
| 357 | if (mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) { |
| 358 | inDockMode = true; |
| 359 | } |
| 360 | if (VDBG) Log.d(LOG_TAG, "received EVENT_DOCK_STATE_CHANGED. Phone inDock = " |
| 361 | + inDockMode); |
| 362 | |
| 363 | phoneState = mCM.getState(); |
| 364 | if (phoneState == PhoneConstants.State.OFFHOOK && |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 365 | !wiredHeadsetManager.isHeadsetPlugged() && |
| 366 | !bluetoothManager.isBluetoothHeadsetAudioOn()) { |
| 367 | audioRouter.setSpeaker(inDockMode); |
| 368 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 369 | PhoneUtils.turnOnSpeaker(getApplicationContext(), inDockMode, true); |
| 370 | updateInCallScreen(); // Has no effect if the InCallScreen isn't visible |
| 371 | } |
| 372 | break; |
| 373 | |
| 374 | case EVENT_TTY_PREFERRED_MODE_CHANGED: |
| 375 | // TTY mode is only applied if a headset is connected |
| 376 | int ttyMode; |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 377 | if (wiredHeadsetManager.isHeadsetPlugged()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 378 | ttyMode = mPreferredTtyMode; |
| 379 | } else { |
| 380 | ttyMode = Phone.TTY_MODE_OFF; |
| 381 | } |
| 382 | phone.setTTYMode(ttyMode, mHandler.obtainMessage(EVENT_TTY_MODE_SET)); |
| 383 | break; |
| 384 | |
| 385 | case EVENT_TTY_MODE_GET: |
| 386 | handleQueryTTYModeResponse(msg); |
| 387 | break; |
| 388 | |
| 389 | case EVENT_TTY_MODE_SET: |
| 390 | handleSetTTYModeResponse(msg); |
| 391 | break; |
| 392 | } |
| 393 | } |
| 394 | }; |
| 395 | |
| 396 | public PhoneGlobals(Context context) { |
| 397 | super(context); |
| 398 | sMe = this; |
| 399 | } |
| 400 | |
| 401 | public void onCreate() { |
| 402 | if (VDBG) Log.v(LOG_TAG, "onCreate()..."); |
| 403 | |
| 404 | ContentResolver resolver = getContentResolver(); |
| 405 | |
| 406 | // Cache the "voice capable" flag. |
| 407 | // This flag currently comes from a resource (which is |
| 408 | // overrideable on a per-product basis): |
| 409 | sVoiceCapable = |
| 410 | getResources().getBoolean(com.android.internal.R.bool.config_voice_capable); |
| 411 | // ...but this might eventually become a PackageManager "system |
| 412 | // feature" instead, in which case we'd do something like: |
| 413 | // sVoiceCapable = |
| 414 | // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS); |
| 415 | |
| 416 | if (phone == null) { |
| 417 | // Initialize the telephony framework |
| 418 | PhoneFactory.makeDefaultPhones(this); |
| 419 | |
| 420 | // Get the default phone |
| 421 | phone = PhoneFactory.getDefaultPhone(); |
| 422 | |
| 423 | // Start TelephonyDebugService After the default phone is created. |
| 424 | Intent intent = new Intent(this, TelephonyDebugService.class); |
| 425 | startService(intent); |
| 426 | |
| 427 | mCM = CallManager.getInstance(); |
| 428 | mCM.registerPhone(phone); |
| 429 | |
| 430 | // Create the NotificationMgr singleton, which is used to display |
| 431 | // status bar icons and control other status bar behavior. |
| 432 | notificationMgr = NotificationMgr.init(this); |
| 433 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 434 | mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE); |
| 435 | |
| 436 | int phoneType = phone.getPhoneType(); |
| 437 | |
| 438 | if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { |
| 439 | // Create an instance of CdmaPhoneCallState and initialize it to IDLE |
| 440 | cdmaPhoneCallState = new CdmaPhoneCallState(); |
| 441 | cdmaPhoneCallState.CdmaPhoneCallStateInit(); |
| 442 | } |
| 443 | |
| 444 | if (BluetoothAdapter.getDefaultAdapter() != null) { |
| 445 | // Start BluetoothPhoneService even if device is not voice capable. |
| 446 | // The device can still support VOIP. |
| 447 | startService(new Intent(this, BluetoothPhoneService.class)); |
| 448 | bindService(new Intent(this, BluetoothPhoneService.class), |
| 449 | mBluetoothPhoneConnection, 0); |
| 450 | } else { |
| 451 | // Device is not bluetooth capable |
| 452 | mBluetoothPhone = null; |
| 453 | } |
| 454 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 455 | // before registering for phone state changes |
| 456 | mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 457 | mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG); |
| 458 | // lock used to keep the processor awake, when we don't care for the display. |
| 459 | mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK |
| 460 | | PowerManager.ON_AFTER_RELEASE, LOG_TAG); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 461 | |
| 462 | mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); |
| 463 | |
| 464 | // get a handle to the service so that we can use it later when we |
| 465 | // want to set the poke lock. |
| 466 | mPowerManagerService = IPowerManager.Stub.asInterface( |
| 467 | ServiceManager.getService("power")); |
| 468 | |
| 469 | // Get UpdateLock to suppress system-update related events (e.g. dialog show-up) |
| 470 | // during phone calls. |
| 471 | mUpdateLock = new UpdateLock("phone"); |
| 472 | |
| 473 | if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock); |
| 474 | |
| 475 | CallLogger callLogger = new CallLogger(this, new CallLogAsync()); |
| 476 | |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 477 | callGatewayManager = new CallGatewayManager(); |
| 478 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 479 | // Create the CallController singleton, which is the interface |
| 480 | // to the telephony layer for user-initiated telephony functionality |
| 481 | // (like making outgoing calls.) |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 482 | callController = CallController.init(this, callLogger, callGatewayManager); |
| 483 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 484 | // ...and also the InCallUiState instance, used by the CallController to |
| 485 | // keep track of some "persistent state" of the in-call UI. |
| 486 | inCallUiState = InCallUiState.init(this); |
| 487 | |
| 488 | // Create the CallerInfoCache singleton, which remembers custom ring tone and |
| 489 | // send-to-voicemail settings. |
| 490 | // |
| 491 | // The asynchronous caching will start just after this call. |
| 492 | callerInfoCache = CallerInfoCache.init(this); |
| 493 | |
| 494 | // Monitors call activity from the telephony layer |
| 495 | callStateMonitor = new CallStateMonitor(mCM); |
| 496 | |
Christine Chen | ee09a49 | 2013-08-06 16:02:29 -0700 | [diff] [blame] | 497 | // Rejects calls with TextMessages |
| 498 | rejectWithTextMessageManager = new RejectWithTextMessageManager(); |
| 499 | |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 500 | // Creates call models for use with CallHandlerService. |
Santos Cordon | 69a6919 | 2013-08-22 14:25:42 -0700 | [diff] [blame] | 501 | callModeler = new CallModeler(callStateMonitor, mCM, rejectWithTextMessageManager, |
| 502 | callGatewayManager); |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 503 | |
Santos Cordon | 2eaff90 | 2013-08-05 04:37:55 -0700 | [diff] [blame] | 504 | // Plays DTMF Tones |
| 505 | dtmfTonePlayer = new DTMFTonePlayer(mCM, callModeler); |
| 506 | |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 507 | // Manages wired headset state |
| 508 | wiredHeadsetManager = new WiredHeadsetManager(this); |
| 509 | wiredHeadsetManager.addWiredHeadsetListener(this); |
| 510 | |
Santos Cordon | 2c2d3cf | 2013-08-08 03:53:47 -0700 | [diff] [blame] | 511 | // Bluetooth manager |
| 512 | bluetoothManager = new BluetoothManager(this, mCM, callModeler); |
Santos Cordon | 2c2d3cf | 2013-08-08 03:53:47 -0700 | [diff] [blame] | 513 | |
| 514 | ringer = Ringer.init(this, bluetoothManager); |
| 515 | |
Santos Cordon | 9b7bac7 | 2013-08-06 08:04:52 -0700 | [diff] [blame] | 516 | // Audio router |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 517 | audioRouter = new AudioRouter(this, bluetoothManager, wiredHeadsetManager, mCM); |
Santos Cordon | 9b7bac7 | 2013-08-06 08:04:52 -0700 | [diff] [blame] | 518 | |
Santos Cordon | 249efd0 | 2013-08-05 03:33:56 -0700 | [diff] [blame] | 519 | // Service used by in-call UI to control calls |
Santos Cordon | 9b7bac7 | 2013-08-06 08:04:52 -0700 | [diff] [blame] | 520 | callCommandService = new CallCommandService(this, mCM, callModeler, dtmfTonePlayer, |
Christine Chen | ee09a49 | 2013-08-06 16:02:29 -0700 | [diff] [blame] | 521 | audioRouter, rejectWithTextMessageManager); |
Santos Cordon | 249efd0 | 2013-08-05 03:33:56 -0700 | [diff] [blame] | 522 | |
Santos Cordon | 89647a6 | 2013-07-16 13:38:09 -0700 | [diff] [blame] | 523 | // Sends call state to the UI |
Santos Cordon | 63a8424 | 2013-07-23 13:32:52 -0700 | [diff] [blame] | 524 | callHandlerServiceProxy = new CallHandlerServiceProxy(this, callModeler, |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 525 | callCommandService, audioRouter); |
Santos Cordon | 89647a6 | 2013-07-16 13:38:09 -0700 | [diff] [blame] | 526 | |
Santos Cordon | 406c034 | 2013-08-28 00:07:47 -0700 | [diff] [blame] | 527 | phoneMgr = PhoneInterfaceManager.init(this, phone, callHandlerServiceProxy); |
| 528 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 529 | // Create the CallNotifer singleton, which handles |
| 530 | // asynchronous events from the telephony layer (like |
| 531 | // launching the incoming-call UI when an incoming call comes |
| 532 | // in.) |
Santos Cordon | 27a3c1f | 2013-08-06 07:49:27 -0700 | [diff] [blame] | 533 | notifier = CallNotifier.init(this, phone, ringer, callLogger, callStateMonitor, |
Santos Cordon | a5d5db8 | 2013-09-15 13:00:34 -0700 | [diff] [blame] | 534 | bluetoothManager, callModeler); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 535 | |
| 536 | // register for ICC status |
| 537 | IccCard sim = phone.getIccCard(); |
| 538 | if (sim != null) { |
| 539 | if (VDBG) Log.v(LOG_TAG, "register for ICC status"); |
| 540 | sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null); |
| 541 | } |
| 542 | |
| 543 | // register for MMI/USSD |
| 544 | mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null); |
| 545 | |
| 546 | // register connection tracking to PhoneUtils |
| 547 | PhoneUtils.initializeConnectionHandler(mCM); |
| 548 | |
| 549 | // Read platform settings for TTY feature |
| 550 | mTtyEnabled = getResources().getBoolean(R.bool.tty_enabled); |
| 551 | |
| 552 | // Register for misc other intent broadcasts. |
| 553 | IntentFilter intentFilter = |
| 554 | new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 555 | intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 556 | intentFilter.addAction(Intent.ACTION_DOCK_EVENT); |
| 557 | intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
| 558 | intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED); |
| 559 | intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); |
| 560 | intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); |
| 561 | if (mTtyEnabled) { |
| 562 | intentFilter.addAction(TtyIntent.TTY_PREFERRED_MODE_CHANGE_ACTION); |
| 563 | } |
| 564 | intentFilter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
| 565 | registerReceiver(mReceiver, intentFilter); |
| 566 | |
| 567 | // Use a separate receiver for ACTION_MEDIA_BUTTON broadcasts, |
| 568 | // since we need to manually adjust its priority (to make sure |
| 569 | // we get these intents *before* the media player.) |
| 570 | IntentFilter mediaButtonIntentFilter = |
| 571 | new IntentFilter(Intent.ACTION_MEDIA_BUTTON); |
| 572 | // TODO verify the independent priority doesn't need to be handled thanks to the |
| 573 | // private intent handler registration |
| 574 | // Make sure we're higher priority than the media player's |
| 575 | // MediaButtonIntentReceiver (which currently has the default |
| 576 | // priority of zero; see apps/Music/AndroidManifest.xml.) |
| 577 | mediaButtonIntentFilter.setPriority(1); |
| 578 | // |
| 579 | registerReceiver(mMediaButtonReceiver, mediaButtonIntentFilter); |
| 580 | // register the component so it gets priority for calls |
| 581 | AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
| 582 | am.registerMediaButtonEventReceiverForCalls(new ComponentName(this.getPackageName(), |
| 583 | MediaButtonBroadcastReceiver.class.getName())); |
| 584 | |
| 585 | //set the default values for the preferences in the phone. |
| 586 | PreferenceManager.setDefaultValues(this, R.xml.network_setting, false); |
| 587 | |
| 588 | PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false); |
| 589 | |
| 590 | // Make sure the audio mode (along with some |
| 591 | // audio-mode-related state of our own) is initialized |
| 592 | // correctly, given the current state of the phone. |
| 593 | PhoneUtils.setAudioMode(mCM); |
| 594 | } |
| 595 | |
| 596 | if (TelephonyCapabilities.supportsOtasp(phone)) { |
| 597 | cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData(); |
| 598 | cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData(); |
| 599 | cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState(); |
| 600 | cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState(); |
| 601 | } |
| 602 | |
| 603 | // XXX pre-load the SimProvider so that it's ready |
| 604 | resolver.getType(Uri.parse("content://icc/adn")); |
| 605 | |
| 606 | // start with the default value to set the mute state. |
| 607 | mShouldRestoreMuteOnInCallResume = false; |
| 608 | |
| 609 | // TODO: Register for Cdma Information Records |
| 610 | // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null); |
| 611 | |
| 612 | // Read TTY settings and store it into BP NV. |
| 613 | // AP owns (i.e. stores) the TTY setting in AP settings database and pushes the setting |
| 614 | // to BP at power up (BP does not need to make the TTY setting persistent storage). |
| 615 | // This way, there is a single owner (i.e AP) for the TTY setting in the phone. |
| 616 | if (mTtyEnabled) { |
| 617 | mPreferredTtyMode = android.provider.Settings.Secure.getInt( |
| 618 | phone.getContext().getContentResolver(), |
| 619 | android.provider.Settings.Secure.PREFERRED_TTY_MODE, |
| 620 | Phone.TTY_MODE_OFF); |
| 621 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_TTY_PREFERRED_MODE_CHANGED, 0)); |
| 622 | } |
| 623 | // Read HAC settings and configure audio hardware |
| 624 | if (getResources().getBoolean(R.bool.hac_enabled)) { |
| 625 | int hac = android.provider.Settings.System.getInt(phone.getContext().getContentResolver(), |
| 626 | android.provider.Settings.System.HEARING_AID, |
| 627 | 0); |
| 628 | AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
| 629 | audioManager.setParameter(CallFeaturesSetting.HAC_KEY, hac != 0 ? |
| 630 | CallFeaturesSetting.HAC_VAL_ON : |
| 631 | CallFeaturesSetting.HAC_VAL_OFF); |
| 632 | } |
| 633 | } |
| 634 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 635 | /** |
| 636 | * Returns the singleton instance of the PhoneApp. |
| 637 | */ |
| 638 | static PhoneGlobals getInstance() { |
| 639 | if (sMe == null) { |
| 640 | throw new IllegalStateException("No PhoneGlobals here!"); |
| 641 | } |
| 642 | return sMe; |
| 643 | } |
| 644 | |
| 645 | /** |
| 646 | * Returns the singleton instance of the PhoneApp if running as the |
| 647 | * primary user, otherwise null. |
| 648 | */ |
| 649 | static PhoneGlobals getInstanceIfPrimary() { |
| 650 | return sMe; |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * Returns the Phone associated with this instance |
| 655 | */ |
| 656 | static Phone getPhone() { |
| 657 | return getInstance().phone; |
| 658 | } |
| 659 | |
| 660 | Ringer getRinger() { |
| 661 | return ringer; |
| 662 | } |
| 663 | |
| 664 | IBluetoothHeadsetPhone getBluetoothPhoneService() { |
| 665 | return mBluetoothPhone; |
| 666 | } |
| 667 | |
Santos Cordon | 27a3c1f | 2013-08-06 07:49:27 -0700 | [diff] [blame] | 668 | /* package */ BluetoothManager getBluetoothManager() { |
| 669 | return bluetoothManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 672 | /* package */ WiredHeadsetManager getWiredHeadsetManager() { |
| 673 | return wiredHeadsetManager; |
| 674 | } |
| 675 | |
| 676 | /* package */ AudioRouter getAudioRouter() { |
| 677 | return audioRouter; |
| 678 | } |
| 679 | |
Santos Cordon | ad1ed6d | 2013-09-16 03:04:23 -0700 | [diff] [blame^] | 680 | /* package */ CallModeler getCallModeler() { |
| 681 | return callModeler; |
| 682 | } |
| 683 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 684 | /** |
| 685 | * Returns an Intent that can be used to go to the "Call log" |
| 686 | * UI (aka CallLogActivity) in the Contacts app. |
| 687 | * |
| 688 | * Watch out: there's no guarantee that the system has any activity to |
| 689 | * handle this intent. (In particular there may be no "Call log" at |
| 690 | * all on on non-voice-capable devices.) |
| 691 | */ |
| 692 | /* package */ static Intent createCallLogIntent() { |
| 693 | Intent intent = new Intent(Intent.ACTION_VIEW, null); |
| 694 | intent.setType("vnd.android.cursor.dir/calls"); |
| 695 | return intent; |
| 696 | } |
| 697 | |
Yorke Lee | ca6ec3b | 2013-08-29 14:21:43 -0700 | [diff] [blame] | 698 | /* package */static PendingIntent createPendingCallLogIntent(Context context) { |
| 699 | final Intent callLogIntent = PhoneGlobals.createCallLogIntent(); |
| 700 | final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); |
| 701 | taskStackBuilder.addNextIntent(callLogIntent); |
| 702 | return taskStackBuilder.getPendingIntent(0, 0); |
| 703 | } |
| 704 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 705 | /** |
| 706 | * Return an Intent that can be used to bring up the in-call screen. |
| 707 | * |
| 708 | * This intent can only be used from within the Phone app, since the |
| 709 | * InCallScreen is not exported from our AndroidManifest. |
| 710 | */ |
| 711 | /* package */ static Intent createInCallIntent() { |
| 712 | Intent intent = new Intent(Intent.ACTION_MAIN, null); |
| 713 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 714 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 715 | | Intent.FLAG_ACTIVITY_NO_USER_ACTION); |
| 716 | intent.setClassName("com.android.phone", getCallScreenClassName()); |
| 717 | return intent; |
| 718 | } |
| 719 | |
| 720 | /** |
| 721 | * Variation of createInCallIntent() that also specifies whether the |
| 722 | * DTMF dialpad should be initially visible when the InCallScreen |
| 723 | * comes up. |
| 724 | */ |
| 725 | /* package */ static Intent createInCallIntent(boolean showDialpad) { |
| 726 | Intent intent = createInCallIntent(); |
| 727 | intent.putExtra(InCallScreen.SHOW_DIALPAD_EXTRA, showDialpad); |
| 728 | return intent; |
| 729 | } |
| 730 | |
| 731 | /** |
| 732 | * Returns PendingIntent for hanging up ongoing phone call. This will typically be used from |
| 733 | * Notification context. |
| 734 | */ |
| 735 | /* package */ static PendingIntent createHangUpOngoingCallPendingIntent(Context context) { |
| 736 | Intent intent = new Intent(PhoneGlobals.ACTION_HANG_UP_ONGOING_CALL, null, |
| 737 | context, NotificationBroadcastReceiver.class); |
| 738 | return PendingIntent.getBroadcast(context, 0, intent, 0); |
| 739 | } |
| 740 | |
| 741 | /* package */ static PendingIntent getCallBackPendingIntent(Context context, String number) { |
| 742 | Intent intent = new Intent(ACTION_CALL_BACK_FROM_NOTIFICATION, |
| 743 | Uri.fromParts(Constants.SCHEME_TEL, number, null), |
| 744 | context, NotificationBroadcastReceiver.class); |
| 745 | return PendingIntent.getBroadcast(context, 0, intent, 0); |
| 746 | } |
| 747 | |
| 748 | /* package */ static PendingIntent getSendSmsFromNotificationPendingIntent( |
| 749 | Context context, String number) { |
| 750 | Intent intent = new Intent(ACTION_SEND_SMS_FROM_NOTIFICATION, |
| 751 | Uri.fromParts(Constants.SCHEME_SMSTO, number, null), |
| 752 | context, NotificationBroadcastReceiver.class); |
| 753 | return PendingIntent.getBroadcast(context, 0, intent, 0); |
| 754 | } |
| 755 | |
| 756 | private static String getCallScreenClassName() { |
Chiao Cheng | 7f7c652 | 2013-07-16 18:39:35 -0700 | [diff] [blame] | 757 | //InCallScreen.class.getName(); |
| 758 | return "blah"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | /** |
| 762 | * Starts the InCallScreen Activity. |
| 763 | */ |
| 764 | /* package */ void displayCallScreen() { |
| 765 | if (VDBG) Log.d(LOG_TAG, "displayCallScreen()..."); |
| 766 | |
| 767 | // On non-voice-capable devices we shouldn't ever be trying to |
| 768 | // bring up the InCallScreen in the first place. |
| 769 | if (!sVoiceCapable) { |
| 770 | Log.w(LOG_TAG, "displayCallScreen() not allowed: non-voice-capable device", |
| 771 | new Throwable("stack dump")); // Include a stack trace since this warning |
| 772 | // indicates a bug in our caller |
| 773 | return; |
| 774 | } |
| 775 | |
| 776 | try { |
Chiao Cheng | 7f7c652 | 2013-07-16 18:39:35 -0700 | [diff] [blame] | 777 | //startActivity(createInCallIntent()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 778 | } catch (ActivityNotFoundException e) { |
| 779 | // It's possible that the in-call UI might not exist (like on |
| 780 | // non-voice-capable devices), so don't crash if someone |
| 781 | // accidentally tries to bring it up... |
| 782 | Log.w(LOG_TAG, "displayCallScreen: transition to InCallScreen failed: " + e); |
| 783 | } |
| 784 | Profiler.callScreenRequested(); |
| 785 | } |
| 786 | |
| 787 | boolean isSimPinEnabled() { |
| 788 | return mIsSimPinEnabled; |
| 789 | } |
| 790 | |
| 791 | boolean authenticateAgainstCachedSimPin(String pin) { |
| 792 | return (mCachedSimPin != null && mCachedSimPin.equals(pin)); |
| 793 | } |
| 794 | |
| 795 | void setCachedSimPin(String pin) { |
| 796 | mCachedSimPin = pin; |
| 797 | } |
| 798 | |
| 799 | void setInCallScreenInstance(InCallScreen inCallScreen) { |
| 800 | mInCallScreen = inCallScreen; |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * @return true if the in-call UI is running as the foreground |
| 805 | * activity. (In other words, from the perspective of the |
| 806 | * InCallScreen activity, return true between onResume() and |
| 807 | * onPause().) |
| 808 | * |
| 809 | * Note this method will return false if the screen is currently off, |
| 810 | * even if the InCallScreen *was* in the foreground just before the |
| 811 | * screen turned off. (This is because the foreground activity is |
| 812 | * always "paused" while the screen is off.) |
| 813 | */ |
| 814 | boolean isShowingCallScreen() { |
| 815 | if (mInCallScreen == null) return false; |
| 816 | return mInCallScreen.isForegroundActivity(); |
| 817 | } |
| 818 | |
| 819 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 820 | * Dismisses the in-call UI. |
| 821 | * |
| 822 | * This also ensures that you won't be able to get back to the in-call |
| 823 | * UI via the BACK button (since this call removes the InCallScreen |
| 824 | * from the activity history.) |
| 825 | * For OTA Call, it call InCallScreen api to handle OTA Call End scenario |
| 826 | * to display OTA Call End screen. |
| 827 | */ |
| 828 | /* package */ void dismissCallScreen() { |
| 829 | if (mInCallScreen != null) { |
| 830 | if ((TelephonyCapabilities.supportsOtasp(phone)) && |
| 831 | (mInCallScreen.isOtaCallInActiveState() |
| 832 | || mInCallScreen.isOtaCallInEndState() |
| 833 | || ((cdmaOtaScreenState != null) |
| 834 | && (cdmaOtaScreenState.otaScreenState |
| 835 | != CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED)))) { |
| 836 | // TODO: During OTA Call, display should not become dark to |
| 837 | // allow user to see OTA UI update. Phone app needs to hold |
| 838 | // a SCREEN_DIM_WAKE_LOCK wake lock during the entire OTA call. |
| 839 | wakeUpScreen(); |
| 840 | // If InCallScreen is not in foreground we resume it to show the OTA call end screen |
| 841 | // Fire off the InCallScreen intent |
| 842 | displayCallScreen(); |
| 843 | |
| 844 | mInCallScreen.handleOtaCallEnd(); |
| 845 | return; |
| 846 | } else { |
| 847 | mInCallScreen.finish(); |
| 848 | } |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * Handles OTASP-related events from the telephony layer. |
| 854 | * |
| 855 | * While an OTASP call is active, the CallNotifier forwards |
| 856 | * OTASP-related telephony events to this method. |
| 857 | */ |
| 858 | void handleOtaspEvent(Message msg) { |
| 859 | if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")..."); |
| 860 | |
| 861 | if (otaUtils == null) { |
| 862 | // We shouldn't be getting OTASP events without ever |
| 863 | // having started the OTASP call in the first place! |
| 864 | Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! " |
| 865 | + "message = " + msg); |
| 866 | return; |
| 867 | } |
| 868 | |
| 869 | otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj); |
| 870 | } |
| 871 | |
| 872 | /** |
| 873 | * Similarly, handle the disconnect event of an OTASP call |
| 874 | * by forwarding it to the OtaUtils instance. |
| 875 | */ |
| 876 | /* package */ void handleOtaspDisconnect() { |
| 877 | if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()..."); |
| 878 | |
| 879 | if (otaUtils == null) { |
| 880 | // We shouldn't be getting OTASP events without ever |
| 881 | // having started the OTASP call in the first place! |
| 882 | Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!"); |
| 883 | return; |
| 884 | } |
| 885 | |
| 886 | otaUtils.onOtaspDisconnect(); |
| 887 | } |
| 888 | |
| 889 | /** |
| 890 | * Sets the activity responsible for un-PUK-blocking the device |
| 891 | * so that we may close it when we receive a positive result. |
| 892 | * mPUKEntryActivity is also used to indicate to the device that |
| 893 | * we are trying to un-PUK-lock the phone. In other words, iff |
| 894 | * it is NOT null, then we are trying to unlock and waiting for |
| 895 | * the SIM to move to READY state. |
| 896 | * |
| 897 | * @param activity is the activity to close when PUK has |
| 898 | * finished unlocking. Can be set to null to indicate the unlock |
| 899 | * or SIM READYing process is over. |
| 900 | */ |
| 901 | void setPukEntryActivity(Activity activity) { |
| 902 | mPUKEntryActivity = activity; |
| 903 | } |
| 904 | |
| 905 | Activity getPUKEntryActivity() { |
| 906 | return mPUKEntryActivity; |
| 907 | } |
| 908 | |
| 909 | /** |
| 910 | * Sets the dialog responsible for notifying the user of un-PUK- |
| 911 | * blocking - SIM READYing progress, so that we may dismiss it |
| 912 | * when we receive a positive result. |
| 913 | * |
| 914 | * @param dialog indicates the progress dialog informing the user |
| 915 | * of the state of the device. Dismissed upon completion of |
| 916 | * READYing process |
| 917 | */ |
| 918 | void setPukEntryProgressDialog(ProgressDialog dialog) { |
| 919 | mPUKEntryProgressDialog = dialog; |
| 920 | } |
| 921 | |
| 922 | ProgressDialog getPUKEntryProgressDialog() { |
| 923 | return mPUKEntryProgressDialog; |
| 924 | } |
| 925 | |
| 926 | /** |
| 927 | * Controls whether or not the screen is allowed to sleep. |
| 928 | * |
| 929 | * Once sleep is allowed (WakeState is SLEEP), it will rely on the |
| 930 | * settings for the poke lock to determine when to timeout and let |
| 931 | * the device sleep {@link PhoneGlobals#setScreenTimeout}. |
| 932 | * |
| 933 | * @param ws tells the device to how to wake. |
| 934 | */ |
| 935 | /* package */ void requestWakeState(WakeState ws) { |
| 936 | if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")..."); |
| 937 | synchronized (this) { |
| 938 | if (mWakeState != ws) { |
| 939 | switch (ws) { |
| 940 | case PARTIAL: |
| 941 | // acquire the processor wake lock, and release the FULL |
| 942 | // lock if it is being held. |
| 943 | mPartialWakeLock.acquire(); |
| 944 | if (mWakeLock.isHeld()) { |
| 945 | mWakeLock.release(); |
| 946 | } |
| 947 | break; |
| 948 | case FULL: |
| 949 | // acquire the full wake lock, and release the PARTIAL |
| 950 | // lock if it is being held. |
| 951 | mWakeLock.acquire(); |
| 952 | if (mPartialWakeLock.isHeld()) { |
| 953 | mPartialWakeLock.release(); |
| 954 | } |
| 955 | break; |
| 956 | case SLEEP: |
| 957 | default: |
| 958 | // release both the PARTIAL and FULL locks. |
| 959 | if (mWakeLock.isHeld()) { |
| 960 | mWakeLock.release(); |
| 961 | } |
| 962 | if (mPartialWakeLock.isHeld()) { |
| 963 | mPartialWakeLock.release(); |
| 964 | } |
| 965 | break; |
| 966 | } |
| 967 | mWakeState = ws; |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | /** |
| 973 | * If we are not currently keeping the screen on, then poke the power |
| 974 | * manager to wake up the screen for the user activity timeout duration. |
| 975 | */ |
| 976 | /* package */ void wakeUpScreen() { |
| 977 | synchronized (this) { |
| 978 | if (mWakeState == WakeState.SLEEP) { |
| 979 | if (DBG) Log.d(LOG_TAG, "pulse screen lock"); |
| 980 | mPowerManager.wakeUp(SystemClock.uptimeMillis()); |
| 981 | } |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | /** |
| 986 | * Sets the wake state and screen timeout based on the current state |
| 987 | * of the phone, and the current state of the in-call UI. |
| 988 | * |
| 989 | * This method is a "UI Policy" wrapper around |
| 990 | * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}. |
| 991 | * |
| 992 | * It's safe to call this method regardless of the state of the Phone |
| 993 | * (e.g. whether or not it's idle), and regardless of the state of the |
| 994 | * Phone UI (e.g. whether or not the InCallScreen is active.) |
| 995 | */ |
| 996 | /* package */ void updateWakeState() { |
| 997 | PhoneConstants.State state = mCM.getState(); |
| 998 | |
| 999 | // True if the in-call UI is the foreground activity. |
| 1000 | // (Note this will be false if the screen is currently off, |
| 1001 | // since in that case *no* activity is in the foreground.) |
| 1002 | boolean isShowingCallScreen = isShowingCallScreen(); |
| 1003 | |
| 1004 | // True if the InCallScreen's DTMF dialer is currently opened. |
| 1005 | // (Note this does NOT imply whether or not the InCallScreen |
| 1006 | // itself is visible.) |
| 1007 | boolean isDialerOpened = (mInCallScreen != null) && mInCallScreen.isDialerOpened(); |
| 1008 | |
| 1009 | // True if the speakerphone is in use. (If so, we *always* use |
| 1010 | // the default timeout. Since the user is obviously not holding |
| 1011 | // the phone up to his/her face, we don't need to worry about |
| 1012 | // false touches, and thus don't need to turn the screen off so |
| 1013 | // aggressively.) |
| 1014 | // Note that we need to make a fresh call to this method any |
| 1015 | // time the speaker state changes. (That happens in |
| 1016 | // PhoneUtils.turnOnSpeaker().) |
| 1017 | boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this); |
| 1018 | |
| 1019 | // TODO (bug 1440854): The screen timeout *might* also need to |
| 1020 | // depend on the bluetooth state, but this isn't as clear-cut as |
| 1021 | // the speaker state (since while using BT it's common for the |
| 1022 | // user to put the phone straight into a pocket, in which case the |
| 1023 | // timeout should probably still be short.) |
| 1024 | |
| 1025 | if (DBG) Log.d(LOG_TAG, "updateWakeState: callscreen " + isShowingCallScreen |
| 1026 | + ", dialer " + isDialerOpened |
| 1027 | + ", speaker " + isSpeakerInUse + "..."); |
| 1028 | |
| 1029 | // |
| 1030 | // Decide whether to force the screen on or not. |
| 1031 | // |
| 1032 | // Force the screen to be on if the phone is ringing or dialing, |
| 1033 | // or if we're displaying the "Call ended" UI for a connection in |
| 1034 | // the "disconnected" state. |
| 1035 | // However, if the phone is disconnected while the user is in the |
| 1036 | // middle of selecting a quick response message, we should not force |
| 1037 | // the screen to be on. |
| 1038 | // |
| 1039 | boolean isRinging = (state == PhoneConstants.State.RINGING); |
| 1040 | boolean isDialing = (phone.getForegroundCall().getState() == Call.State.DIALING); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1041 | boolean showingDisconnectedConnection = |
| 1042 | PhoneUtils.hasDisconnectedConnections(phone) && isShowingCallScreen; |
Christine Chen | 0ce0e85 | 2013-08-09 18:26:31 -0700 | [diff] [blame] | 1043 | boolean keepScreenOn = isRinging || isDialing || showingDisconnectedConnection; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1044 | if (DBG) Log.d(LOG_TAG, "updateWakeState: keepScreenOn = " + keepScreenOn |
| 1045 | + " (isRinging " + isRinging |
| 1046 | + ", isDialing " + isDialing |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1047 | + ", showingDisc " + showingDisconnectedConnection + ")"); |
| 1048 | // keepScreenOn == true means we'll hold a full wake lock: |
| 1049 | requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP); |
| 1050 | } |
| 1051 | |
| 1052 | /** |
| 1053 | * Manually pokes the PowerManager's userActivity method. Since we |
| 1054 | * set the {@link WindowManager.LayoutParams#INPUT_FEATURE_DISABLE_USER_ACTIVITY} |
| 1055 | * flag while the InCallScreen is active when there is no proximity sensor, |
| 1056 | * we need to do this for touch events that really do count as user activity |
| 1057 | * (like pressing any onscreen UI elements.) |
| 1058 | */ |
| 1059 | /* package */ void pokeUserActivity() { |
| 1060 | if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()..."); |
| 1061 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
| 1062 | } |
| 1063 | |
| 1064 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1065 | * Notifies the phone app when the phone state changes. |
| 1066 | * |
Santos Cordon | fc30981 | 2013-08-20 18:33:16 -0700 | [diff] [blame] | 1067 | * 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] | 1068 | */ |
| 1069 | /* package */ void updatePhoneState(PhoneConstants.State state) { |
| 1070 | if (state != mLastPhoneState) { |
| 1071 | mLastPhoneState = state; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1072 | |
| 1073 | // Try to acquire or release UpdateLock. |
| 1074 | // |
| 1075 | // Watch out: we don't release the lock here when the screen is still in foreground. |
| 1076 | // At that time InCallScreen will release it on onPause(). |
| 1077 | if (state != PhoneConstants.State.IDLE) { |
| 1078 | // UpdateLock is a recursive lock, while we may get "acquire" request twice and |
| 1079 | // "release" request once for a single call (RINGING + OFFHOOK and IDLE). |
| 1080 | // We need to manually ensure the lock is just acquired once for each (and this |
| 1081 | // will prevent other possible buggy situations too). |
| 1082 | if (!mUpdateLock.isHeld()) { |
| 1083 | mUpdateLock.acquire(); |
| 1084 | } |
| 1085 | } else { |
| 1086 | if (!isShowingCallScreen()) { |
| 1087 | if (!mUpdateLock.isHeld()) { |
| 1088 | mUpdateLock.release(); |
| 1089 | } |
| 1090 | } else { |
| 1091 | // For this case InCallScreen will take care of the release() call. |
| 1092 | } |
| 1093 | } |
| 1094 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1095 | // While we are in call, the in-call screen should dismiss the keyguard. |
| 1096 | // This allows the user to press Home to go directly home without going through |
| 1097 | // an insecure lock screen. |
| 1098 | // But we do not want to do this if there is no active call so we do not |
| 1099 | // bypass the keyguard if the call is not answered or declined. |
| 1100 | if (mInCallScreen != null) { |
| 1101 | mInCallScreen.updateKeyguardPolicy(state == PhoneConstants.State.OFFHOOK); |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | /* package */ PhoneConstants.State getPhoneState() { |
| 1107 | return mLastPhoneState; |
| 1108 | } |
| 1109 | |
| 1110 | /** |
| 1111 | * Returns UpdateLock object. |
| 1112 | */ |
| 1113 | /* package */ UpdateLock getUpdateLock() { |
| 1114 | return mUpdateLock; |
| 1115 | } |
| 1116 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1117 | KeyguardManager getKeyguardManager() { |
| 1118 | return mKeyguardManager; |
| 1119 | } |
| 1120 | |
| 1121 | private void onMMIComplete(AsyncResult r) { |
| 1122 | if (VDBG) Log.d(LOG_TAG, "onMMIComplete()..."); |
| 1123 | MmiCode mmiCode = (MmiCode) r.result; |
| 1124 | PhoneUtils.displayMMIComplete(phone, getInstance(), mmiCode, null, null); |
| 1125 | } |
| 1126 | |
| 1127 | private void initForNewRadioTechnology() { |
| 1128 | if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology..."); |
| 1129 | |
| 1130 | if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 1131 | // Create an instance of CdmaPhoneCallState and initialize it to IDLE |
| 1132 | cdmaPhoneCallState = new CdmaPhoneCallState(); |
| 1133 | cdmaPhoneCallState.CdmaPhoneCallStateInit(); |
| 1134 | } |
| 1135 | if (TelephonyCapabilities.supportsOtasp(phone)) { |
| 1136 | //create instances of CDMA OTA data classes |
| 1137 | if (cdmaOtaProvisionData == null) { |
| 1138 | cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData(); |
| 1139 | } |
| 1140 | if (cdmaOtaConfigData == null) { |
| 1141 | cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData(); |
| 1142 | } |
| 1143 | if (cdmaOtaScreenState == null) { |
| 1144 | cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState(); |
| 1145 | } |
| 1146 | if (cdmaOtaInCallScreenUiState == null) { |
| 1147 | cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState(); |
| 1148 | } |
| 1149 | } else { |
| 1150 | //Clean up OTA data in GSM/UMTS. It is valid only for CDMA |
| 1151 | clearOtaState(); |
| 1152 | } |
| 1153 | |
| 1154 | ringer.updateRingerContextAfterRadioTechnologyChange(this.phone); |
| 1155 | notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange(); |
| 1156 | callStateMonitor.updateAfterRadioTechnologyChange(); |
| 1157 | |
| 1158 | if (mBluetoothPhone != null) { |
| 1159 | try { |
| 1160 | mBluetoothPhone.updateBtHandsfreeAfterRadioTechnologyChange(); |
| 1161 | } catch (RemoteException e) { |
| 1162 | Log.e(LOG_TAG, Log.getStackTraceString(new Throwable())); |
| 1163 | } |
| 1164 | } |
| 1165 | if (mInCallScreen != null) { |
| 1166 | mInCallScreen.updateAfterRadioTechnologyChange(); |
| 1167 | } |
| 1168 | |
| 1169 | // Update registration for ICC status after radio technology change |
| 1170 | IccCard sim = phone.getIccCard(); |
| 1171 | if (sim != null) { |
| 1172 | if (DBG) Log.d(LOG_TAG, "Update registration for ICC status..."); |
| 1173 | |
| 1174 | //Register all events new to the new active phone |
| 1175 | sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null); |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | |
| 1180 | /** |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 1181 | * This is called when the wired headset state changes. |
| 1182 | */ |
| 1183 | @Override |
| 1184 | public void onWiredHeadsetConnection(boolean pluggedIn) { |
| 1185 | PhoneConstants.State phoneState = mCM.getState(); |
| 1186 | |
Santos Cordon | 593ab38 | 2013-08-06 21:58:23 -0700 | [diff] [blame] | 1187 | // Force TTY state update according to new headset state |
| 1188 | if (mTtyEnabled) { |
| 1189 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_TTY_PREFERRED_MODE_CHANGED, 0)); |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1194 | * Receiver for misc intent broadcasts the Phone app cares about. |
| 1195 | */ |
| 1196 | private class PhoneAppBroadcastReceiver extends BroadcastReceiver { |
| 1197 | @Override |
| 1198 | public void onReceive(Context context, Intent intent) { |
| 1199 | String action = intent.getAction(); |
| 1200 | if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) { |
| 1201 | boolean enabled = System.getInt(getContentResolver(), |
| 1202 | System.AIRPLANE_MODE_ON, 0) == 0; |
| 1203 | phone.setRadioPower(enabled); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1204 | } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) { |
| 1205 | if (VDBG) Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED"); |
| 1206 | if (VDBG) Log.d(LOG_TAG, "- state: " + intent.getStringExtra(PhoneConstants.STATE_KEY)); |
| 1207 | if (VDBG) Log.d(LOG_TAG, "- reason: " |
| 1208 | + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY)); |
| 1209 | |
| 1210 | // The "data disconnected due to roaming" notification is shown |
| 1211 | // if (a) you have the "data roaming" feature turned off, and |
| 1212 | // (b) you just lost data connectivity because you're roaming. |
| 1213 | boolean disconnectedDueToRoaming = |
| 1214 | !phone.getDataRoamingEnabled() |
| 1215 | && "DISCONNECTED".equals(intent.getStringExtra(PhoneConstants.STATE_KEY)) |
| 1216 | && Phone.REASON_ROAMING_ON.equals( |
| 1217 | intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY)); |
| 1218 | mHandler.sendEmptyMessage(disconnectedDueToRoaming |
| 1219 | ? EVENT_DATA_ROAMING_DISCONNECTED |
| 1220 | : EVENT_DATA_ROAMING_OK); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1221 | } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) && |
| 1222 | (mPUKEntryActivity != null)) { |
| 1223 | // if an attempt to un-PUK-lock the device was made, while we're |
| 1224 | // receiving this state change notification, notify the handler. |
| 1225 | // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has |
| 1226 | // been attempted. |
| 1227 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED, |
| 1228 | intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE))); |
| 1229 | } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) { |
| 1230 | String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY); |
| 1231 | Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active."); |
| 1232 | initForNewRadioTechnology(); |
| 1233 | } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) { |
| 1234 | handleServiceStateChanged(intent); |
| 1235 | } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) { |
| 1236 | if (TelephonyCapabilities.supportsEcm(phone)) { |
| 1237 | Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp."); |
| 1238 | // Start Emergency Callback Mode service |
| 1239 | if (intent.getBooleanExtra("phoneinECMState", false)) { |
| 1240 | context.startService(new Intent(context, |
| 1241 | EmergencyCallbackModeService.class)); |
| 1242 | } |
| 1243 | } else { |
| 1244 | // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED |
| 1245 | // on a device that doesn't support ECM in the first place. |
| 1246 | Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, " |
| 1247 | + "but ECM isn't supported for phone: " + phone.getPhoneName()); |
| 1248 | } |
| 1249 | } else if (action.equals(Intent.ACTION_DOCK_EVENT)) { |
| 1250 | mDockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1251 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1252 | if (VDBG) Log.d(LOG_TAG, "ACTION_DOCK_EVENT -> mDockState = " + mDockState); |
| 1253 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_DOCK_STATE_CHANGED, 0)); |
| 1254 | } else if (action.equals(TtyIntent.TTY_PREFERRED_MODE_CHANGE_ACTION)) { |
| 1255 | mPreferredTtyMode = intent.getIntExtra(TtyIntent.TTY_PREFFERED_MODE, |
| 1256 | Phone.TTY_MODE_OFF); |
| 1257 | if (VDBG) Log.d(LOG_TAG, "mReceiver: TTY_PREFERRED_MODE_CHANGE_ACTION"); |
| 1258 | if (VDBG) Log.d(LOG_TAG, " mode: " + mPreferredTtyMode); |
| 1259 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_TTY_PREFERRED_MODE_CHANGED, 0)); |
| 1260 | } else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { |
| 1261 | int ringerMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, |
| 1262 | AudioManager.RINGER_MODE_NORMAL); |
| 1263 | if (ringerMode == AudioManager.RINGER_MODE_SILENT) { |
| 1264 | notifier.silenceRinger(); |
| 1265 | } |
| 1266 | } |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | /** |
| 1271 | * Broadcast receiver for the ACTION_MEDIA_BUTTON broadcast intent. |
| 1272 | * |
| 1273 | * This functionality isn't lumped in with the other intents in |
| 1274 | * PhoneAppBroadcastReceiver because we instantiate this as a totally |
| 1275 | * separate BroadcastReceiver instance, since we need to manually |
| 1276 | * adjust its IntentFilter's priority (to make sure we get these |
| 1277 | * intents *before* the media player.) |
| 1278 | */ |
| 1279 | private class MediaButtonBroadcastReceiver extends BroadcastReceiver { |
| 1280 | @Override |
| 1281 | public void onReceive(Context context, Intent intent) { |
| 1282 | KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); |
| 1283 | if (VDBG) Log.d(LOG_TAG, |
| 1284 | "MediaButtonBroadcastReceiver.onReceive()... event = " + event); |
| 1285 | if ((event != null) |
| 1286 | && (event.getKeyCode() == KeyEvent.KEYCODE_HEADSETHOOK)) { |
| 1287 | if (VDBG) Log.d(LOG_TAG, "MediaButtonBroadcastReceiver: HEADSETHOOK"); |
| 1288 | boolean consumed = PhoneUtils.handleHeadsetHook(phone, event); |
| 1289 | if (VDBG) Log.d(LOG_TAG, "==> handleHeadsetHook(): consumed = " + consumed); |
| 1290 | if (consumed) { |
| 1291 | // If a headset is attached and the press is consumed, also update |
| 1292 | // any UI items (such as an InCallScreen mute button) that may need to |
| 1293 | // be updated if their state changed. |
| 1294 | updateInCallScreen(); // Has no effect if the InCallScreen isn't visible |
| 1295 | abortBroadcast(); |
| 1296 | } |
| 1297 | } else { |
| 1298 | if (mCM.getState() != PhoneConstants.State.IDLE) { |
| 1299 | // If the phone is anything other than completely idle, |
| 1300 | // then we consume and ignore any media key events, |
| 1301 | // Otherwise it is too easy to accidentally start |
| 1302 | // playing music while a phone call is in progress. |
| 1303 | if (VDBG) Log.d(LOG_TAG, "MediaButtonBroadcastReceiver: consumed"); |
| 1304 | abortBroadcast(); |
| 1305 | } |
| 1306 | } |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | /** |
| 1311 | * Accepts broadcast Intents which will be prepared by {@link NotificationMgr} and thus |
| 1312 | * sent from framework's notification mechanism (which is outside Phone context). |
| 1313 | * This should be visible from outside, but shouldn't be in "exported" state. |
| 1314 | * |
| 1315 | * TODO: If possible merge this into PhoneAppBroadcastReceiver. |
| 1316 | */ |
| 1317 | public static class NotificationBroadcastReceiver extends BroadcastReceiver { |
| 1318 | @Override |
| 1319 | public void onReceive(Context context, Intent intent) { |
| 1320 | String action = intent.getAction(); |
| 1321 | // TODO: use "if (VDBG)" here. |
| 1322 | Log.d(LOG_TAG, "Broadcast from Notification: " + action); |
| 1323 | |
| 1324 | if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) { |
| 1325 | PhoneUtils.hangup(PhoneGlobals.getInstance().mCM); |
| 1326 | } else if (action.equals(ACTION_CALL_BACK_FROM_NOTIFICATION)) { |
| 1327 | // Collapse the expanded notification and the notification item itself. |
| 1328 | closeSystemDialogs(context); |
| 1329 | clearMissedCallNotification(context); |
| 1330 | |
| 1331 | Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, intent.getData()); |
| 1332 | callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1333 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 1334 | context.startActivity(callIntent); |
| 1335 | } else if (action.equals(ACTION_SEND_SMS_FROM_NOTIFICATION)) { |
| 1336 | // Collapse the expanded notification and the notification item itself. |
| 1337 | closeSystemDialogs(context); |
| 1338 | clearMissedCallNotification(context); |
| 1339 | |
| 1340 | Intent smsIntent = new Intent(Intent.ACTION_SENDTO, intent.getData()); |
| 1341 | smsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1342 | context.startActivity(smsIntent); |
| 1343 | } else { |
| 1344 | Log.w(LOG_TAG, "Received hang-up request from notification," |
| 1345 | + " but there's no call the system can hang up."); |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | private void closeSystemDialogs(Context context) { |
| 1350 | Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 1351 | context.sendBroadcastAsUser(intent, UserHandle.ALL); |
| 1352 | } |
| 1353 | |
| 1354 | private void clearMissedCallNotification(Context context) { |
| 1355 | Intent clearIntent = new Intent(context, ClearMissedCallsService.class); |
| 1356 | clearIntent.setAction(ClearMissedCallsService.ACTION_CLEAR_MISSED_CALLS); |
| 1357 | context.startService(clearIntent); |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | private void handleServiceStateChanged(Intent intent) { |
| 1362 | /** |
| 1363 | * This used to handle updating EriTextWidgetProvider this routine |
| 1364 | * and and listening for ACTION_SERVICE_STATE_CHANGED intents could |
| 1365 | * be removed. But leaving just in case it might be needed in the near |
| 1366 | * future. |
| 1367 | */ |
| 1368 | |
| 1369 | // If service just returned, start sending out the queued messages |
| 1370 | ServiceState ss = ServiceState.newFromBundle(intent.getExtras()); |
| 1371 | |
| 1372 | if (ss != null) { |
| 1373 | int state = ss.getState(); |
| 1374 | notificationMgr.updateNetworkSelection(state); |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | public boolean isOtaCallInActiveState() { |
| 1379 | boolean otaCallActive = false; |
| 1380 | if (mInCallScreen != null) { |
| 1381 | otaCallActive = mInCallScreen.isOtaCallInActiveState(); |
| 1382 | } |
| 1383 | if (VDBG) Log.d(LOG_TAG, "- isOtaCallInActiveState " + otaCallActive); |
| 1384 | return otaCallActive; |
| 1385 | } |
| 1386 | |
| 1387 | public boolean isOtaCallInEndState() { |
| 1388 | boolean otaCallEnded = false; |
| 1389 | if (mInCallScreen != null) { |
| 1390 | otaCallEnded = mInCallScreen.isOtaCallInEndState(); |
| 1391 | } |
| 1392 | if (VDBG) Log.d(LOG_TAG, "- isOtaCallInEndState " + otaCallEnded); |
| 1393 | return otaCallEnded; |
| 1394 | } |
| 1395 | |
| 1396 | // it is safe to call clearOtaState() even if the InCallScreen isn't active |
| 1397 | public void clearOtaState() { |
| 1398 | if (DBG) Log.d(LOG_TAG, "- clearOtaState ..."); |
| 1399 | if ((mInCallScreen != null) |
| 1400 | && (otaUtils != null)) { |
| 1401 | otaUtils.cleanOtaScreen(true); |
| 1402 | if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen"); |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active |
| 1407 | public void dismissOtaDialogs() { |
| 1408 | if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ..."); |
| 1409 | if ((mInCallScreen != null) |
| 1410 | && (otaUtils != null)) { |
| 1411 | otaUtils.dismissAllOtaDialogs(); |
| 1412 | if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs"); |
| 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | // it is safe to call clearInCallScreenMode() even if the InCallScreen isn't active |
| 1417 | public void clearInCallScreenMode() { |
| 1418 | if (DBG) Log.d(LOG_TAG, "- clearInCallScreenMode ..."); |
| 1419 | if (mInCallScreen != null) { |
| 1420 | mInCallScreen.resetInCallScreenMode(); |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | /** |
| 1425 | * Force the in-call UI to refresh itself, if it's currently visible. |
| 1426 | * |
| 1427 | * This method can be used any time there's a state change anywhere in |
| 1428 | * the phone app that needs to be reflected in the onscreen UI. |
| 1429 | * |
| 1430 | * Note that it's *not* necessary to manually refresh the in-call UI |
| 1431 | * (via this method) for regular telephony state changes like |
| 1432 | * DIALING -> ALERTING -> ACTIVE, since the InCallScreen already |
| 1433 | * listens for those state changes itself. |
| 1434 | * |
| 1435 | * This method does *not* force the in-call UI to come up if it's not |
| 1436 | * already visible. To do that, use displayCallScreen(). |
| 1437 | */ |
| 1438 | /* package */ void updateInCallScreen() { |
| 1439 | if (DBG) Log.d(LOG_TAG, "- updateInCallScreen()..."); |
| 1440 | if (mInCallScreen != null) { |
| 1441 | // Post an updateScreen() request. Note that the |
| 1442 | // updateScreen() call will end up being a no-op if the |
| 1443 | // InCallScreen isn't the foreground activity. |
| 1444 | mInCallScreen.requestUpdateScreen(); |
| 1445 | } |
| 1446 | } |
| 1447 | |
| 1448 | private void handleQueryTTYModeResponse(Message msg) { |
| 1449 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1450 | if (ar.exception != null) { |
| 1451 | if (DBG) Log.d(LOG_TAG, "handleQueryTTYModeResponse: Error getting TTY state."); |
| 1452 | } else { |
| 1453 | if (DBG) Log.d(LOG_TAG, |
| 1454 | "handleQueryTTYModeResponse: TTY enable state successfully queried."); |
| 1455 | |
| 1456 | int ttymode = ((int[]) ar.result)[0]; |
| 1457 | if (DBG) Log.d(LOG_TAG, "handleQueryTTYModeResponse:ttymode=" + ttymode); |
| 1458 | |
| 1459 | Intent ttyModeChanged = new Intent(TtyIntent.TTY_ENABLED_CHANGE_ACTION); |
| 1460 | ttyModeChanged.putExtra("ttyEnabled", ttymode != Phone.TTY_MODE_OFF); |
| 1461 | sendBroadcastAsUser(ttyModeChanged, UserHandle.ALL); |
| 1462 | |
| 1463 | String audioTtyMode; |
| 1464 | switch (ttymode) { |
| 1465 | case Phone.TTY_MODE_FULL: |
| 1466 | audioTtyMode = "tty_full"; |
| 1467 | break; |
| 1468 | case Phone.TTY_MODE_VCO: |
| 1469 | audioTtyMode = "tty_vco"; |
| 1470 | break; |
| 1471 | case Phone.TTY_MODE_HCO: |
| 1472 | audioTtyMode = "tty_hco"; |
| 1473 | break; |
| 1474 | case Phone.TTY_MODE_OFF: |
| 1475 | default: |
| 1476 | audioTtyMode = "tty_off"; |
| 1477 | break; |
| 1478 | } |
| 1479 | AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
| 1480 | audioManager.setParameters("tty_mode="+audioTtyMode); |
| 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | private void handleSetTTYModeResponse(Message msg) { |
| 1485 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1486 | |
| 1487 | if (ar.exception != null) { |
| 1488 | if (DBG) Log.d (LOG_TAG, |
| 1489 | "handleSetTTYModeResponse: Error setting TTY mode, ar.exception" |
| 1490 | + ar.exception); |
| 1491 | } |
| 1492 | phone.queryTTYMode(mHandler.obtainMessage(EVENT_TTY_MODE_GET)); |
| 1493 | } |
| 1494 | |
| 1495 | /** |
| 1496 | * "Call origin" may be used by Contacts app to specify where the phone call comes from. |
| 1497 | * Currently, the only permitted value for this extra is {@link #ALLOWED_EXTRA_CALL_ORIGIN}. |
| 1498 | * Any other value will be ignored, to make sure that malicious apps can't trick the in-call |
| 1499 | * UI into launching some random other app after a call ends. |
| 1500 | * |
| 1501 | * TODO: make this more generic. Note that we should let the "origin" specify its package |
| 1502 | * while we are now assuming it is "com.android.contacts" |
| 1503 | */ |
| 1504 | public static final String EXTRA_CALL_ORIGIN = "com.android.phone.CALL_ORIGIN"; |
| 1505 | private static final String DEFAULT_CALL_ORIGIN_PACKAGE = "com.android.dialer"; |
| 1506 | private static final String ALLOWED_EXTRA_CALL_ORIGIN = |
| 1507 | "com.android.dialer.DialtactsActivity"; |
| 1508 | /** |
| 1509 | * Used to determine if the preserved call origin is fresh enough. |
| 1510 | */ |
| 1511 | private static final long CALL_ORIGIN_EXPIRATION_MILLIS = 30 * 1000; |
| 1512 | |
| 1513 | public void setLatestActiveCallOrigin(String callOrigin) { |
| 1514 | inCallUiState.latestActiveCallOrigin = callOrigin; |
| 1515 | if (callOrigin != null) { |
| 1516 | inCallUiState.latestActiveCallOriginTimeStamp = SystemClock.elapsedRealtime(); |
| 1517 | } else { |
| 1518 | inCallUiState.latestActiveCallOriginTimeStamp = 0; |
| 1519 | } |
| 1520 | } |
| 1521 | |
| 1522 | /** |
| 1523 | * Reset call origin depending on its timestamp. |
| 1524 | * |
| 1525 | * See if the current call origin preserved by the app is fresh enough or not. If it is, |
| 1526 | * previous call origin will be used as is. If not, call origin will be reset. |
| 1527 | * |
| 1528 | * This will be effective especially for 3rd party apps which want to bypass phone calls with |
| 1529 | * their own telephone lines. In that case Phone app may finish the phone call once and make |
| 1530 | * another for the external apps, which will drop call origin information in Intent. |
| 1531 | * Even in that case we are sure the second phone call should be initiated just after the first |
| 1532 | * phone call, so here we restore it from the previous information iff the second call is done |
| 1533 | * fairly soon. |
| 1534 | */ |
| 1535 | public void resetLatestActiveCallOrigin() { |
| 1536 | final long callOriginTimestamp = inCallUiState.latestActiveCallOriginTimeStamp; |
| 1537 | final long currentTimestamp = SystemClock.elapsedRealtime(); |
| 1538 | if (VDBG) { |
| 1539 | Log.d(LOG_TAG, "currentTimeMillis: " + currentTimestamp |
| 1540 | + ", saved timestamp for call origin: " + callOriginTimestamp); |
| 1541 | } |
| 1542 | if (inCallUiState.latestActiveCallOriginTimeStamp > 0 |
| 1543 | && (currentTimestamp - callOriginTimestamp < CALL_ORIGIN_EXPIRATION_MILLIS)) { |
| 1544 | if (VDBG) { |
| 1545 | Log.d(LOG_TAG, "Resume previous call origin (" + |
| 1546 | inCallUiState.latestActiveCallOrigin + ")"); |
| 1547 | } |
| 1548 | // Do nothing toward call origin itself but update the timestamp just in case. |
| 1549 | inCallUiState.latestActiveCallOriginTimeStamp = currentTimestamp; |
| 1550 | } else { |
| 1551 | if (VDBG) Log.d(LOG_TAG, "Drop previous call origin and set the current one to null"); |
| 1552 | setLatestActiveCallOrigin(null); |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | /** |
| 1557 | * @return Intent which will be used when in-call UI is shown and the phone call is hang up. |
| 1558 | * By default CallLog screen will be introduced, but the destination may change depending on |
| 1559 | * its latest call origin state. |
| 1560 | */ |
| 1561 | public Intent createPhoneEndIntentUsingCallOrigin() { |
| 1562 | if (TextUtils.equals(inCallUiState.latestActiveCallOrigin, ALLOWED_EXTRA_CALL_ORIGIN)) { |
| 1563 | if (VDBG) Log.d(LOG_TAG, "Valid latestActiveCallOrigin(" |
| 1564 | + inCallUiState.latestActiveCallOrigin + ") was found. " |
| 1565 | + "Go back to the previous screen."); |
| 1566 | // Right now we just launch the Activity which launched in-call UI. Note that we're |
| 1567 | // assuming the origin is from "com.android.dialer", which may be incorrect in the |
| 1568 | // future. |
| 1569 | final Intent intent = new Intent(); |
| 1570 | intent.setClassName(DEFAULT_CALL_ORIGIN_PACKAGE, inCallUiState.latestActiveCallOrigin); |
| 1571 | return intent; |
| 1572 | } else { |
| 1573 | if (VDBG) Log.d(LOG_TAG, "Current latestActiveCallOrigin (" |
| 1574 | + inCallUiState.latestActiveCallOrigin + ") is not valid. " |
| 1575 | + "Just use CallLog as a default destination."); |
| 1576 | return PhoneGlobals.createCallLogIntent(); |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | /** Service connection */ |
| 1581 | private final ServiceConnection mBluetoothPhoneConnection = new ServiceConnection() { |
| 1582 | |
| 1583 | /** Handle the task of binding the local object to the service */ |
| 1584 | public void onServiceConnected(ComponentName className, IBinder service) { |
| 1585 | Log.i(LOG_TAG, "Headset phone created, binding local service."); |
| 1586 | mBluetoothPhone = IBluetoothHeadsetPhone.Stub.asInterface(service); |
| 1587 | } |
| 1588 | |
| 1589 | /** Handle the task of cleaning up the local binding */ |
| 1590 | public void onServiceDisconnected(ComponentName className) { |
| 1591 | Log.i(LOG_TAG, "Headset phone disconnected, cleaning local binding."); |
| 1592 | mBluetoothPhone = null; |
| 1593 | } |
| 1594 | }; |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 1595 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1596 | } |