blob: bc13010d0af19045ab2de0c31bc9ce715a5489e1 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
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
17package com.android.phone;
18
19import com.android.internal.telephony.Call;
20import com.android.internal.telephony.CallManager;
21import com.android.internal.telephony.CallerInfo;
22import com.android.internal.telephony.CallerInfoAsyncQuery;
23import com.android.internal.telephony.Connection;
24import com.android.internal.telephony.Phone;
25import com.android.internal.telephony.PhoneConstants;
26import com.android.internal.telephony.PhoneBase;
27import com.android.internal.telephony.TelephonyCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import com.android.internal.telephony.cdma.CdmaInformationRecords.CdmaDisplayInfoRec;
29import com.android.internal.telephony.cdma.CdmaInformationRecords.CdmaSignalInfoRec;
30import com.android.internal.telephony.cdma.SignalToneUtil;
31
32import android.app.ActivityManagerNative;
33import android.bluetooth.BluetoothAdapter;
34import android.bluetooth.BluetoothHeadset;
35import android.bluetooth.BluetoothProfile;
36import android.content.Context;
John Spurlock6ee06d02014-07-18 20:06:20 -040037import android.media.AudioAttributes;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.media.AudioManager;
39import android.media.ToneGenerator;
40import android.net.Uri;
41import android.os.AsyncResult;
42import android.os.Handler;
43import android.os.Message;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.SystemProperties;
45import android.os.SystemVibrator;
46import android.os.Vibrator;
47import android.provider.CallLog.Calls;
48import android.provider.Settings;
Anders Kristensen0b35f042014-02-27 14:31:07 -080049import android.telephony.DisconnectCause;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.telephony.PhoneNumberUtils;
51import android.telephony.PhoneStateListener;
52import android.telephony.TelephonyManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.util.EventLog;
54import android.util.Log;
55
56/**
57 * Phone app module that listens for phone state changes and various other
58 * events from the telephony layer, and triggers any resulting UI behavior
Santos Cordon5422a8d2014-09-12 04:20:56 -070059 * (like starting the Incoming Call UI, playing in-call tones,
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060 * updating notifications, writing call log entries, etc.)
61 */
Santos Cordon5422a8d2014-09-12 04:20:56 -070062public class CallNotifier extends Handler {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063 private static final String LOG_TAG = "CallNotifier";
64 private static final boolean DBG =
65 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
66 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
67
Anthony Leee9468532014-11-15 15:21:00 -080068 // Time to display the message from the underlying phone layers.
69 private static final int SHOW_MESSAGE_NOTIFICATION_TIME = 3000; // msec
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070
John Spurlock6ee06d02014-07-18 20:06:20 -040071 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
72 .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
73 .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
74 .build();
75
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076 /** The singleton instance. */
77 private static CallNotifier sInstance;
78
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079 // values used to track the query state
80 private static final int CALLERINFO_QUERY_READY = 0;
81 private static final int CALLERINFO_QUERYING = -1;
82
83 // the state of the CallerInfo Query.
84 private int mCallerInfoQueryState;
85
86 // object used to synchronize access to mCallerInfoQueryState
87 private Object mCallerInfoQueryStateGuard = new Object();
88
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089 private PhoneGlobals mApplication;
90 private CallManager mCM;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091 private BluetoothHeadset mBluetoothHeadset;
92 private CallLogger mCallLogger;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093
94 // ToneGenerator instance for playing SignalInfo tones
95 private ToneGenerator mSignalInfoToneGenerator;
96
97 // The tone volume relative to other sounds in the stream SignalInfo
98 private static final int TONE_RELATIVE_VOLUME_SIGNALINFO = 80;
99
100 private Call.State mPreviousCdmaCallState;
101 private boolean mVoicePrivacyState = false;
102 private boolean mIsCdmaRedialCall = false;
103
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104 // Cached AudioManager
105 private AudioManager mAudioManager;
106
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700107 private final BluetoothManager mBluetoothManager;
108
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109 /**
110 * Initialize the singleton CallNotifier instance.
111 * This is only done once, at startup, from PhoneApp.onCreate().
112 */
Santos Cordon5422a8d2014-09-12 04:20:56 -0700113 /* package */ static CallNotifier init(PhoneGlobals app, Phone phone,
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700114 CallLogger callLogger, CallStateMonitor callStateMonitor,
Sailesh Nepal23d9ed72014-07-03 09:40:26 -0700115 BluetoothManager bluetoothManager) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116 synchronized (CallNotifier.class) {
117 if (sInstance == null) {
Santos Cordon5422a8d2014-09-12 04:20:56 -0700118 sInstance = new CallNotifier(app, phone, callLogger, callStateMonitor,
Sailesh Nepal23d9ed72014-07-03 09:40:26 -0700119 bluetoothManager);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120 } else {
121 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
122 }
123 return sInstance;
124 }
125 }
126
127 /** Private constructor; @see init() */
Santos Cordon5422a8d2014-09-12 04:20:56 -0700128 private CallNotifier(PhoneGlobals app, Phone phone, CallLogger callLogger,
Sailesh Nepal23d9ed72014-07-03 09:40:26 -0700129 CallStateMonitor callStateMonitor, BluetoothManager bluetoothManager) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130 mApplication = app;
131 mCM = app.mCM;
132 mCallLogger = callLogger;
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700133 mBluetoothManager = bluetoothManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134
135 mAudioManager = (AudioManager) mApplication.getSystemService(Context.AUDIO_SERVICE);
136
137 callStateMonitor.addListener(this);
138
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
140 if (adapter != null) {
141 adapter.getProfileProxy(mApplication.getApplicationContext(),
142 mBluetoothProfileServiceListener,
143 BluetoothProfile.HEADSET);
144 }
145
146 TelephonyManager telephonyManager = (TelephonyManager)app.getSystemService(
147 Context.TELEPHONY_SERVICE);
148 telephonyManager.listen(mPhoneStateListener,
149 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
150 | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR);
151 }
152
153 private void createSignalInfoToneGenerator() {
154 // Instantiate the ToneGenerator for SignalInfo and CallWaiting
155 // TODO: We probably don't need the mSignalInfoToneGenerator instance
156 // around forever. Need to change it so as to create a ToneGenerator instance only
157 // when a tone is being played and releases it after its done playing.
158 if (mSignalInfoToneGenerator == null) {
159 try {
160 mSignalInfoToneGenerator = new ToneGenerator(AudioManager.STREAM_VOICE_CALL,
161 TONE_RELATIVE_VOLUME_SIGNALINFO);
162 Log.d(LOG_TAG, "CallNotifier: mSignalInfoToneGenerator created when toneplay");
163 } catch (RuntimeException e) {
164 Log.w(LOG_TAG, "CallNotifier: Exception caught while creating " +
165 "mSignalInfoToneGenerator: " + e);
166 mSignalInfoToneGenerator = null;
167 }
168 } else {
169 Log.d(LOG_TAG, "mSignalInfoToneGenerator created already, hence skipping");
170 }
171 }
172
173 @Override
174 public void handleMessage(Message msg) {
175 switch (msg.what) {
176 case CallStateMonitor.PHONE_NEW_RINGING_CONNECTION:
177 log("RINGING... (new)");
178 onNewRingingConnection((AsyncResult) msg.obj);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179 break;
180
181 case CallStateMonitor.PHONE_STATE_CHANGED:
182 onPhoneStateChanged((AsyncResult) msg.obj);
183 break;
184
185 case CallStateMonitor.PHONE_DISCONNECT:
186 if (DBG) log("DISCONNECT");
187 onDisconnect((AsyncResult) msg.obj);
188 break;
189
190 case CallStateMonitor.PHONE_UNKNOWN_CONNECTION_APPEARED:
191 onUnknownConnectionAppeared((AsyncResult) msg.obj);
192 break;
193
Anthony Leee9468532014-11-15 15:21:00 -0800194 case CallStateMonitor.INTERNAL_PHONE_MWI_CHANGED:
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 onMwiChanged(mApplication.phone.getMessageWaitingIndicator());
196 break;
197
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198 case CallStateMonitor.PHONE_STATE_DISPLAYINFO:
199 if (DBG) log("Received PHONE_STATE_DISPLAYINFO event");
200 onDisplayInfo((AsyncResult) msg.obj);
201 break;
202
203 case CallStateMonitor.PHONE_STATE_SIGNALINFO:
204 if (DBG) log("Received PHONE_STATE_SIGNALINFO event");
205 onSignalInfo((AsyncResult) msg.obj);
206 break;
207
Anthony Leee9468532014-11-15 15:21:00 -0800208 case CallStateMonitor.INTERNAL_SHOW_MESSAGE_NOTIFICATION_DONE:
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700209 if (DBG) log("Received Display Info notification done event ...");
Anthony Leee9468532014-11-15 15:21:00 -0800210 PhoneDisplayMessage.dismissMessage();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211 break;
212
213 case CallStateMonitor.EVENT_OTA_PROVISION_CHANGE:
214 if (DBG) log("EVENT_OTA_PROVISION_CHANGE...");
215 mApplication.handleOtaspEvent(msg);
216 break;
217
218 case CallStateMonitor.PHONE_ENHANCED_VP_ON:
219 if (DBG) log("PHONE_ENHANCED_VP_ON...");
220 if (!mVoicePrivacyState) {
221 int toneToPlay = InCallTonePlayer.TONE_VOICE_PRIVACY;
222 new InCallTonePlayer(toneToPlay).start();
223 mVoicePrivacyState = true;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 }
225 break;
226
227 case CallStateMonitor.PHONE_ENHANCED_VP_OFF:
228 if (DBG) log("PHONE_ENHANCED_VP_OFF...");
229 if (mVoicePrivacyState) {
230 int toneToPlay = InCallTonePlayer.TONE_VOICE_PRIVACY;
231 new InCallTonePlayer(toneToPlay).start();
232 mVoicePrivacyState = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 }
234 break;
235
Anthony Leee9468532014-11-15 15:21:00 -0800236 case CallStateMonitor.PHONE_SUPP_SERVICE_FAILED:
237 if (DBG) log("PHONE_SUPP_SERVICE_FAILED...");
238 onSuppServiceFailed((AsyncResult) msg.obj);
239 break;
240
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241 default:
242 // super.handleMessage(msg);
243 }
244 }
245
246 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
247 @Override
248 public void onMessageWaitingIndicatorChanged(boolean mwi) {
249 onMwiChanged(mwi);
250 }
251
252 @Override
253 public void onCallForwardingIndicatorChanged(boolean cfi) {
254 onCfiChanged(cfi);
255 }
256 };
257
258 /**
259 * Handles a "new ringing connection" event from the telephony layer.
260 */
261 private void onNewRingingConnection(AsyncResult r) {
262 Connection c = (Connection) r.result;
263 log("onNewRingingConnection(): state = " + mCM.getState() + ", conn = { " + c + " }");
264 Call ringing = c.getCall();
265 Phone phone = ringing.getPhone();
266
267 // Check for a few cases where we totally ignore incoming calls.
268 if (ignoreAllIncomingCalls(phone)) {
269 // Immediately reject the call, without even indicating to the user
270 // that an incoming call occurred. (This will generally send the
271 // caller straight to voicemail, just as if we *had* shown the
272 // incoming-call UI and the user had declined the call.)
273 PhoneUtils.hangupRingingCall(ringing);
274 return;
275 }
276
277 if (!c.isRinging()) {
278 Log.i(LOG_TAG, "CallNotifier.onNewRingingConnection(): connection not ringing!");
279 // This is a very strange case: an incoming call that stopped
280 // ringing almost instantly after the onNewRingingConnection()
281 // event. There's nothing we can do here, so just bail out
282 // without doing anything. (But presumably we'll log it in
283 // the call log when the disconnect event comes in...)
284 return;
285 }
286
287 // Stop any signalInfo tone being played on receiving a Call
288 stopSignalInfoTone();
289
290 Call.State state = c.getState();
291 // State will be either INCOMING or WAITING.
292 if (VDBG) log("- connection is ringing! state = " + state);
293 // if (DBG) PhoneUtils.dumpCallState(mPhone);
294
295 // No need to do any service state checks here (like for
296 // "emergency mode"), since in those states the SIM won't let
297 // us get incoming connections in the first place.
298
299 // TODO: Consider sending out a serialized broadcast Intent here
300 // (maybe "ACTION_NEW_INCOMING_CALL"), *before* starting the
301 // ringer and going to the in-call UI. The intent should contain
302 // the caller-id info for the current connection, and say whether
303 // it would be a "call waiting" call or a regular ringing call.
304 // If anybody consumed the broadcast, we'd bail out without
305 // ringing or bringing up the in-call UI.
306 //
307 // This would give 3rd party apps a chance to listen for (and
308 // intercept) new ringing connections. An app could reject the
309 // incoming call by consuming the broadcast and doing nothing, or
310 // it could "pick up" the call (without any action by the user!)
311 // via some future TelephonyManager API.
312 //
313 // See bug 1312336 for more details.
314 // We'd need to protect this with a new "intercept incoming calls"
315 // system permission.
316
317 // Obtain a partial wake lock to make sure the CPU doesn't go to
318 // sleep before we finish bringing up the InCallScreen.
319 // (This will be upgraded soon to a full wake lock; see
320 // showIncomingCall().)
321 if (VDBG) log("Holding wake lock on new incoming connection.");
322 mApplication.requestWakeState(PhoneGlobals.WakeState.PARTIAL);
323
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324 // Note we *don't* post a status bar notification here, since
325 // we're not necessarily ready to actually show the incoming call
326 // to the user. (For calls in the INCOMING state, at least, we
327 // still need to run a caller-id query, and we may not even ring
328 // at all if the "send directly to voicemail" flag is set.)
329 //
330 // Instead, we update the notification (and potentially launch the
331 // InCallScreen) from the showIncomingCall() method, which runs
332 // when the caller-id query completes or times out.
333
334 if (VDBG) log("- onNewRingingConnection() done.");
335 }
336
337 /**
338 * Determines whether or not we're allowed to present incoming calls to the
339 * user, based on the capabilities and/or current state of the device.
340 *
341 * If this method returns true, that means we should immediately reject the
342 * current incoming call, without even indicating to the user that an
343 * incoming call occurred.
344 *
345 * (We only reject incoming calls in a few cases, like during an OTASP call
346 * when we can't interrupt the user, or if the device hasn't completed the
347 * SetupWizard yet. We also don't allow incoming calls on non-voice-capable
348 * devices. But note that we *always* allow incoming calls while in ECM.)
349 *
350 * @return true if we're *not* allowed to present an incoming call to
351 * the user.
352 */
353 private boolean ignoreAllIncomingCalls(Phone phone) {
354 // Incoming calls are totally ignored on non-voice-capable devices.
355 if (!PhoneGlobals.sVoiceCapable) {
356 // ...but still log a warning, since we shouldn't have gotten this
357 // event in the first place! (Incoming calls *should* be blocked at
358 // the telephony layer on non-voice-capable capable devices.)
359 Log.w(LOG_TAG, "Got onNewRingingConnection() on non-voice-capable device! Ignoring...");
360 return true;
361 }
362
363 // In ECM (emergency callback mode), we ALWAYS allow incoming calls
364 // to get through to the user. (Note that ECM is applicable only to
365 // voice-capable CDMA devices).
366 if (PhoneUtils.isPhoneInEcm(phone)) {
367 if (DBG) log("Incoming call while in ECM: always allow...");
368 return false;
369 }
370
371 // Incoming calls are totally ignored if the device isn't provisioned yet.
372 boolean provisioned = Settings.Global.getInt(mApplication.getContentResolver(),
373 Settings.Global.DEVICE_PROVISIONED, 0) != 0;
374 if (!provisioned) {
375 Log.i(LOG_TAG, "Ignoring incoming call: not provisioned");
376 return true;
377 }
378
379 // Incoming calls are totally ignored if an OTASP call is active.
380 if (TelephonyCapabilities.supportsOtasp(phone)) {
381 boolean activateState = (mApplication.cdmaOtaScreenState.otaScreenState
382 == OtaUtils.CdmaOtaScreenState.OtaScreenState.OTA_STATUS_ACTIVATION);
383 boolean dialogState = (mApplication.cdmaOtaScreenState.otaScreenState
384 == OtaUtils.CdmaOtaScreenState.OtaScreenState.OTA_STATUS_SUCCESS_FAILURE_DLG);
385 boolean spcState = mApplication.cdmaOtaProvisionData.inOtaSpcState;
386
387 if (spcState) {
388 Log.i(LOG_TAG, "Ignoring incoming call: OTA call is active");
389 return true;
390 } else if (activateState || dialogState) {
391 // We *are* allowed to receive incoming calls at this point.
392 // But clear out any residual OTASP UI first.
393 // TODO: It's an MVC violation to twiddle the OTA UI state here;
394 // we should instead provide a higher-level API via OtaUtils.
395 if (dialogState) mApplication.dismissOtaDialogs();
396 mApplication.clearOtaState();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 return false;
398 }
399 }
400
401 // Normal case: allow this call to be presented to the user.
402 return false;
403 }
404
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 private void onUnknownConnectionAppeared(AsyncResult r) {
406 PhoneConstants.State state = mCM.getState();
407
408 if (state == PhoneConstants.State.OFFHOOK) {
Santos Cordon54fdb592013-09-19 05:16:18 -0700409 if (DBG) log("unknown connection appeared...");
Chiao Cheng312b9c92013-09-16 15:40:53 -0700410
Santos Cordon54fdb592013-09-19 05:16:18 -0700411 onPhoneStateChanged(r);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412 }
413 }
414
Christine Chenb5e4b652013-09-19 11:20:18 -0700415 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 * Updates the phone UI in response to phone state changes.
417 *
418 * Watch out: certain state changes are actually handled by their own
419 * specific methods:
420 * - see onNewRingingConnection() for new incoming calls
421 * - see onDisconnect() for calls being hung up or disconnected
422 */
423 private void onPhoneStateChanged(AsyncResult r) {
424 PhoneConstants.State state = mCM.getState();
425 if (VDBG) log("onPhoneStateChanged: state = " + state);
426
427 // Turn status bar notifications on or off depending upon the state
428 // of the phone. Notification Alerts (audible or vibrating) should
429 // be on if and only if the phone is IDLE.
430 mApplication.notificationMgr.statusBarHelper
431 .enableNotificationAlerts(state == PhoneConstants.State.IDLE);
432
433 Phone fgPhone = mCM.getFgPhone();
434 if (fgPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
435 if ((fgPhone.getForegroundCall().getState() == Call.State.ACTIVE)
436 && ((mPreviousCdmaCallState == Call.State.DIALING)
437 || (mPreviousCdmaCallState == Call.State.ALERTING))) {
438 if (mIsCdmaRedialCall) {
439 int toneToPlay = InCallTonePlayer.TONE_REDIAL;
440 new InCallTonePlayer(toneToPlay).start();
441 }
442 // Stop any signal info tone when call moves to ACTIVE state
443 stopSignalInfoTone();
444 }
445 mPreviousCdmaCallState = fgPhone.getForegroundCall().getState();
446 }
447
448 // Have the PhoneApp recompute its mShowBluetoothIndication
449 // flag based on the (new) telephony state.
450 // There's no need to force a UI update since we update the
451 // in-call notification ourselves (below), and the InCallScreen
452 // listens for phone state changes itself.
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700453 mBluetoothManager.updateBluetoothIndication();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 // Update the phone state and other sensor/lock.
456 mApplication.updatePhoneState(state);
457
458 if (state == PhoneConstants.State.OFFHOOK) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459
460 if (VDBG) log("onPhoneStateChanged: OFF HOOK");
461 // make sure audio is in in-call mode now
462 PhoneUtils.setAudioMode(mCM);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700464 }
465
466 void updateCallNotifierRegistrationsAfterRadioTechnologyChange() {
467 if (DBG) Log.d(LOG_TAG, "updateCallNotifierRegistrationsAfterRadioTechnologyChange...");
468
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 // Instantiate mSignalInfoToneGenerator
470 createSignalInfoToneGenerator();
471 }
472
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 private void onDisconnect(AsyncResult r) {
474 if (VDBG) log("onDisconnect()... CallManager state: " + mCM.getState());
475
476 mVoicePrivacyState = false;
477 Connection c = (Connection) r.result;
478 if (c != null) {
Anders Kristensen0b35f042014-02-27 14:31:07 -0800479 log("onDisconnect: cause = " + DisconnectCause.toString(c.getDisconnectCause())
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480 + ", incoming = " + c.isIncoming()
481 + ", date = " + c.getCreateTime());
482 } else {
483 Log.w(LOG_TAG, "onDisconnect: null connection");
484 }
485
486 int autoretrySetting = 0;
Anthony Leee9468532014-11-15 15:21:00 -0800487 if ((c != null) &&
488 (c.getCall().getPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489 autoretrySetting = android.provider.Settings.Global.getInt(mApplication.
490 getContentResolver(),android.provider.Settings.Global.CALL_AUTO_RETRY, 0);
491 }
492
493 // Stop any signalInfo tone being played when a call gets ended
494 stopSignalInfoTone();
495
Anthony Leee9468532014-11-15 15:21:00 -0800496 if ((c != null) &&
497 (c.getCall().getPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700498 // Resetting the CdmaPhoneCallState members
499 mApplication.cdmaPhoneCallState.resetCdmaPhoneCallState();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700500 }
501
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700502 // If this is the end of an OTASP call, pass it on to the PhoneApp.
503 if (c != null && TelephonyCapabilities.supportsOtasp(c.getCall().getPhone())) {
504 final String number = c.getAddress();
505 if (c.getCall().getPhone().isOtaSpNumber(number)) {
506 if (DBG) log("onDisconnect: this was an OTASP call!");
507 mApplication.handleOtaspDisconnect();
508 }
509 }
510
511 // Check for the various tones we might need to play (thru the
512 // earpiece) after a call disconnects.
513 int toneToPlay = InCallTonePlayer.TONE_NONE;
514
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700515 // If we don't need to play BUSY or CONGESTION, then play the
516 // "call ended" tone if this was a "regular disconnect" (i.e. a
517 // normal call where one end or the other hung up) *and* this
518 // disconnect event caused the phone to become idle. (In other
519 // words, we *don't* play the sound if one call hangs up but
520 // there's still an active call on the other line.)
521 // TODO: We may eventually want to disable this via a preference.
522 if ((toneToPlay == InCallTonePlayer.TONE_NONE)
523 && (mCM.getState() == PhoneConstants.State.IDLE)
524 && (c != null)) {
Anders Kristensen0b35f042014-02-27 14:31:07 -0800525 int cause = c.getDisconnectCause();
526 if ((cause == DisconnectCause.NORMAL) // remote hangup
527 || (cause == DisconnectCause.LOCAL)) { // local hangup
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528 if (VDBG) log("- need to play CALL_ENDED tone!");
529 toneToPlay = InCallTonePlayer.TONE_CALL_ENDED;
530 mIsCdmaRedialCall = false;
531 }
532 }
533
534 // All phone calls are disconnected.
535 if (mCM.getState() == PhoneConstants.State.IDLE) {
536 // Don't reset the audio mode or bluetooth/speakerphone state
537 // if we still need to let the user hear a tone through the earpiece.
538 if (toneToPlay == InCallTonePlayer.TONE_NONE) {
539 resetAudioStateAfterDisconnect();
540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541 }
542
543 if (c != null) {
544 mCallLogger.logCall(c);
545
546 final String number = c.getAddress();
547 final Phone phone = c.getCall().getPhone();
548 final boolean isEmergencyNumber =
Yorke Lee36bb2542014-06-05 08:09:52 -0700549 PhoneNumberUtils.isLocalEmergencyNumber(mApplication, number);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551 // Possibly play a "post-disconnect tone" thru the earpiece.
552 // We do this here, rather than from the InCallScreen
553 // activity, since we need to do this even if you're not in
554 // the Phone UI at the moment the connection ends.
555 if (toneToPlay != InCallTonePlayer.TONE_NONE) {
556 if (VDBG) log("- starting post-disconnect tone (" + toneToPlay + ")...");
557 new InCallTonePlayer(toneToPlay).start();
558
559 // TODO: alternatively, we could start an InCallTonePlayer
560 // here with an "unlimited" tone length,
561 // and manually stop it later when this connection truly goes
562 // away. (The real connection over the network was closed as soon
563 // as we got the BUSY message. But our telephony layer keeps the
564 // connection open for a few extra seconds so we can show the
565 // "busy" indication to the user. We could stop the busy tone
566 // when *that* connection's "disconnect" event comes in.)
567 }
568
Santos Cordonf68db2e2014-07-02 14:40:44 -0700569 final int cause = c.getDisconnectCause();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700570 if (((mPreviousCdmaCallState == Call.State.DIALING)
571 || (mPreviousCdmaCallState == Call.State.ALERTING))
572 && (!isEmergencyNumber)
Anders Kristensen0b35f042014-02-27 14:31:07 -0800573 && (cause != DisconnectCause.INCOMING_MISSED )
574 && (cause != DisconnectCause.NORMAL)
575 && (cause != DisconnectCause.LOCAL)
576 && (cause != DisconnectCause.INCOMING_REJECTED)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700577 if (!mIsCdmaRedialCall) {
578 if (autoretrySetting == InCallScreen.AUTO_RETRY_ON) {
579 // TODO: (Moto): The contact reference data may need to be stored and use
580 // here when redialing a call. For now, pass in NULL as the URI parameter.
Santos Cordonce02f3a2013-09-19 01:58:42 -0700581 final int status =
582 PhoneUtils.placeCall(mApplication, phone, number, null, false);
583 if (status != PhoneUtils.CALL_STATUS_FAILED) {
584 mIsCdmaRedialCall = true;
585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700586 } else {
587 mIsCdmaRedialCall = false;
588 }
589 } else {
590 mIsCdmaRedialCall = false;
591 }
592 }
593 }
594 }
595
596 /**
597 * Resets the audio mode and speaker state when a call ends.
598 */
599 private void resetAudioStateAfterDisconnect() {
600 if (VDBG) log("resetAudioStateAfterDisconnect()...");
601
602 if (mBluetoothHeadset != null) {
603 mBluetoothHeadset.disconnectAudio();
604 }
605
606 // call turnOnSpeaker() with state=false and store=true even if speaker
607 // is already off to reset user requested speaker state.
608 PhoneUtils.turnOnSpeaker(mApplication, false, true);
609
610 PhoneUtils.setAudioMode(mCM);
611 }
612
613 private void onMwiChanged(boolean visible) {
614 if (VDBG) log("onMwiChanged(): " + visible);
615
616 // "Voicemail" is meaningless on non-voice-capable devices,
617 // so ignore MWI events.
618 if (!PhoneGlobals.sVoiceCapable) {
619 // ...but still log a warning, since we shouldn't have gotten this
620 // event in the first place!
621 // (PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR events
622 // *should* be blocked at the telephony layer on non-voice-capable
623 // capable devices.)
624 Log.w(LOG_TAG, "Got onMwiChanged() on non-voice-capable device! Ignoring...");
625 return;
626 }
627
628 mApplication.notificationMgr.updateMwi(visible);
629 }
630
631 /**
632 * Posts a delayed PHONE_MWI_CHANGED event, to schedule a "retry" for a
633 * failed NotificationMgr.updateMwi() call.
634 */
635 /* package */ void sendMwiChangedDelayed(long delayMillis) {
Anthony Leee9468532014-11-15 15:21:00 -0800636 Message message = Message.obtain(this, CallStateMonitor.INTERNAL_PHONE_MWI_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700637 sendMessageDelayed(message, delayMillis);
638 }
639
640 private void onCfiChanged(boolean visible) {
641 if (VDBG) log("onCfiChanged(): " + visible);
642 mApplication.notificationMgr.updateCfi(visible);
643 }
644
645 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700646 * Helper class to play tones through the earpiece (or speaker / BT)
647 * during a call, using the ToneGenerator.
648 *
649 * To use, just instantiate a new InCallTonePlayer
650 * (passing in the TONE_* constant for the tone you want)
651 * and start() it.
652 *
653 * When we're done playing the tone, if the phone is idle at that
654 * point, we'll reset the audio routing and speaker state.
655 * (That means that for tones that get played *after* a call
656 * disconnects, like "busy" or "congestion" or "call ended", you
657 * should NOT call resetAudioStateAfterDisconnect() yourself.
658 * Instead, just start the InCallTonePlayer, which will automatically
659 * defer the resetAudioStateAfterDisconnect() call until the tone
660 * finishes playing.)
661 */
662 private class InCallTonePlayer extends Thread {
663 private int mToneId;
664 private int mState;
665 // The possible tones we can play.
666 public static final int TONE_NONE = 0;
667 public static final int TONE_CALL_WAITING = 1;
668 public static final int TONE_BUSY = 2;
669 public static final int TONE_CONGESTION = 3;
670 public static final int TONE_CALL_ENDED = 4;
671 public static final int TONE_VOICE_PRIVACY = 5;
672 public static final int TONE_REORDER = 6;
673 public static final int TONE_INTERCEPT = 7;
674 public static final int TONE_CDMA_DROP = 8;
675 public static final int TONE_OUT_OF_SERVICE = 9;
676 public static final int TONE_REDIAL = 10;
677 public static final int TONE_OTA_CALL_END = 11;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700678 public static final int TONE_UNOBTAINABLE_NUMBER = 13;
679
680 // The tone volume relative to other sounds in the stream
681 static final int TONE_RELATIVE_VOLUME_EMERGENCY = 100;
682 static final int TONE_RELATIVE_VOLUME_HIPRI = 80;
683 static final int TONE_RELATIVE_VOLUME_LOPRI = 50;
684
685 // Buffer time (in msec) to add on to tone timeout value.
686 // Needed mainly when the timeout value for a tone is the
687 // exact duration of the tone itself.
688 static final int TONE_TIMEOUT_BUFFER = 20;
689
690 // The tone state
691 static final int TONE_OFF = 0;
692 static final int TONE_ON = 1;
693 static final int TONE_STOPPED = 2;
694
695 InCallTonePlayer(int toneId) {
696 super();
697 mToneId = toneId;
698 mState = TONE_OFF;
699 }
700
701 @Override
702 public void run() {
703 log("InCallTonePlayer.run(toneId = " + mToneId + ")...");
704
705 int toneType = 0; // passed to ToneGenerator.startTone()
706 int toneVolume; // passed to the ToneGenerator constructor
707 int toneLengthMillis;
708 int phoneType = mCM.getFgPhone().getPhoneType();
709
710 switch (mToneId) {
711 case TONE_CALL_WAITING:
712 toneType = ToneGenerator.TONE_SUP_CALL_WAITING;
713 toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
714 // Call waiting tone is stopped by stopTone() method
715 toneLengthMillis = Integer.MAX_VALUE - TONE_TIMEOUT_BUFFER;
716 break;
717 case TONE_BUSY:
718 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
719 toneType = ToneGenerator.TONE_CDMA_NETWORK_BUSY_ONE_SHOT;
720 toneVolume = TONE_RELATIVE_VOLUME_LOPRI;
721 toneLengthMillis = 1000;
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800722 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM
723 || phoneType == PhoneConstants.PHONE_TYPE_SIP
Etan Cohen0ca1c802014-07-07 15:35:48 -0700724 || phoneType == PhoneConstants.PHONE_TYPE_IMS
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800725 || phoneType == PhoneConstants.PHONE_TYPE_THIRD_PARTY) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700726 toneType = ToneGenerator.TONE_SUP_BUSY;
727 toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
728 toneLengthMillis = 4000;
729 } else {
730 throw new IllegalStateException("Unexpected phone type: " + phoneType);
731 }
732 break;
733 case TONE_CONGESTION:
734 toneType = ToneGenerator.TONE_SUP_CONGESTION;
735 toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
736 toneLengthMillis = 4000;
737 break;
738
739 case TONE_CALL_ENDED:
740 toneType = ToneGenerator.TONE_PROP_PROMPT;
741 toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
742 toneLengthMillis = 200;
743 break;
744 case TONE_OTA_CALL_END:
745 if (mApplication.cdmaOtaConfigData.otaPlaySuccessFailureTone ==
746 OtaUtils.OTA_PLAY_SUCCESS_FAILURE_TONE_ON) {
747 toneType = ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD;
748 toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
749 toneLengthMillis = 750;
750 } else {
751 toneType = ToneGenerator.TONE_PROP_PROMPT;
752 toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
753 toneLengthMillis = 200;
754 }
755 break;
756 case TONE_VOICE_PRIVACY:
757 toneType = ToneGenerator.TONE_CDMA_ALERT_NETWORK_LITE;
758 toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
759 toneLengthMillis = 5000;
760 break;
761 case TONE_REORDER:
762 toneType = ToneGenerator.TONE_CDMA_REORDER;
763 toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
764 toneLengthMillis = 4000;
765 break;
766 case TONE_INTERCEPT:
767 toneType = ToneGenerator.TONE_CDMA_ABBR_INTERCEPT;
768 toneVolume = TONE_RELATIVE_VOLUME_LOPRI;
769 toneLengthMillis = 500;
770 break;
771 case TONE_CDMA_DROP:
772 case TONE_OUT_OF_SERVICE:
773 toneType = ToneGenerator.TONE_CDMA_CALLDROP_LITE;
774 toneVolume = TONE_RELATIVE_VOLUME_LOPRI;
775 toneLengthMillis = 375;
776 break;
777 case TONE_REDIAL:
778 toneType = ToneGenerator.TONE_CDMA_ALERT_AUTOREDIAL_LITE;
779 toneVolume = TONE_RELATIVE_VOLUME_LOPRI;
780 toneLengthMillis = 5000;
781 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700782 case TONE_UNOBTAINABLE_NUMBER:
783 toneType = ToneGenerator.TONE_SUP_ERROR;
784 toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
785 toneLengthMillis = 4000;
786 break;
787 default:
788 throw new IllegalArgumentException("Bad toneId: " + mToneId);
789 }
790
791 // If the mToneGenerator creation fails, just continue without it. It is
792 // a local audio signal, and is not as important.
793 ToneGenerator toneGenerator;
794 try {
795 int stream;
796 if (mBluetoothHeadset != null) {
797 stream = mBluetoothHeadset.isAudioOn() ? AudioManager.STREAM_BLUETOOTH_SCO:
798 AudioManager.STREAM_VOICE_CALL;
799 } else {
800 stream = AudioManager.STREAM_VOICE_CALL;
801 }
802 toneGenerator = new ToneGenerator(stream, toneVolume);
803 // if (DBG) log("- created toneGenerator: " + toneGenerator);
804 } catch (RuntimeException e) {
805 Log.w(LOG_TAG,
806 "InCallTonePlayer: Exception caught while creating ToneGenerator: " + e);
807 toneGenerator = null;
808 }
809
810 // Using the ToneGenerator (with the CALL_WAITING / BUSY /
811 // CONGESTION tones at least), the ToneGenerator itself knows
812 // the right pattern of tones to play; we do NOT need to
813 // manually start/stop each individual tone, or manually
814 // insert the correct delay between tones. (We just start it
815 // and let it run for however long we want the tone pattern to
816 // continue.)
817 //
818 // TODO: When we stop the ToneGenerator in the middle of a
819 // "tone pattern", it sounds bad if we cut if off while the
820 // tone is actually playing. Consider adding API to the
821 // ToneGenerator to say "stop at the next silent part of the
822 // pattern", or simply "play the pattern N times and then
823 // stop."
824 boolean needToStopTone = true;
825 boolean okToPlayTone = false;
826
827 if (toneGenerator != null) {
828 int ringerMode = mAudioManager.getRingerMode();
829 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
830 if (toneType == ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD) {
831 if ((ringerMode != AudioManager.RINGER_MODE_SILENT) &&
832 (ringerMode != AudioManager.RINGER_MODE_VIBRATE)) {
833 if (DBG) log("- InCallTonePlayer: start playing call tone=" + toneType);
834 okToPlayTone = true;
835 needToStopTone = false;
836 }
837 } else if ((toneType == ToneGenerator.TONE_CDMA_NETWORK_BUSY_ONE_SHOT) ||
838 (toneType == ToneGenerator.TONE_CDMA_REORDER) ||
839 (toneType == ToneGenerator.TONE_CDMA_ABBR_REORDER) ||
840 (toneType == ToneGenerator.TONE_CDMA_ABBR_INTERCEPT) ||
841 (toneType == ToneGenerator.TONE_CDMA_CALLDROP_LITE)) {
842 if (ringerMode != AudioManager.RINGER_MODE_SILENT) {
843 if (DBG) log("InCallTonePlayer:playing call fail tone:" + toneType);
844 okToPlayTone = true;
845 needToStopTone = false;
846 }
847 } else if ((toneType == ToneGenerator.TONE_CDMA_ALERT_AUTOREDIAL_LITE) ||
848 (toneType == ToneGenerator.TONE_CDMA_ALERT_NETWORK_LITE)) {
849 if ((ringerMode != AudioManager.RINGER_MODE_SILENT) &&
850 (ringerMode != AudioManager.RINGER_MODE_VIBRATE)) {
851 if (DBG) log("InCallTonePlayer:playing tone for toneType=" + toneType);
852 okToPlayTone = true;
853 needToStopTone = false;
854 }
855 } else { // For the rest of the tones, always OK to play.
856 okToPlayTone = true;
857 }
858 } else { // Not "CDMA"
859 okToPlayTone = true;
860 }
861
862 synchronized (this) {
863 if (okToPlayTone && mState != TONE_STOPPED) {
864 mState = TONE_ON;
865 toneGenerator.startTone(toneType);
866 try {
867 wait(toneLengthMillis + TONE_TIMEOUT_BUFFER);
868 } catch (InterruptedException e) {
869 Log.w(LOG_TAG,
870 "InCallTonePlayer stopped: " + e);
871 }
872 if (needToStopTone) {
873 toneGenerator.stopTone();
874 }
875 }
876 // if (DBG) log("- InCallTonePlayer: done playing.");
877 toneGenerator.release();
878 mState = TONE_OFF;
879 }
880 }
881
882 // Finally, do the same cleanup we otherwise would have done
883 // in onDisconnect().
884 //
885 // (But watch out: do NOT do this if the phone is in use,
886 // since some of our tones get played *during* a call (like
887 // CALL_WAITING) and we definitely *don't*
888 // want to reset the audio mode / speaker / bluetooth after
889 // playing those!
890 // This call is really here for use with tones that get played
891 // *after* a call disconnects, like "busy" or "congestion" or
892 // "call ended", where the phone has already become idle but
893 // we need to defer the resetAudioStateAfterDisconnect() call
894 // till the tone finishes playing.)
895 if (mCM.getState() == PhoneConstants.State.IDLE) {
896 resetAudioStateAfterDisconnect();
897 }
898 }
899
900 public void stopTone() {
901 synchronized (this) {
902 if (mState == TONE_ON) {
903 notify();
904 }
905 mState = TONE_STOPPED;
906 }
907 }
908 }
909
910 /**
911 * Displays a notification when the phone receives a DisplayInfo record.
912 */
913 private void onDisplayInfo(AsyncResult r) {
914 // Extract the DisplayInfo String from the message
915 CdmaDisplayInfoRec displayInfoRec = (CdmaDisplayInfoRec)(r.result);
916
917 if (displayInfoRec != null) {
918 String displayInfo = displayInfoRec.alpha;
919 if (DBG) log("onDisplayInfo: displayInfo=" + displayInfo);
Anthony Leee9468532014-11-15 15:21:00 -0800920 PhoneDisplayMessage.displayNetworkMessage(mApplication, displayInfo);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700921
Anthony Leee9468532014-11-15 15:21:00 -0800922 // start a timer that kills the dialog
923 sendEmptyMessageDelayed(CallStateMonitor.INTERNAL_SHOW_MESSAGE_NOTIFICATION_DONE,
924 SHOW_MESSAGE_NOTIFICATION_TIME);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700925 }
926 }
927
928 /**
Anthony Leee9468532014-11-15 15:21:00 -0800929 * Displays a notification when the phone receives a notice that a supplemental
930 * service has failed.
931 * TODO: This is a NOOP if it isn't for conferences right now.
932 */
933 private void onSuppServiceFailed(AsyncResult r) {
934 if (r.result != Phone.SuppService.CONFERENCE) {
935 if (DBG) log("onSuppServiceFailed: not a merge failure event");
936 return;
937 }
938
939 if (DBG) log("onSuppServiceFailed: displaying merge failure message");
940
941 String mergeFailedString = mApplication.getResources().getString(
942 R.string.incall_error_supp_service_conference);
943 PhoneDisplayMessage.displayErrorMessage(mApplication, mergeFailedString);
944
945 // start a timer that kills the dialog
946 sendEmptyMessageDelayed(CallStateMonitor.INTERNAL_SHOW_MESSAGE_NOTIFICATION_DONE,
947 SHOW_MESSAGE_NOTIFICATION_TIME);
948 }
949
950 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700951 * Helper class to play SignalInfo tones using the ToneGenerator.
952 *
953 * To use, just instantiate a new SignalInfoTonePlayer
954 * (passing in the ToneID constant for the tone you want)
955 * and start() it.
956 */
957 private class SignalInfoTonePlayer extends Thread {
958 private int mToneId;
959
960 SignalInfoTonePlayer(int toneId) {
961 super();
962 mToneId = toneId;
963 }
964
965 @Override
966 public void run() {
967 log("SignalInfoTonePlayer.run(toneId = " + mToneId + ")...");
Yorke Lee65cbd162014-10-08 11:26:02 -0700968 createSignalInfoToneGenerator();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700969 if (mSignalInfoToneGenerator != null) {
970 //First stop any ongoing SignalInfo tone
971 mSignalInfoToneGenerator.stopTone();
972
973 //Start playing the new tone if its a valid tone
974 mSignalInfoToneGenerator.startTone(mToneId);
975 }
976 }
977 }
978
979 /**
980 * Plays a tone when the phone receives a SignalInfo record.
981 */
982 private void onSignalInfo(AsyncResult r) {
983 // Signal Info are totally ignored on non-voice-capable devices.
984 if (!PhoneGlobals.sVoiceCapable) {
985 Log.w(LOG_TAG, "Got onSignalInfo() on non-voice-capable device! Ignoring...");
986 return;
987 }
988
989 if (PhoneUtils.isRealIncomingCall(mCM.getFirstActiveRingingCall().getState())) {
990 // Do not start any new SignalInfo tone when Call state is INCOMING
991 // and stop any previous SignalInfo tone which is being played
992 stopSignalInfoTone();
993 } else {
994 // Extract the SignalInfo String from the message
995 CdmaSignalInfoRec signalInfoRec = (CdmaSignalInfoRec)(r.result);
996 // Only proceed if a Signal info is present.
997 if (signalInfoRec != null) {
998 boolean isPresent = signalInfoRec.isPresent;
999 if (DBG) log("onSignalInfo: isPresent=" + isPresent);
1000 if (isPresent) {// if tone is valid
1001 int uSignalType = signalInfoRec.signalType;
1002 int uAlertPitch = signalInfoRec.alertPitch;
1003 int uSignal = signalInfoRec.signal;
1004
1005 if (DBG) log("onSignalInfo: uSignalType=" + uSignalType + ", uAlertPitch=" +
1006 uAlertPitch + ", uSignal=" + uSignal);
1007 //Map the Signal to a ToneGenerator ToneID only if Signal info is present
1008 int toneID = SignalToneUtil.getAudioToneFromSignalInfo
1009 (uSignalType, uAlertPitch, uSignal);
1010
1011 //Create the SignalInfo tone player and pass the ToneID
1012 new SignalInfoTonePlayer(toneID).start();
1013 }
1014 }
1015 }
1016 }
1017
1018 /**
1019 * Stops a SignalInfo tone in the following condition
1020 * 1 - On receiving a New Ringing Call
1021 * 2 - On disconnecting a call
1022 * 3 - On answering a Call Waiting Call
1023 */
1024 /* package */ void stopSignalInfoTone() {
1025 if (DBG) log("stopSignalInfoTone: Stopping SignalInfo tone player");
1026 new SignalInfoTonePlayer(ToneGenerator.TONE_CDMA_SIGNAL_OFF).start();
1027 }
1028
1029 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001030 * Return the private variable mPreviousCdmaCallState.
1031 */
1032 /* package */ Call.State getPreviousCdmaCallState() {
1033 return mPreviousCdmaCallState;
1034 }
1035
1036 /**
1037 * Return the private variable mVoicePrivacyState.
1038 */
1039 /* package */ boolean getVoicePrivacyState() {
1040 return mVoicePrivacyState;
1041 }
1042
1043 /**
1044 * Return the private variable mIsCdmaRedialCall.
1045 */
1046 /* package */ boolean getIsCdmaRedialCall() {
1047 return mIsCdmaRedialCall;
1048 }
1049
Santos Cordon5c046722014-09-18 15:41:13 -07001050 private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001051 new BluetoothProfile.ServiceListener() {
1052 public void onServiceConnected(int profile, BluetoothProfile proxy) {
1053 mBluetoothHeadset = (BluetoothHeadset) proxy;
1054 if (VDBG) log("- Got BluetoothHeadset: " + mBluetoothHeadset);
1055 }
1056
1057 public void onServiceDisconnected(int profile) {
1058 mBluetoothHeadset = null;
1059 }
1060 };
1061
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001062 private void log(String msg) {
1063 Log.d(LOG_TAG, msg);
1064 }
1065}