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