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