blob: 6929b37bfd7c2ef6a1cf16d769ce3455faf54218 [file] [log] [blame]
Santos Cordon8e8b8d22013-12-19 14:14:05 -08001/*
2 * Copyright (C) 2013 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
Ben Gilad9f2bed32013-12-12 17:43:26 -080017package com.android.telecomm;
18
Evan Charlton5c670a92014-03-06 14:58:20 -080019import android.Manifest;
Sailesh Nepal1cecc7c2014-03-10 17:03:08 -070020import android.content.Context;
Evan Charlton5c670a92014-03-06 14:58:20 -080021import android.content.Intent;
Sailesh Nepal1cecc7c2014-03-10 17:03:08 -070022import android.media.AudioManager;
Evan Charltona05805b2014-03-05 08:21:46 -080023import android.os.Bundle;
Evan Charlton5c670a92014-03-06 14:58:20 -080024import android.telecomm.CallService;
Ben Giladc5b22692014-02-18 20:03:22 -080025import android.telecomm.CallServiceDescriptor;
Santos Cordon681663d2014-01-30 04:32:15 -080026import android.telecomm.CallState;
Evan Charlton5c670a92014-03-06 14:58:20 -080027import android.telecomm.ICallService;
28import android.telephony.TelephonyManager;
Santos Cordon8e8b8d22013-12-19 14:14:05 -080029
Santos Cordon681663d2014-01-30 04:32:15 -080030import com.google.common.base.Preconditions;
31import com.google.common.base.Strings;
Santos Cordon8e8b8d22013-12-19 14:14:05 -080032import com.google.common.collect.Lists;
Santos Cordon681663d2014-01-30 04:32:15 -080033import com.google.common.collect.Maps;
Ben Gilad9f2bed32013-12-12 17:43:26 -080034
Ben Gilad9f2bed32013-12-12 17:43:26 -080035import java.util.List;
Santos Cordon681663d2014-01-30 04:32:15 -080036import java.util.Map;
Ben Gilad9f2bed32013-12-12 17:43:26 -080037
Ben Giladdd8c6082013-12-30 14:44:08 -080038/**
39 * Singleton.
40 *
41 * NOTE(gilad): by design most APIs are package private, use the relevant adapter/s to allow
42 * access from other packages specifically refraining from passing the CallsManager instance
43 * beyond the com.android.telecomm package boundary.
44 */
Santos Cordon8e8b8d22013-12-19 14:14:05 -080045public final class CallsManager {
Ben Gilada0d9f752014-02-26 11:49:03 -080046
Santos Cordon8e8b8d22013-12-19 14:14:05 -080047 private static final CallsManager INSTANCE = new CallsManager();
Ben Gilad9f2bed32013-12-12 17:43:26 -080048
Santos Cordone3d76ab2014-01-28 17:25:20 -080049 private final Switchboard mSwitchboard;
50
51 /** Used to control the in-call app. */
52 private final InCallController mInCallController;
53
Santos Cordon4e9fffe2014-03-04 18:13:41 -080054 private final Ringer mRinger;
55
Santos Cordon8e8b8d22013-12-19 14:14:05 -080056 /**
Santos Cordon681663d2014-01-30 04:32:15 -080057 * The main call repository. Keeps an instance of all live calls keyed by call ID. New incoming
58 * and outgoing calls are added to the map and removed when the calls move to the disconnected
59 * state.
60 * TODO(santoscordon): Add new CallId class and use it in place of String.
61 */
62 private final Map<String, Call> mCalls = Maps.newHashMap();
63
64 /**
Santos Cordon4e9fffe2014-03-04 18:13:41 -080065 * Used to keep ordering of unanswered incoming calls. The existence of multiple call services
66 * means that there can easily exist multiple incoming calls and explicit ordering is useful for
67 * maintaining the proper state of the ringer.
68 * TODO(santoscordon): May want to add comments about ITelephony.answerCall() method since
69 * ordering may also apply to that case.
70 */
71 private final List<Call> mUnansweredIncomingCalls = Lists.newLinkedList();
72
73 /**
Santos Cordon8e8b8d22013-12-19 14:14:05 -080074 * May be unnecessary per off-line discussions (between santoscordon and gilad) since the set
75 * of CallsManager APIs that need to be exposed to the dialer (or any application firing call
76 * intents) may be empty.
77 */
78 private DialerAdapter mDialerAdapter;
Ben Gilad9f2bed32013-12-12 17:43:26 -080079
Santos Cordon8e8b8d22013-12-19 14:14:05 -080080 private InCallAdapter mInCallAdapter;
Ben Gilad9f2bed32013-12-12 17:43:26 -080081
Santos Cordon8e8b8d22013-12-19 14:14:05 -080082 private CallLogManager mCallLogManager;
Ben Gilad9f2bed32013-12-12 17:43:26 -080083
Santos Cordon8e8b8d22013-12-19 14:14:05 -080084 private VoicemailManager mVoicemailManager;
Ben Gilad9f2bed32013-12-12 17:43:26 -080085
Evan Charltonf02e9882014-03-06 12:54:52 -080086 private final List<OutgoingCallValidator> mOutgoingCallValidators = Lists.newArrayList();
Ben Gilad9f2bed32013-12-12 17:43:26 -080087
Evan Charltonf02e9882014-03-06 12:54:52 -080088 private final List<IncomingCallValidator> mIncomingCallValidators = Lists.newArrayList();
Ben Gilad9f2bed32013-12-12 17:43:26 -080089
Santos Cordon8e8b8d22013-12-19 14:14:05 -080090 /**
Ben Gilad8bdaa462014-02-05 12:53:19 -080091 * Initializes the required Telecomm components.
Santos Cordon8e8b8d22013-12-19 14:14:05 -080092 */
93 private CallsManager() {
Santos Cordon6242b132014-02-07 16:24:42 -080094 mSwitchboard = new Switchboard(this);
95 mInCallController = new InCallController(this);
Santos Cordon4e9fffe2014-03-04 18:13:41 -080096 mRinger = new Ringer();
Yorke Leef98fb572014-03-05 10:56:55 -080097 mCallLogManager = new CallLogManager(TelecommApp.getInstance());
Santos Cordon8e8b8d22013-12-19 14:14:05 -080098 }
99
Ben Gilada0d9f752014-02-26 11:49:03 -0800100 static CallsManager getInstance() {
101 return INSTANCE;
102 }
103
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800104 /**
Santos Cordon493e8f22014-02-19 03:15:12 -0800105 * Starts the incoming call sequence by having switchboard gather more information about the
106 * specified call; using the specified call service descriptor. Upon success, execution returns
107 * to {@link #handleSuccessfulIncomingCall} to start the in-call UI.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800108 *
Ben Giladc5b22692014-02-18 20:03:22 -0800109 * @param descriptor The descriptor of the call service to use for this incoming call.
Evan Charltona05805b2014-03-05 08:21:46 -0800110 * @param extras The optional extras Bundle passed with the intent used for the incoming call.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800111 */
Evan Charltona05805b2014-03-05 08:21:46 -0800112 void processIncomingCallIntent(CallServiceDescriptor descriptor, Bundle extras) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800113 Log.d(this, "processIncomingCallIntent");
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800114 // Create a call with no handle. Eventually, switchboard will update the call with
115 // additional information from the call service, but for now we just need one to pass around
116 // with a unique call ID.
Santos Cordon493e8f22014-02-19 03:15:12 -0800117 Call call = new Call();
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800118
Evan Charltona05805b2014-03-05 08:21:46 -0800119 mSwitchboard.retrieveIncomingCall(call, descriptor, extras);
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800120 }
121
122 /**
Ben Gilada0d9f752014-02-26 11:49:03 -0800123 * Validates the specified call and, upon no objection to connect it, adds the new call to the
124 * list of live calls. Also notifies the in-call app so the user can answer or reject the call.
125 *
126 * @param call The new incoming call.
127 */
128 void handleSuccessfulIncomingCall(Call call) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800129 Log.d(this, "handleSuccessfulIncomingCall");
Ben Gilada0d9f752014-02-26 11:49:03 -0800130 Preconditions.checkState(call.getState() == CallState.RINGING);
131
132 String handle = call.getHandle();
133 ContactInfo contactInfo = call.getContactInfo();
134 for (IncomingCallValidator validator : mIncomingCallValidators) {
135 if (!validator.isValid(handle, contactInfo)) {
136 // TODO(gilad): Consider displaying an error message.
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800137 Log.i(this, "Dropping restricted incoming call");
Ben Gilada0d9f752014-02-26 11:49:03 -0800138 return;
139 }
140 }
141
142 // No objection to accept the incoming call, proceed with potentially connecting it (based
143 // on the user's action, or lack thereof).
144 addCall(call);
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800145
146 mUnansweredIncomingCalls.add(call);
147 if (mUnansweredIncomingCalls.size() == 1) {
148 // Start the ringer if we are the top-most incoming call (the only one in this case).
149 mRinger.startRinging();
150 }
Ben Gilada0d9f752014-02-26 11:49:03 -0800151 }
152
153 /**
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800154 * Attempts to issue/connect the specified call. From an (arbitrary) application standpoint,
155 * all that is required to initiate this flow is to fire either of the CALL, CALL_PRIVILEGED,
156 * and CALL_EMERGENCY intents. These are listened to by CallActivity.java which then invokes
157 * this method.
158 *
159 * @param handle The handle to dial.
160 * @param contactInfo Information about the entity being called.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800161 */
Ben Gilada0d9f752014-02-26 11:49:03 -0800162 void processOutgoingCallIntent(String handle, ContactInfo contactInfo) {
Ben Gilad8bdaa462014-02-05 12:53:19 -0800163 for (OutgoingCallValidator validator : mOutgoingCallValidators) {
Ben Gilada0d9f752014-02-26 11:49:03 -0800164 if (!validator.isValid(handle, contactInfo)) {
165 // TODO(gilad): Display an error message.
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800166 Log.i(this, "Dropping restricted outgoing call.");
Ben Gilada0d9f752014-02-26 11:49:03 -0800167 return;
168 }
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800169 }
170
171 // No objection to issue the call, proceed with trying to put it through.
Ben Gilad13329fd2014-02-11 17:20:29 -0800172 Call call = new Call(handle, contactInfo);
Santos Cordonc195e362014-02-11 17:05:31 -0800173 mSwitchboard.placeOutgoingCall(call);
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800174 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800175
176 /**
Santos Cordon681663d2014-01-30 04:32:15 -0800177 * Adds a new outgoing call to the list of live calls and notifies the in-call app.
178 *
179 * @param call The new outgoing call.
180 */
181 void handleSuccessfulOutgoingCall(Call call) {
182 // OutgoingCallProcessor sets the call state to DIALING when it receives confirmation of the
183 // placed call from the call service so there is no need to set it here. Instead, check that
184 // the state is appropriate.
185 Preconditions.checkState(call.getState() == CallState.DIALING);
Santos Cordon681663d2014-01-30 04:32:15 -0800186 addCall(call);
Santos Cordon681663d2014-01-30 04:32:15 -0800187 }
188
189 /**
Yorke Leef98fb572014-03-05 10:56:55 -0800190 * Informs mCallLogManager about the outgoing call that failed, so that it can be logged.
191 *
192 * @param call The failed outgoing call.
193 */
194 void handleFailedOutgoingCall(Call call) {
195 mCallLogManager.logFailedOutgoingCall(call);
196 }
197
198 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800199 * Instructs Telecomm to answer the specified call. Intended to be invoked by the in-call
200 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
201 * the user opting to answer said call.
202 *
203 * @param callId The ID of the call.
204 */
205 void answerCall(String callId) {
Santos Cordon61d0f702014-02-19 02:52:23 -0800206 Call call = mCalls.get(callId);
207 if (call == null) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800208 Log.i(this, "Request to answer a non-existent call %s", callId);
Santos Cordon61d0f702014-02-19 02:52:23 -0800209 } else {
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800210 stopRinging(call);
211
Santos Cordon61d0f702014-02-19 02:52:23 -0800212 // We do not update the UI until we get confirmation of the answer() through
213 // {@link #markCallAsActive}. However, if we ever change that to look more responsive,
214 // then we need to make sure we add a timeout for the answer() in case the call never
215 // comes out of RINGING.
216 call.answer();
217 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800218 }
219
220 /**
221 * Instructs Telecomm to reject the specified call. Intended to be invoked by the in-call
222 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
223 * the user opting to reject said call.
224 *
225 * @param callId The ID of the call.
226 */
227 void rejectCall(String callId) {
Santos Cordon61d0f702014-02-19 02:52:23 -0800228 Call call = mCalls.get(callId);
229 if (call == null) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800230 Log.i(this, "Request to reject a non-existent call %s", callId);
Santos Cordon61d0f702014-02-19 02:52:23 -0800231 } else {
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800232 stopRinging(call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800233 call.reject();
234 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800235 }
236
237 /**
238 * Instructs Telecomm to disconnect the specified call. Intended to be invoked by the
239 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
240 * the user hitting the end-call button.
241 *
242 * @param callId The ID of the call.
243 */
244 void disconnectCall(String callId) {
Santos Cordon049b7b62014-01-30 05:34:26 -0800245 Call call = mCalls.get(callId);
246 if (call == null) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800247 Log.w(this, "Unknown call (%s) asked to disconnect", callId);
Santos Cordon049b7b62014-01-30 05:34:26 -0800248 } else {
249 call.disconnect();
250 }
251
Sailesh Nepal1cecc7c2014-03-10 17:03:08 -0700252 // TODO(sail): Replace with CallAudioManager.
253 Log.v(this, "disconnectCall, abandoning audio focus");
254 Context context = TelecommApp.getInstance().getApplicationContext();
255 AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
256 audioManager.setMode(AudioManager.MODE_NORMAL);
257 audioManager.abandonAudioFocusForCall();
Santos Cordone3d76ab2014-01-28 17:25:20 -0800258 }
Santos Cordon681663d2014-01-30 04:32:15 -0800259
260 void markCallAsRinging(String callId) {
261 setCallState(callId, CallState.RINGING);
262 }
263
264 void markCallAsDialing(String callId) {
265 setCallState(callId, CallState.DIALING);
266 }
267
268 void markCallAsActive(String callId) {
269 setCallState(callId, CallState.ACTIVE);
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800270 removeFromUnansweredCalls(callId);
Sailesh Nepalfc511ca2014-02-20 18:48:53 -0800271 mInCallController.markCallAsActive(callId);
Sailesh Nepal1cecc7c2014-03-10 17:03:08 -0700272
273 // TODO(sail): Replace with CallAudioManager.
274 Log.v(this, "markCallAsActive, requesting audio focus");
275 Context context = TelecommApp.getInstance().getApplicationContext();
276 AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
277 audioManager.requestAudioFocusForCall(AudioManager.STREAM_VOICE_CALL,
278 AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
279 audioManager.setMode(AudioManager.MODE_IN_CALL);
280 audioManager.setMicrophoneMute(false);
281 audioManager.setSpeakerphoneOn(false);
Santos Cordon681663d2014-01-30 04:32:15 -0800282 }
283
Santos Cordon049b7b62014-01-30 05:34:26 -0800284 /**
285 * Marks the specified call as DISCONNECTED and notifies the in-call app. If this was the last
286 * live call, then also disconnect from the in-call controller.
287 *
288 * @param callId The ID of the call.
289 */
Santos Cordon681663d2014-01-30 04:32:15 -0800290 void markCallAsDisconnected(String callId) {
291 setCallState(callId, CallState.DISCONNECTED);
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800292 removeFromUnansweredCalls(callId);
Santos Cordonc195e362014-02-11 17:05:31 -0800293
294 Call call = mCalls.remove(callId);
295 // At this point the call service has confirmed that the call is disconnected to it is
296 // safe to disassociate the call from its call service.
297 call.clearCallService();
Santos Cordon049b7b62014-01-30 05:34:26 -0800298
299 // Notify the in-call UI
300 mInCallController.markCallAsDisconnected(callId);
301 if (mCalls.isEmpty()) {
302 mInCallController.unbind();
303 }
Yorke Leef98fb572014-03-05 10:56:55 -0800304
305 // Log the call in the call log.
306 mCallLogManager.logDisconnectedCall(call);
Santos Cordon681663d2014-01-30 04:32:15 -0800307 }
308
309 /**
Ben Gilada0d9f752014-02-26 11:49:03 -0800310 * Sends all the live calls to the in-call app if any exist. If there are no live calls, then
311 * tells the in-call controller to unbind since it is not needed.
312 */
313 void updateInCall() {
314 if (mCalls.isEmpty()) {
315 mInCallController.unbind();
316 } else {
317 for (Call call : mCalls.values()) {
318 addInCallEntry(call);
319 }
320 }
321 }
322
323 /**
324 * Adds the specified call to the main list of live calls.
325 *
326 * @param call The call to add.
327 */
328 private void addCall(Call call) {
329 mCalls.put(call.getId(), call);
330 addInCallEntry(call);
331 }
332
333 /**
334 * Notifies the in-call app of the specified (new) call.
335 */
336 private void addInCallEntry(Call call) {
337 mInCallController.addCall(call.toCallInfo());
338 }
339
340 /**
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800341 * Sets the specified state on the specified call. Updates the ringer if the call is exiting
342 * the RINGING state.
Santos Cordon681663d2014-01-30 04:32:15 -0800343 *
344 * @param callId The ID of the call to update.
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800345 * @param newState The new state of the call.
Santos Cordon681663d2014-01-30 04:32:15 -0800346 */
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800347 private void setCallState(String callId, CallState newState) {
Santos Cordon681663d2014-01-30 04:32:15 -0800348 Preconditions.checkState(!Strings.isNullOrEmpty(callId));
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800349 Preconditions.checkNotNull(newState);
Santos Cordon681663d2014-01-30 04:32:15 -0800350
351 Call call = mCalls.get(callId);
352 if (call == null) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800353 Log.w(this, "Call %s was not found while attempting to update the state to %s.",
354 callId, newState );
Santos Cordon681663d2014-01-30 04:32:15 -0800355 } else {
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800356 if (newState != call.getState()) {
357 // Unfortunately, in the telephony world the radio is king. So if the call notifies
358 // us that the call is in a particular state, we allow it even if it doesn't make
359 // sense (e.g., ACTIVE -> RINGING).
360 // TODO(santoscordon): Consider putting a stop to the above and turning CallState
361 // into a well-defined state machine.
362 // TODO(santoscordon): Define expected state transitions here, and log when an
363 // unexpected transition occurs.
364 call.setState(newState);
365 // TODO(santoscordon): Notify the in-call app whenever a call changes state.
Evan Charlton5c670a92014-03-06 14:58:20 -0800366
367 broadcastState(call);
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800368 }
369 }
370 }
371
372 /**
Evan Charlton5c670a92014-03-06 14:58:20 -0800373 * Send a {@link TelephonyManager#ACTION_PHONE_STATE_CHANGED} broadcast when the call state
374 * changes. TODO: Split this out into a separate class and do it properly; this is just a first
375 * pass over the functionality.
376 *
377 * @param call The {@link Call} being updated.
378 */
379 private void broadcastState(Call call) {
380 final String callState;
381 switch (call.getState()) {
382 case DIALING:
383 case ACTIVE:
384 callState = TelephonyManager.EXTRA_STATE_OFFHOOK;
385 break;
386
387 case RINGING:
388 callState = TelephonyManager.EXTRA_STATE_RINGING;
389 break;
390
391 case DISCONNECTED:
392 case ABORTED:
393 callState = TelephonyManager.EXTRA_STATE_IDLE;
394 break;
395
396 default:
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800397 Log.w(this, "Call is in an unknown state (%s), not broadcasting: %s", call.getState(),
398 call.getId());
Evan Charlton5c670a92014-03-06 14:58:20 -0800399 return;
400 }
401
402 Intent updateIntent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
403 updateIntent.putExtra(TelephonyManager.EXTRA_STATE, callState);
404
405 // Populate both, since the original API was needlessly complicated.
406 updateIntent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, call.getHandle());
407 // TODO: See if we can add this (the current API only sets this on NEW_OUTGOING_CALL).
408 updateIntent.putExtra(Intent.EXTRA_PHONE_NUMBER, call.getHandle());
409
410 // TODO: Replace these with real constants once this API has been vetted.
411 CallServiceWrapper callService = call.getCallService();
412 if (callService != null) {
413 updateIntent.putExtra(CallService.class.getName(), callService.getComponentName());
414 }
415 TelecommApp.getInstance().sendBroadcast(updateIntent, Manifest.permission.READ_PHONE_STATE);
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800416 Log.i(this, "Broadcasted state change: %s", callState);
Evan Charlton5c670a92014-03-06 14:58:20 -0800417 }
418
419 /**
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800420 * Removes the specified call from the list of unanswered incoming calls and updates the ringer
421 * based on the new state of {@link #mUnansweredIncomingCalls}. Safe to call with a call ID that
422 * is not present in the list of incoming calls.
423 *
424 * @param callId The ID of the call.
425 */
426 private void removeFromUnansweredCalls(String callId) {
427 Call call = mCalls.get(callId);
428 if (call != null && mUnansweredIncomingCalls.remove(call)) {
429 if (mUnansweredIncomingCalls.isEmpty()) {
430 mRinger.stopRinging();
431 } else {
432 mRinger.startRinging();
433 }
434 }
435 }
436
437 /**
438 * Stops playing the ringer if the specified call is the top-most incoming call. This exists
439 * separately from {@link #removeIncomingCall} for cases where we would like to stop playing the
440 * ringer for a call, but that call may still exist in {@link #mUnansweredIncomingCalls} - See
441 * {@link #rejectCall}, {@link #answerCall}.
442 *
443 * @param call The call for which we should stop ringing.
444 */
445 private void stopRinging(Call call) {
446 // Only stop the ringer if this call is the top-most incoming call.
447 if (!mUnansweredIncomingCalls.isEmpty() && mUnansweredIncomingCalls.get(0) == call) {
448 mRinger.stopRinging();
Santos Cordon681663d2014-01-30 04:32:15 -0800449 }
450 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800451}