blob: 8ccc0e3da9adee20855fec3cedc2516010b6b397 [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
Sailesh Nepalce704b92014-03-17 18:31:43 -070019import android.net.Uri;
Evan Charltona05805b2014-03-05 08:21:46 -080020import android.os.Bundle;
Sailesh Nepal6aca10a2014-03-24 16:11:02 -070021import android.telecomm.CallAudioState;
Sailesh Nepal810735e2014-03-18 18:15:46 -070022import android.telecomm.CallInfo;
Ben Giladc5b22692014-02-18 20:03:22 -080023import android.telecomm.CallServiceDescriptor;
Santos Cordon681663d2014-01-30 04:32:15 -080024import android.telecomm.CallState;
Yorke Lee33501632014-03-17 19:24:12 -070025import android.telecomm.GatewayInfo;
Nancy Chen77d2d0e2014-06-24 12:06:03 -070026import android.telecomm.Subscription;
Santos Cordon79ff2bc2014-03-27 15:31:27 -070027import android.telephony.DisconnectCause;
Santos Cordon8e8b8d22013-12-19 14:14:05 -080028
Santos Cordon681663d2014-01-30 04:32:15 -080029import com.google.common.base.Preconditions;
Sailesh Nepal810735e2014-03-18 18:15:46 -070030import com.google.common.collect.ImmutableCollection;
31import com.google.common.collect.ImmutableList;
Ben Gilad9f2bed32013-12-12 17:43:26 -080032
Santos Cordon23baed32014-06-27 14:45:39 -070033import java.util.ArrayList;
34import java.util.Arrays;
35import java.util.Collections;
Santos Cordonf3671a62014-05-29 21:51:53 -070036import java.util.HashSet;
37import java.util.LinkedHashSet;
Santos Cordona56f2762014-03-24 15:55:53 -070038import java.util.Set;
Ben Gilad9f2bed32013-12-12 17:43:26 -080039
Ben Giladdd8c6082013-12-30 14:44:08 -080040/**
41 * Singleton.
42 *
43 * NOTE(gilad): by design most APIs are package private, use the relevant adapter/s to allow
44 * access from other packages specifically refraining from passing the CallsManager instance
45 * beyond the com.android.telecomm package boundary.
46 */
Santos Cordon766d04f2014-05-06 10:28:25 -070047public final class CallsManager implements Call.Listener {
Ben Gilada0d9f752014-02-26 11:49:03 -080048
Santos Cordon74d420b2014-05-07 14:38:47 -070049 // TODO(santoscordon): Consider renaming this CallsManagerPlugin.
Sailesh Nepal810735e2014-03-18 18:15:46 -070050 interface CallsManagerListener {
51 void onCallAdded(Call call);
52 void onCallRemoved(Call call);
53 void onCallStateChanged(Call call, CallState oldState, CallState newState);
Sailesh Nepal8c85dee2014-04-07 22:21:40 -070054 void onCallHandoffHandleChanged(Call call, Uri oldHandle, Uri newHandle);
55 void onCallServiceChanged(
56 Call call,
57 CallServiceWrapper oldCallService,
58 CallServiceWrapper newCallService);
59 void onCallHandoffCallServiceDescriptorChanged(
60 Call call,
61 CallServiceDescriptor oldDescriptor,
62 CallServiceDescriptor newDescriptor);
Sailesh Nepal810735e2014-03-18 18:15:46 -070063 void onIncomingCallAnswered(Call call);
Ihab Awadff7493a2014-06-10 13:47:44 -070064 void onIncomingCallRejected(Call call, boolean rejectWithMessage, String textMessage);
Sailesh Nepal810735e2014-03-18 18:15:46 -070065 void onForegroundCallChanged(Call oldForegroundCall, Call newForegroundCall);
Sailesh Nepal6aca10a2014-03-24 16:11:02 -070066 void onAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState);
Ihab Awadcb387ac2014-05-28 16:49:38 -070067 void onRequestingRingback(Call call, boolean ringback);
Santos Cordona1610702014-06-04 20:22:56 -070068 void onIsConferenceCapableChanged(Call call, boolean isConferenceCapable);
69 void onIsConferencedChanged(Call call);
Ihab Awadff7493a2014-06-10 13:47:44 -070070 void onCannedSmsResponsesLoaded(Call call);
Nancy Chena65d41f2014-06-24 12:06:03 -070071 void onCallVideoProviderChanged(Call call);
Sailesh Nepal810735e2014-03-18 18:15:46 -070072 }
73
Santos Cordon8e8b8d22013-12-19 14:14:05 -080074 private static final CallsManager INSTANCE = new CallsManager();
Ben Gilad9f2bed32013-12-12 17:43:26 -080075
Santos Cordon8e8b8d22013-12-19 14:14:05 -080076 /**
Sailesh Nepale59bb192014-04-01 18:33:59 -070077 * The main call repository. Keeps an instance of all live calls. New incoming and outgoing
78 * calls are added to the map and removed when the calls move to the disconnected state.
Santos Cordon681663d2014-01-30 04:32:15 -080079 */
Santos Cordonf3671a62014-05-29 21:51:53 -070080 private final Set<Call> mCalls = new LinkedHashSet<>();
Santos Cordon681663d2014-01-30 04:32:15 -080081
82 /**
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070083 * Set of new calls created to perform a handoff. The calls are added when handoff is initiated
84 * and removed when hadnoff is complete.
85 */
Santos Cordonf3671a62014-05-29 21:51:53 -070086 private final Set<Call> mPendingHandoffCalls = new LinkedHashSet<>();
87
88
89 private final DtmfLocalTonePlayer mDtmfLocalTonePlayer = new DtmfLocalTonePlayer();
90 private final InCallController mInCallController = new InCallController();
91 private final CallAudioManager mCallAudioManager;
92 private final Ringer mRinger;
93 private final Set<CallsManagerListener> mListeners = new HashSet<>();
Santos Cordondeb8c892014-05-30 01:38:03 -070094 private final HeadsetMediaButton mHeadsetMediaButton;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070095
96 /**
Sailesh Nepal810735e2014-03-18 18:15:46 -070097 * The call the user is currently interacting with. This is the call that should have audio
98 * focus and be visible in the in-call UI.
Santos Cordon4e9fffe2014-03-04 18:13:41 -080099 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700100 private Call mForegroundCall;
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800101
Santos Cordon766d04f2014-05-06 10:28:25 -0700102 /** Singleton accessor. */
103 static CallsManager getInstance() {
104 return INSTANCE;
105 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800106
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800107 /**
Ben Gilad8bdaa462014-02-05 12:53:19 -0800108 * Initializes the required Telecomm components.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800109 */
110 private CallsManager() {
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700111 TelecommApp app = TelecommApp.getInstance();
Santos Cordona56f2762014-03-24 15:55:53 -0700112
Santos Cordondeb8c892014-05-30 01:38:03 -0700113 StatusBarNotifier statusBarNotifier = new StatusBarNotifier(app, this);
114 mCallAudioManager = new CallAudioManager(app, statusBarNotifier);
Santos Cordonc7b8eba2014-04-01 15:26:28 -0700115 InCallTonePlayer.Factory playerFactory = new InCallTonePlayer.Factory(mCallAudioManager);
Santos Cordonae193062014-05-21 21:21:49 -0700116 mRinger = new Ringer(mCallAudioManager, this, playerFactory, app);
Santos Cordondeb8c892014-05-30 01:38:03 -0700117 mHeadsetMediaButton = new HeadsetMediaButton(app, this);
Santos Cordonae193062014-05-21 21:21:49 -0700118
Santos Cordondeb8c892014-05-30 01:38:03 -0700119 mListeners.add(statusBarNotifier);
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700120 mListeners.add(new CallLogManager(app));
Santos Cordona56f2762014-03-24 15:55:53 -0700121 mListeners.add(new PhoneStateBroadcaster());
Santos Cordonf3671a62014-05-29 21:51:53 -0700122 mListeners.add(mInCallController);
Santos Cordonae193062014-05-21 21:21:49 -0700123 mListeners.add(mRinger);
Santos Cordonc7b8eba2014-04-01 15:26:28 -0700124 mListeners.add(new RingbackPlayer(this, playerFactory));
125 mListeners.add(new InCallToneMonitor(playerFactory, this));
Santos Cordona56f2762014-03-24 15:55:53 -0700126 mListeners.add(mCallAudioManager);
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700127 mListeners.add(app.getMissedCallNotifier());
Santos Cordon92a2d812014-04-30 15:19:01 -0700128 mListeners.add(mDtmfLocalTonePlayer);
Santos Cordon81289982014-06-03 16:03:08 -0700129 mListeners.add(mHeadsetMediaButton);
Ihab Awadff7493a2014-06-10 13:47:44 -0700130 mListeners.add(RespondViaSmsManager.getInstance());
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800131 }
132
Santos Cordon766d04f2014-05-06 10:28:25 -0700133 @Override
134 public void onSuccessfulOutgoingCall(Call call) {
135 Log.v(this, "onSuccessfulOutgoingCall, %s", call);
136 if (mCalls.contains(call)) {
137 // The call's CallService has been updated.
138 for (CallsManagerListener listener : mListeners) {
139 listener.onCallServiceChanged(call, null, call.getCallService());
140 }
141 } else if (mPendingHandoffCalls.contains(call)) {
142 updateHandoffCallServiceDescriptor(call.getOriginalCall(),
143 call.getCallService().getDescriptor());
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700144 } else {
145 Log.wtf(this, "unexpected successful call notification: %s", call);
146 return;
Santos Cordon766d04f2014-05-06 10:28:25 -0700147 }
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700148
149 markCallAsDialing(call);
Santos Cordon766d04f2014-05-06 10:28:25 -0700150 }
151
152 @Override
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700153 public void onFailedOutgoingCall(Call call, int errorCode, String errorMsg) {
154 Log.v(this, "onFailedOutgoingCall, call: %s", call);
155 // TODO: Replace disconnect cause with more specific disconnect causes.
156 markCallAsDisconnected(call, errorCode, errorMsg);
157 }
158
159 @Override
160 public void onCancelledOutgoingCall(Call call) {
161 Log.v(this, "onCancelledOutgoingCall, call: %s", call);
162 setCallState(call, CallState.ABORTED);
163 removeCall(call);
Santos Cordon766d04f2014-05-06 10:28:25 -0700164 }
165
166 @Override
167 public void onSuccessfulIncomingCall(Call call, CallInfo callInfo) {
168 Log.d(this, "onSuccessfulIncomingCall");
169 setCallState(call, callInfo.getState());
170 addCall(call);
171 }
172
173 @Override
174 public void onFailedIncomingCall(Call call) {
175 call.removeListener(this);
Ben Gilada0d9f752014-02-26 11:49:03 -0800176 }
177
Ihab Awadcb387ac2014-05-28 16:49:38 -0700178 @Override
Santos Cordona1610702014-06-04 20:22:56 -0700179 public void onIsConferenceCapableChanged(Call call, boolean isConferenceCapable) {
180 for (CallsManagerListener listener : mListeners) {
181 listener.onIsConferenceCapableChanged(call, isConferenceCapable);
182 }
183 }
184
185 @Override
Ihab Awadcb387ac2014-05-28 16:49:38 -0700186 public void onRequestingRingback(Call call, boolean ringback) {
187 for (CallsManagerListener listener : mListeners) {
188 listener.onRequestingRingback(call, ringback);
189 }
190 }
191
Evan Charlton352105c2014-06-03 14:10:54 -0700192 @Override
193 public void onPostDialWait(Call call, String remaining) {
194 mInCallController.onPostDialWait(call, remaining);
195 }
196
Santos Cordona1610702014-06-04 20:22:56 -0700197 @Override
198 public void onExpiredConferenceCall(Call call) {
199 call.removeListener(this);
200 }
201
202 @Override
203 public void onConfirmedConferenceCall(Call call) {
204 addCall(call);
205 Log.v(this, "confirming Conf call %s", call);
206 for (CallsManagerListener listener : mListeners) {
207 listener.onIsConferencedChanged(call);
208 }
209 }
210
211 @Override
212 public void onParentChanged(Call call) {
213 for (CallsManagerListener listener : mListeners) {
214 listener.onIsConferencedChanged(call);
215 }
216 }
217
218 @Override
219 public void onChildrenChanged(Call call) {
220 for (CallsManagerListener listener : mListeners) {
221 listener.onIsConferencedChanged(call);
222 }
223 }
224
Ihab Awadff7493a2014-06-10 13:47:44 -0700225 @Override
226 public void onCannedSmsResponsesLoaded(Call call) {
227 for (CallsManagerListener listener : mListeners) {
228 listener.onCannedSmsResponsesLoaded(call);
229 }
230 }
231
Nancy Chena65d41f2014-06-24 12:06:03 -0700232 @Override
233 public void onCallVideoProviderChanged(Call call) {
234 for (CallsManagerListener listener : mListeners) {
235 listener.onCallVideoProviderChanged(call);
236 }
237 }
238
Sailesh Nepal810735e2014-03-18 18:15:46 -0700239 ImmutableCollection<Call> getCalls() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700240 return ImmutableList.copyOf(mCalls);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700241 }
242
243 Call getForegroundCall() {
244 return mForegroundCall;
245 }
246
Santos Cordonae193062014-05-21 21:21:49 -0700247 Ringer getRinger() {
248 return mRinger;
249 }
250
Santos Cordonf3671a62014-05-29 21:51:53 -0700251 InCallController getInCallController() {
252 return mInCallController;
253 }
254
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700255 boolean hasEmergencyCall() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700256 for (Call call : mCalls) {
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700257 if (call.isEmergencyCall()) {
258 return true;
259 }
260 }
261 return false;
262 }
263
264 CallAudioState getAudioState() {
265 return mCallAudioManager.getAudioState();
266 }
267
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800268 /**
Santos Cordon493e8f22014-02-19 03:15:12 -0800269 * Starts the incoming call sequence by having switchboard gather more information about the
270 * specified call; using the specified call service descriptor. Upon success, execution returns
Santos Cordon766d04f2014-05-06 10:28:25 -0700271 * to {@link #onSuccessfulIncomingCall} to start the in-call UI.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800272 *
Ben Giladc5b22692014-02-18 20:03:22 -0800273 * @param descriptor The descriptor of the call service to use for this incoming call.
Evan Charltona05805b2014-03-05 08:21:46 -0800274 * @param extras The optional extras Bundle passed with the intent used for the incoming call.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800275 */
Evan Charltona05805b2014-03-05 08:21:46 -0800276 void processIncomingCallIntent(CallServiceDescriptor descriptor, Bundle extras) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800277 Log.d(this, "processIncomingCallIntent");
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800278 // Create a call with no handle. Eventually, switchboard will update the call with
Sailesh Nepale59bb192014-04-01 18:33:59 -0700279 // additional information from the call service, but for now we just need one to pass
280 // around.
Santos Cordona1610702014-06-04 20:22:56 -0700281 Call call = new Call(true /* isIncoming */, false /* isConference */);
Santos Cordon766d04f2014-05-06 10:28:25 -0700282 // TODO(santoscordon): Move this to be a part of addCall()
283 call.addListener(this);
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800284
Santos Cordon766d04f2014-05-06 10:28:25 -0700285 call.startIncoming(descriptor, extras);
Ben Gilada0d9f752014-02-26 11:49:03 -0800286 }
287
288 /**
Yorke Lee33501632014-03-17 19:24:12 -0700289 * Attempts to issue/connect the specified call.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800290 *
Yorke Lee33501632014-03-17 19:24:12 -0700291 * @param handle Handle to connect the call with.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800292 * @param contactInfo Information about the entity being called.
Yorke Lee33501632014-03-17 19:24:12 -0700293 * @param gatewayInfo Optional gateway information that can be used to route the call to the
Santos Cordon5b7b9b32014-03-26 14:00:22 -0700294 * actual dialed handle via a gateway provider. May be null.
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700295 * @param speakerphoneOn Whether or not to turn the speakerphone on once the call connects.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800296 */
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700297 void placeOutgoingCall(Uri handle, ContactInfo contactInfo, GatewayInfo gatewayInfo,
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700298 Subscription subscription, boolean speakerphoneOn) {
Yorke Lee33501632014-03-17 19:24:12 -0700299 final Uri uriHandle = (gatewayInfo == null) ? handle : gatewayInfo.getGatewayHandle();
300
301 if (gatewayInfo == null) {
Santos Cordonb58f4532014-05-29 11:59:06 -0700302 Log.i(this, "Creating a new outgoing call with handle: %s", Log.piiHandle(uriHandle));
Yorke Lee33501632014-03-17 19:24:12 -0700303 } else {
304 Log.i(this, "Creating a new outgoing call with gateway handle: %s, original handle: %s",
305 Log.pii(uriHandle), Log.pii(handle));
306 }
Santos Cordon766d04f2014-05-06 10:28:25 -0700307
Santos Cordona1610702014-06-04 20:22:56 -0700308 Call call = new Call(
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700309 uriHandle, gatewayInfo, subscription,
310 false /* isIncoming */, false /* isConference */);
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700311 call.setStartWithSpeakerphoneOn(speakerphoneOn);
Santos Cordon766d04f2014-05-06 10:28:25 -0700312
313 // TODO(santoscordon): Move this to be a part of addCall()
314 call.addListener(this);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700315 addCall(call);
Santos Cordone3d76ab2014-01-28 17:25:20 -0800316
Santos Cordon766d04f2014-05-06 10:28:25 -0700317 call.startOutgoing();
Yorke Leef98fb572014-03-05 10:56:55 -0800318 }
319
320 /**
Santos Cordona1610702014-06-04 20:22:56 -0700321 * Attempts to start a conference call for the specified call.
322 *
323 * @param call The call to conference with.
324 */
325 void conference(Call call) {
326 Call conferenceCall = new Call(false, true);
327 conferenceCall.addListener(this);
328 call.conferenceInto(conferenceCall);
329 }
330
331 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800332 * Instructs Telecomm to answer the specified call. Intended to be invoked by the in-call
333 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
334 * the user opting to answer said call.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800335 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700336 void answerCall(Call call) {
337 if (!mCalls.contains(call)) {
338 Log.i(this, "Request to answer a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800339 } else {
Santos Cordon40f78c22014-04-07 02:11:42 -0700340 // If the foreground call is not the ringing call and it is currently isActive() or
341 // DIALING, put it on hold before answering the call.
342 if (mForegroundCall != null && mForegroundCall != call &&
343 (mForegroundCall.isActive() ||
344 mForegroundCall.getState() == CallState.DIALING)) {
345 Log.v(this, "Holding active/dialing call %s before answering incoming call %s.",
346 mForegroundCall, call);
347 mForegroundCall.hold();
348 // TODO(santoscordon): Wait until we get confirmation of the active call being
349 // on-hold before answering the new call.
350 // TODO(santoscordon): Import logic from CallManager.acceptCall()
351 }
352
Santos Cordona56f2762014-03-24 15:55:53 -0700353 for (CallsManagerListener listener : mListeners) {
354 listener.onIncomingCallAnswered(call);
355 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800356
Santos Cordon61d0f702014-02-19 02:52:23 -0800357 // We do not update the UI until we get confirmation of the answer() through
Sailesh Nepale59bb192014-04-01 18:33:59 -0700358 // {@link #markCallAsActive}.
Santos Cordon61d0f702014-02-19 02:52:23 -0800359 call.answer();
360 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800361 }
362
363 /**
364 * Instructs Telecomm to reject the specified call. Intended to be invoked by the in-call
365 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
366 * the user opting to reject said call.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800367 */
Ihab Awadff7493a2014-06-10 13:47:44 -0700368 void rejectCall(Call call, boolean rejectWithMessage, String textMessage) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700369 if (!mCalls.contains(call)) {
370 Log.i(this, "Request to reject a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800371 } else {
Santos Cordona56f2762014-03-24 15:55:53 -0700372 for (CallsManagerListener listener : mListeners) {
Ihab Awadff7493a2014-06-10 13:47:44 -0700373 listener.onIncomingCallRejected(call, rejectWithMessage, textMessage);
Santos Cordona56f2762014-03-24 15:55:53 -0700374 }
Ihab Awadff7493a2014-06-10 13:47:44 -0700375 call.reject(rejectWithMessage, textMessage);
Santos Cordon61d0f702014-02-19 02:52:23 -0800376 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800377 }
378
379 /**
Ihab Awad74549ec2014-03-10 15:33:25 -0700380 * Instructs Telecomm to play the specified DTMF tone within the specified call.
381 *
Ihab Awad74549ec2014-03-10 15:33:25 -0700382 * @param digit The DTMF digit to play.
383 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700384 void playDtmfTone(Call call, char digit) {
385 if (!mCalls.contains(call)) {
386 Log.i(this, "Request to play DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700387 } else {
388 call.playDtmfTone(digit);
Santos Cordon92a2d812014-04-30 15:19:01 -0700389 mDtmfLocalTonePlayer.playTone(call, digit);
Ihab Awad74549ec2014-03-10 15:33:25 -0700390 }
391 }
392
393 /**
394 * Instructs Telecomm to stop the currently playing DTMF tone, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -0700395 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700396 void stopDtmfTone(Call call) {
397 if (!mCalls.contains(call)) {
398 Log.i(this, "Request to stop DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700399 } else {
400 call.stopDtmfTone();
Santos Cordon92a2d812014-04-30 15:19:01 -0700401 mDtmfLocalTonePlayer.stopTone(call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700402 }
403 }
404
405 /**
Evan Charlton352105c2014-06-03 14:10:54 -0700406 * Instructs Telecomm to continue (or not) the current post-dial DTMF string, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -0700407 */
Evan Charlton352105c2014-06-03 14:10:54 -0700408 void postDialContinue(Call call, boolean proceed) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700409 if (!mCalls.contains(call)) {
410 Log.i(this, "Request to continue post-dial string in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700411 } else {
Evan Charlton352105c2014-06-03 14:10:54 -0700412 call.postDialContinue(proceed);
Ihab Awad74549ec2014-03-10 15:33:25 -0700413 }
414 }
415
416 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800417 * Instructs Telecomm to disconnect the specified call. Intended to be invoked by the
418 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
419 * the user hitting the end-call button.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800420 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700421 void disconnectCall(Call call) {
Santos Cordon682fe6b2014-05-20 08:56:39 -0700422 Log.v(this, "disconnectCall %s", call);
423
Sailesh Nepale59bb192014-04-01 18:33:59 -0700424 if (!mCalls.contains(call)) {
425 Log.w(this, "Unknown call (%s) asked to disconnect", call);
Santos Cordon049b7b62014-01-30 05:34:26 -0800426 } else {
427 call.disconnect();
428 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800429 }
Santos Cordon681663d2014-01-30 04:32:15 -0800430
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700431 /**
432 * Instructs Telecomm to put the specified call on hold. Intended to be invoked by the
433 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
434 * the user hitting the hold button during an active call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700435 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700436 void holdCall(Call call) {
437 if (!mCalls.contains(call)) {
438 Log.w(this, "Unknown call (%s) asked to be put on hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700439 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700440 Log.d(this, "Putting call on hold: (%s)", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700441 call.hold();
442 }
443 }
444
445 /**
446 * Instructs Telecomm to release the specified call from hold. Intended to be invoked by
447 * the in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered
448 * by the user hitting the hold button during a held call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700449 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700450 void unholdCall(Call call) {
451 if (!mCalls.contains(call)) {
452 Log.w(this, "Unknown call (%s) asked to be removed from hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700453 } else {
Santos Cordonc7e85d42014-05-22 02:51:48 -0700454 Log.d(this, "unholding call: (%s)", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700455 call.unhold();
456 }
457 }
458
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700459 /** Called by the in-call UI to change the mute state. */
460 void mute(boolean shouldMute) {
461 mCallAudioManager.mute(shouldMute);
462 }
463
464 /**
465 * Called by the in-call UI to change the audio route, for example to change from earpiece to
466 * speaker phone.
467 */
468 void setAudioRoute(int route) {
469 mCallAudioManager.setAudioRoute(route);
470 }
471
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700472 void startHandoffForCall(Call originalCall) {
473 if (!mCalls.contains(originalCall)) {
474 Log.w(this, "Unknown call %s asked to be handed off", originalCall);
475 return;
476 }
477
478 for (Call handoffCall : mPendingHandoffCalls) {
479 if (handoffCall.getOriginalCall() == originalCall) {
480 Log.w(this, "Call %s is already being handed off, skipping", originalCall);
481 return;
482 }
483 }
484
485 // Create a new call to be placed in the background. If handoff is successful then the
486 // original call will live on but its state will be updated to the new call's state. In
487 // particular the original call's call service will be updated to the new call's call
488 // service.
Santos Cordona1610702014-06-04 20:22:56 -0700489 Call tempCall = new Call(
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700490 originalCall.getHandoffHandle(), originalCall.getGatewayInfo(),
491 originalCall.getSubscription(), false, false);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700492 tempCall.setOriginalCall(originalCall);
493 tempCall.setExtras(originalCall.getExtras());
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700494 mPendingHandoffCalls.add(tempCall);
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700495 tempCall.addListener(this);
496
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700497 Log.d(this, "Placing handoff call");
Santos Cordon766d04f2014-05-06 10:28:25 -0700498 tempCall.startOutgoing();
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700499 }
500
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700501 /** Called when the audio state changes. */
502 void onAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState) {
503 Log.v(this, "onAudioStateChanged, audioState: %s -> %s", oldAudioState, newAudioState);
Santos Cordona56f2762014-03-24 15:55:53 -0700504 for (CallsManagerListener listener : mListeners) {
505 listener.onAudioStateChanged(oldAudioState, newAudioState);
506 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700507 }
508
Sailesh Nepale59bb192014-04-01 18:33:59 -0700509 void markCallAsRinging(Call call) {
510 setCallState(call, CallState.RINGING);
Santos Cordon681663d2014-01-30 04:32:15 -0800511 }
512
Sailesh Nepale59bb192014-04-01 18:33:59 -0700513 void markCallAsDialing(Call call) {
514 setCallState(call, CallState.DIALING);
Santos Cordon681663d2014-01-30 04:32:15 -0800515 }
516
Sailesh Nepale59bb192014-04-01 18:33:59 -0700517 void markCallAsActive(Call call) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700518 if (call.getConnectTimeMillis() == 0) {
519 call.setConnectTimeMillis(System.currentTimeMillis());
520 }
Sailesh Nepale59bb192014-04-01 18:33:59 -0700521 setCallState(call, CallState.ACTIVE);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700522
523 if (mPendingHandoffCalls.contains(call)) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700524 completeHandoff(call, true);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700525 }
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700526 if (call.getStartWithSpeakerphoneOn()) {
527 setAudioRoute(CallAudioState.ROUTE_SPEAKER);
528 }
Santos Cordon681663d2014-01-30 04:32:15 -0800529 }
530
Sailesh Nepale59bb192014-04-01 18:33:59 -0700531 void markCallAsOnHold(Call call) {
532 setCallState(call, CallState.ON_HOLD);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700533 }
534
Santos Cordon049b7b62014-01-30 05:34:26 -0800535 /**
536 * Marks the specified call as DISCONNECTED and notifies the in-call app. If this was the last
537 * live call, then also disconnect from the in-call controller.
538 *
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700539 * @param disconnectCause The disconnect reason, see {@link android.telephony.DisconnectCause}.
540 * @param disconnectMessage Optional call-service-provided message about the disconnect.
Santos Cordon049b7b62014-01-30 05:34:26 -0800541 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700542 void markCallAsDisconnected(Call call, int disconnectCause, String disconnectMessage) {
543 call.setDisconnectCause(disconnectCause, disconnectMessage);
544 setCallState(call, CallState.DISCONNECTED);
Sailesh Nepal4857f472014-04-07 22:26:27 -0700545
546 // Only remove the call if handoff is not pending.
547 if (call.getHandoffCallServiceDescriptor() == null) {
548 removeCall(call);
549 }
Ben Gilada0d9f752014-02-26 11:49:03 -0800550 }
551
Sailesh Nepal6ab6fb72014-04-01 20:03:19 -0700552 void setHandoffInfo(Call call, Uri handle, Bundle extras) {
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700553 if (!mCalls.contains(call)) {
554 Log.w(this, "Unknown call (%s) asked to set handoff info", call);
555 return;
556 }
557
558 if (extras == null) {
559 call.setExtras(Bundle.EMPTY);
560 } else {
561 call.setExtras(extras);
562 }
563
564 Uri oldHandle = call.getHandoffHandle();
565 Log.v(this, "set handoff handle %s -> %s, for call: %s", oldHandle, handle, call);
566 if (!areUriEqual(oldHandle, handle)) {
567 call.setHandoffHandle(handle);
568 for (CallsManagerListener listener : mListeners) {
569 listener.onCallHandoffHandleChanged(call, oldHandle, handle);
570 }
571 }
Sailesh Nepal6ab6fb72014-04-01 20:03:19 -0700572 }
573
Ben Gilada0d9f752014-02-26 11:49:03 -0800574 /**
Santos Cordon4b2c1192014-03-19 18:15:38 -0700575 * Cleans up any calls currently associated with the specified call service when the
576 * call-service binder disconnects unexpectedly.
577 *
578 * @param callService The call service that disconnected.
579 */
580 void handleCallServiceDeath(CallServiceWrapper callService) {
581 Preconditions.checkNotNull(callService);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700582 for (Call call : ImmutableList.copyOf(mCalls)) {
Santos Cordon4b2c1192014-03-19 18:15:38 -0700583 if (call.getCallService() == callService) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700584 markCallAsDisconnected(call, DisconnectCause.ERROR_UNSPECIFIED, null);
Santos Cordon4b2c1192014-03-19 18:15:38 -0700585 }
586 }
587 }
588
Santos Cordondeb8c892014-05-30 01:38:03 -0700589 boolean hasAnyCalls() {
590 return !mCalls.isEmpty();
591 }
592
Santos Cordonc7e85d42014-05-22 02:51:48 -0700593 boolean hasActiveOrHoldingCall() {
Santos Cordon23baed32014-06-27 14:45:39 -0700594 return getFirstCallWithState(CallState.ACTIVE, CallState.ON_HOLD) != null;
Santos Cordonc7e85d42014-05-22 02:51:48 -0700595 }
596
597 boolean hasRingingCall() {
Santos Cordon23baed32014-06-27 14:45:39 -0700598 return getFirstCallWithState(CallState.RINGING) != null;
Santos Cordonc7e85d42014-05-22 02:51:48 -0700599 }
600
Santos Cordondeb8c892014-05-30 01:38:03 -0700601 boolean onMediaButton(int type) {
602 if (hasAnyCalls()) {
603 if (HeadsetMediaButton.SHORT_PRESS == type) {
604 Call ringingCall = getFirstCallWithState(CallState.RINGING);
605 if (ringingCall == null) {
606 mCallAudioManager.toggleMute();
607 return true;
608 } else {
609 ringingCall.answer();
610 return true;
611 }
612 } else if (HeadsetMediaButton.LONG_PRESS == type) {
613 Log.d(this, "handleHeadsetHook: longpress -> hangup");
614 Call callToHangup = getFirstCallWithState(
615 CallState.RINGING, CallState.DIALING, CallState.ACTIVE, CallState.ON_HOLD);
616 if (callToHangup != null) {
617 callToHangup.disconnect();
618 return true;
619 }
620 }
621 }
622 return false;
623 }
624
625 /**
Santos Cordon10838c22014-06-11 17:36:04 -0700626 * Checks to see if the specified call is the only high-level call and if so, enable the
627 * "Add-call" button. We allow you to add a second call but not a third or beyond.
628 *
629 * @param call The call to test for add-call.
630 * @return Whether the add-call feature should be enabled for the call.
631 */
632 protected boolean isAddCallCapable(Call call) {
633 if (call.getParentCall() != null) {
634 // Never true for child calls.
635 return false;
636 }
637
638 // Loop through all the other calls and there exists a top level (has no parent) call
639 // that is not the specified call, return false.
640 for (Call otherCall : mCalls) {
641 if (call != otherCall && otherCall.getParentCall() == null) {
642 return false;
643 }
644 }
645 return true;
646 }
647
648 /**
Santos Cordondeb8c892014-05-30 01:38:03 -0700649 * Returns the first call that it finds with the given states. The states are treated as having
650 * priority order so that any call with the first state will be returned before any call with
651 * states listed later in the parameter list.
652 */
Santos Cordon23baed32014-06-27 14:45:39 -0700653 Call getFirstCallWithState(CallState... states) {
Santos Cordondeb8c892014-05-30 01:38:03 -0700654 for (CallState currentState : states) {
Santos Cordon23baed32014-06-27 14:45:39 -0700655 // check the foreground first
656 if (mForegroundCall != null && mForegroundCall.getState() == currentState) {
657 return mForegroundCall;
658 }
659
Santos Cordondeb8c892014-05-30 01:38:03 -0700660 for (Call call : mCalls) {
661 if (currentState == call.getState()) {
662 return call;
663 }
664 }
665 }
666 return null;
667 }
668
Santos Cordon4b2c1192014-03-19 18:15:38 -0700669 /**
Ben Gilada0d9f752014-02-26 11:49:03 -0800670 * Adds the specified call to the main list of live calls.
671 *
672 * @param call The call to add.
673 */
674 private void addCall(Call call) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700675 mCalls.add(call);
Santos Cordon40f78c22014-04-07 02:11:42 -0700676
677 // TODO(santoscordon): Update mForegroundCall prior to invoking
678 // onCallAdded for calls which immediately take the foreground (like the first call).
Santos Cordona56f2762014-03-24 15:55:53 -0700679 for (CallsManagerListener listener : mListeners) {
680 listener.onCallAdded(call);
681 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700682 updateForegroundCall();
Ben Gilada0d9f752014-02-26 11:49:03 -0800683 }
684
Sailesh Nepal810735e2014-03-18 18:15:46 -0700685 private void removeCall(Call call) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700686 // If a handoff is pending then the original call shouldn't be removed.
687 Preconditions.checkState(call.getHandoffCallServiceDescriptor() == null);
Santos Cordonc499c1c2014-04-14 17:13:14 -0700688 Log.v(this, "removeCall(%s)", call);
Sailesh Nepal4857f472014-04-07 22:26:27 -0700689
Santos Cordon766d04f2014-05-06 10:28:25 -0700690 call.removeListener(this);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700691 call.clearCallService();
Sailesh Nepale59bb192014-04-01 18:33:59 -0700692
693 boolean shouldNotify = false;
694 if (mCalls.contains(call)) {
695 mCalls.remove(call);
696 shouldNotify = true;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700697 } else if (mPendingHandoffCalls.contains(call)) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700698 Log.v(this, "removeCall, marking handoff call as failed");
699 completeHandoff(call, false);
Santos Cordona56f2762014-03-24 15:55:53 -0700700 }
Ben Gilada0d9f752014-02-26 11:49:03 -0800701
Sailesh Nepale59bb192014-04-01 18:33:59 -0700702 // Only broadcast changes for calls that are being tracked.
703 if (shouldNotify) {
704 for (CallsManagerListener listener : mListeners) {
705 listener.onCallRemoved(call);
706 }
707 updateForegroundCall();
Sailesh Nepal810735e2014-03-18 18:15:46 -0700708 }
709 }
Evan Charlton5c670a92014-03-06 14:58:20 -0800710
Sailesh Nepal810735e2014-03-18 18:15:46 -0700711 /**
Santos Cordon1ae2b852014-03-19 03:03:10 -0700712 * Sets the specified state on the specified call.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700713 *
714 * @param call The call.
715 * @param newState The new state of the call.
716 */
717 private void setCallState(Call call, CallState newState) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700718 Preconditions.checkNotNull(newState);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700719 CallState oldState = call.getState();
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700720 Log.i(this, "setCallState %s -> %s, call: %s", oldState, newState, call);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700721 if (newState != oldState) {
722 // Unfortunately, in the telephony world the radio is king. So if the call notifies
723 // us that the call is in a particular state, we allow it even if it doesn't make
724 // sense (e.g., ACTIVE -> RINGING).
725 // TODO(santoscordon): Consider putting a stop to the above and turning CallState
726 // into a well-defined state machine.
727 // TODO(santoscordon): Define expected state transitions here, and log when an
728 // unexpected transition occurs.
729 call.setState(newState);
730
731 // Only broadcast state change for calls that are being tracked.
Sailesh Nepale59bb192014-04-01 18:33:59 -0700732 if (mCalls.contains(call)) {
Santos Cordona56f2762014-03-24 15:55:53 -0700733 for (CallsManagerListener listener : mListeners) {
734 listener.onCallStateChanged(call, oldState, newState);
735 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700736 updateForegroundCall();
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800737 }
738 }
739 }
740
741 /**
Sailesh Nepal810735e2014-03-18 18:15:46 -0700742 * Checks which call should be visible to the user and have audio focus.
Evan Charlton5c670a92014-03-06 14:58:20 -0800743 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700744 private void updateForegroundCall() {
745 Call newForegroundCall = null;
Sailesh Nepale59bb192014-04-01 18:33:59 -0700746 for (Call call : mCalls) {
Santos Cordon40f78c22014-04-07 02:11:42 -0700747 // TODO(santoscordon): Foreground-ness needs to be explicitly set. No call, regardless
748 // of its state will be foreground by default and instead the call service should be
749 // notified when its calls enter and exit foreground state. Foreground will mean that
750 // the call should play audio and listen to microphone if it wants.
751
752 // Active calls have priority.
753 if (call.isActive()) {
Sailesh Nepal810735e2014-03-18 18:15:46 -0700754 newForegroundCall = call;
Evan Charlton5c670a92014-03-06 14:58:20 -0800755 break;
Sailesh Nepal810735e2014-03-18 18:15:46 -0700756 }
Santos Cordon40f78c22014-04-07 02:11:42 -0700757
758 if (call.isAlive() || call.getState() == CallState.RINGING) {
Sailesh Nepal810735e2014-03-18 18:15:46 -0700759 newForegroundCall = call;
Santos Cordon40f78c22014-04-07 02:11:42 -0700760 // Don't break in case there's an active call that has priority.
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800761 }
762 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800763
Sailesh Nepal810735e2014-03-18 18:15:46 -0700764 if (newForegroundCall != mForegroundCall) {
Santos Cordon40f78c22014-04-07 02:11:42 -0700765 Log.v(this, "Updating foreground call, %s -> %s.", mForegroundCall, newForegroundCall);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700766 Call oldForegroundCall = mForegroundCall;
767 mForegroundCall = newForegroundCall;
768
Santos Cordona56f2762014-03-24 15:55:53 -0700769 for (CallsManagerListener listener : mListeners) {
770 listener.onForegroundCallChanged(oldForegroundCall, mForegroundCall);
771 }
Santos Cordon681663d2014-01-30 04:32:15 -0800772 }
773 }
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700774
Sailesh Nepal4857f472014-04-07 22:26:27 -0700775 private void completeHandoff(Call handoffCall, boolean wasSuccessful) {
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700776 Call originalCall = handoffCall.getOriginalCall();
Sailesh Nepal4857f472014-04-07 22:26:27 -0700777 Log.v(this, "complete handoff, %s -> %s, wasSuccessful: %b", handoffCall, originalCall,
778 wasSuccessful);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700779
Sailesh Nepal4857f472014-04-07 22:26:27 -0700780 // Remove the transient handoff call object (don't disconnect because the call could still
781 // be live).
782 mPendingHandoffCalls.remove(handoffCall);
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700783 handoffCall.removeListener(this);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700784
Sailesh Nepal4857f472014-04-07 22:26:27 -0700785 if (wasSuccessful) {
Sailesh Nepaldcd64262014-05-23 17:03:28 -0700786 if (TelephonyUtil.isCurrentlyPSTNCall(originalCall)) {
787 originalCall.disconnect();
788 }
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700789
Sailesh Nepal4857f472014-04-07 22:26:27 -0700790 // Synchronize.
791 originalCall.setCallService(handoffCall.getCallService(), handoffCall);
792 setCallState(originalCall, handoffCall.getState());
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700793
Sailesh Nepal4857f472014-04-07 22:26:27 -0700794 // Force the foreground call changed notification to be sent.
795 for (CallsManagerListener listener : mListeners) {
796 listener.onForegroundCallChanged(mForegroundCall, mForegroundCall);
797 }
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700798
Sailesh Nepal4857f472014-04-07 22:26:27 -0700799 updateHandoffCallServiceDescriptor(originalCall, null);
800 } else {
801 updateHandoffCallServiceDescriptor(originalCall, null);
802 if (originalCall.getState() == CallState.DISCONNECTED ||
803 originalCall.getState() == CallState.ABORTED) {
804 removeCall(originalCall);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700805 }
806 }
807 }
808
Sailesh Nepal4857f472014-04-07 22:26:27 -0700809 private void updateHandoffCallServiceDescriptor(
810 Call originalCall,
811 CallServiceDescriptor newDescriptor) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700812 CallServiceDescriptor oldDescriptor = originalCall.getHandoffCallServiceDescriptor();
Sailesh Nepal4857f472014-04-07 22:26:27 -0700813 Log.v(this, "updateHandoffCallServiceDescriptor, call: %s, pending descriptor: %s -> %s",
814 originalCall, oldDescriptor, newDescriptor);
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700815
816 if (!areDescriptorsEqual(oldDescriptor, newDescriptor)) {
817 originalCall.setHandoffCallServiceDescriptor(newDescriptor);
818 for (CallsManagerListener listener : mListeners) {
819 listener.onCallHandoffCallServiceDescriptorChanged(originalCall, oldDescriptor,
820 newDescriptor);
821 }
822 }
823 }
824
825 private static boolean areDescriptorsEqual(
826 CallServiceDescriptor descriptor1,
827 CallServiceDescriptor descriptor2) {
828 if (descriptor1 == null) {
829 return descriptor2 == null;
830 }
831 return descriptor1.equals(descriptor2);
832 }
833
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700834 private static boolean areUriEqual(Uri handle1, Uri handle2) {
835 if (handle1 == null) {
836 return handle2 == null;
837 }
838 return handle1.equals(handle2);
839 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800840}