blob: 26f627f883f792be2922e1cb2817b49572b1056a [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 Cordonf3671a62014-05-29 21:51:53 -070033import java.util.HashSet;
34import java.util.LinkedHashSet;
Santos Cordona56f2762014-03-24 15:55:53 -070035import java.util.Set;
Ben Gilad9f2bed32013-12-12 17:43:26 -080036
Ben Giladdd8c6082013-12-30 14:44:08 -080037/**
38 * Singleton.
39 *
40 * NOTE(gilad): by design most APIs are package private, use the relevant adapter/s to allow
41 * access from other packages specifically refraining from passing the CallsManager instance
42 * beyond the com.android.telecomm package boundary.
43 */
Santos Cordon766d04f2014-05-06 10:28:25 -070044public final class CallsManager implements Call.Listener {
Ben Gilada0d9f752014-02-26 11:49:03 -080045
Santos Cordon74d420b2014-05-07 14:38:47 -070046 // TODO(santoscordon): Consider renaming this CallsManagerPlugin.
Sailesh Nepal810735e2014-03-18 18:15:46 -070047 interface CallsManagerListener {
48 void onCallAdded(Call call);
49 void onCallRemoved(Call call);
50 void onCallStateChanged(Call call, CallState oldState, CallState newState);
Sailesh Nepal8c85dee2014-04-07 22:21:40 -070051 void onCallHandoffHandleChanged(Call call, Uri oldHandle, Uri newHandle);
52 void onCallServiceChanged(
53 Call call,
54 CallServiceWrapper oldCallService,
55 CallServiceWrapper newCallService);
56 void onCallHandoffCallServiceDescriptorChanged(
57 Call call,
58 CallServiceDescriptor oldDescriptor,
59 CallServiceDescriptor newDescriptor);
Sailesh Nepal810735e2014-03-18 18:15:46 -070060 void onIncomingCallAnswered(Call call);
Ihab Awadff7493a2014-06-10 13:47:44 -070061 void onIncomingCallRejected(Call call, boolean rejectWithMessage, String textMessage);
Sailesh Nepal810735e2014-03-18 18:15:46 -070062 void onForegroundCallChanged(Call oldForegroundCall, Call newForegroundCall);
Sailesh Nepal6aca10a2014-03-24 16:11:02 -070063 void onAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState);
Ihab Awadcb387ac2014-05-28 16:49:38 -070064 void onRequestingRingback(Call call, boolean ringback);
Santos Cordona1610702014-06-04 20:22:56 -070065 void onIsConferenceCapableChanged(Call call, boolean isConferenceCapable);
66 void onIsConferencedChanged(Call call);
Ihab Awadff7493a2014-06-10 13:47:44 -070067 void onCannedSmsResponsesLoaded(Call call);
Nancy Chena65d41f2014-06-24 12:06:03 -070068 void onCallVideoProviderChanged(Call call);
Sailesh Nepal810735e2014-03-18 18:15:46 -070069 }
70
Santos Cordon8e8b8d22013-12-19 14:14:05 -080071 private static final CallsManager INSTANCE = new CallsManager();
Ben Gilad9f2bed32013-12-12 17:43:26 -080072
Santos Cordon8e8b8d22013-12-19 14:14:05 -080073 /**
Sailesh Nepale59bb192014-04-01 18:33:59 -070074 * The main call repository. Keeps an instance of all live calls. New incoming and outgoing
75 * calls are added to the map and removed when the calls move to the disconnected state.
Santos Cordon681663d2014-01-30 04:32:15 -080076 */
Santos Cordonf3671a62014-05-29 21:51:53 -070077 private final Set<Call> mCalls = new LinkedHashSet<>();
Santos Cordon681663d2014-01-30 04:32:15 -080078
79 /**
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070080 * Set of new calls created to perform a handoff. The calls are added when handoff is initiated
81 * and removed when hadnoff is complete.
82 */
Santos Cordonf3671a62014-05-29 21:51:53 -070083 private final Set<Call> mPendingHandoffCalls = new LinkedHashSet<>();
84
85
86 private final DtmfLocalTonePlayer mDtmfLocalTonePlayer = new DtmfLocalTonePlayer();
87 private final InCallController mInCallController = new InCallController();
88 private final CallAudioManager mCallAudioManager;
89 private final Ringer mRinger;
90 private final Set<CallsManagerListener> mListeners = new HashSet<>();
Santos Cordondeb8c892014-05-30 01:38:03 -070091 private final HeadsetMediaButton mHeadsetMediaButton;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070092
93 /**
Sailesh Nepal810735e2014-03-18 18:15:46 -070094 * The call the user is currently interacting with. This is the call that should have audio
95 * focus and be visible in the in-call UI.
Santos Cordon4e9fffe2014-03-04 18:13:41 -080096 */
Sailesh Nepal810735e2014-03-18 18:15:46 -070097 private Call mForegroundCall;
Santos Cordon4e9fffe2014-03-04 18:13:41 -080098
Santos Cordon766d04f2014-05-06 10:28:25 -070099 /** Singleton accessor. */
100 static CallsManager getInstance() {
101 return INSTANCE;
102 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800103
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800104 /**
Ben Gilad8bdaa462014-02-05 12:53:19 -0800105 * Initializes the required Telecomm components.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800106 */
107 private CallsManager() {
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700108 TelecommApp app = TelecommApp.getInstance();
Santos Cordona56f2762014-03-24 15:55:53 -0700109
Santos Cordondeb8c892014-05-30 01:38:03 -0700110 StatusBarNotifier statusBarNotifier = new StatusBarNotifier(app, this);
111 mCallAudioManager = new CallAudioManager(app, statusBarNotifier);
Santos Cordonc7b8eba2014-04-01 15:26:28 -0700112 InCallTonePlayer.Factory playerFactory = new InCallTonePlayer.Factory(mCallAudioManager);
Santos Cordonae193062014-05-21 21:21:49 -0700113 mRinger = new Ringer(mCallAudioManager, this, playerFactory, app);
Santos Cordondeb8c892014-05-30 01:38:03 -0700114 mHeadsetMediaButton = new HeadsetMediaButton(app, this);
Santos Cordonae193062014-05-21 21:21:49 -0700115
Santos Cordondeb8c892014-05-30 01:38:03 -0700116 mListeners.add(statusBarNotifier);
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700117 mListeners.add(new CallLogManager(app));
Santos Cordona56f2762014-03-24 15:55:53 -0700118 mListeners.add(new PhoneStateBroadcaster());
Santos Cordonf3671a62014-05-29 21:51:53 -0700119 mListeners.add(mInCallController);
Santos Cordonae193062014-05-21 21:21:49 -0700120 mListeners.add(mRinger);
Santos Cordonc7b8eba2014-04-01 15:26:28 -0700121 mListeners.add(new RingbackPlayer(this, playerFactory));
122 mListeners.add(new InCallToneMonitor(playerFactory, this));
Santos Cordona56f2762014-03-24 15:55:53 -0700123 mListeners.add(mCallAudioManager);
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700124 mListeners.add(app.getMissedCallNotifier());
Santos Cordon92a2d812014-04-30 15:19:01 -0700125 mListeners.add(mDtmfLocalTonePlayer);
Santos Cordon81289982014-06-03 16:03:08 -0700126 mListeners.add(mHeadsetMediaButton);
Ihab Awadff7493a2014-06-10 13:47:44 -0700127 mListeners.add(RespondViaSmsManager.getInstance());
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800128 }
129
Santos Cordon766d04f2014-05-06 10:28:25 -0700130 @Override
131 public void onSuccessfulOutgoingCall(Call call) {
132 Log.v(this, "onSuccessfulOutgoingCall, %s", call);
133 if (mCalls.contains(call)) {
134 // The call's CallService has been updated.
135 for (CallsManagerListener listener : mListeners) {
136 listener.onCallServiceChanged(call, null, call.getCallService());
137 }
138 } else if (mPendingHandoffCalls.contains(call)) {
139 updateHandoffCallServiceDescriptor(call.getOriginalCall(),
140 call.getCallService().getDescriptor());
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700141 } else {
142 Log.wtf(this, "unexpected successful call notification: %s", call);
143 return;
Santos Cordon766d04f2014-05-06 10:28:25 -0700144 }
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700145
146 markCallAsDialing(call);
Santos Cordon766d04f2014-05-06 10:28:25 -0700147 }
148
149 @Override
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700150 public void onFailedOutgoingCall(Call call, int errorCode, String errorMsg) {
151 Log.v(this, "onFailedOutgoingCall, call: %s", call);
152 // TODO: Replace disconnect cause with more specific disconnect causes.
153 markCallAsDisconnected(call, errorCode, errorMsg);
154 }
155
156 @Override
157 public void onCancelledOutgoingCall(Call call) {
158 Log.v(this, "onCancelledOutgoingCall, call: %s", call);
159 setCallState(call, CallState.ABORTED);
160 removeCall(call);
Santos Cordon766d04f2014-05-06 10:28:25 -0700161 }
162
163 @Override
164 public void onSuccessfulIncomingCall(Call call, CallInfo callInfo) {
165 Log.d(this, "onSuccessfulIncomingCall");
166 setCallState(call, callInfo.getState());
167 addCall(call);
168 }
169
170 @Override
171 public void onFailedIncomingCall(Call call) {
172 call.removeListener(this);
Ben Gilada0d9f752014-02-26 11:49:03 -0800173 }
174
Ihab Awadcb387ac2014-05-28 16:49:38 -0700175 @Override
Santos Cordona1610702014-06-04 20:22:56 -0700176 public void onIsConferenceCapableChanged(Call call, boolean isConferenceCapable) {
177 for (CallsManagerListener listener : mListeners) {
178 listener.onIsConferenceCapableChanged(call, isConferenceCapable);
179 }
180 }
181
182 @Override
Ihab Awadcb387ac2014-05-28 16:49:38 -0700183 public void onRequestingRingback(Call call, boolean ringback) {
184 for (CallsManagerListener listener : mListeners) {
185 listener.onRequestingRingback(call, ringback);
186 }
187 }
188
Evan Charlton352105c2014-06-03 14:10:54 -0700189 @Override
190 public void onPostDialWait(Call call, String remaining) {
191 mInCallController.onPostDialWait(call, remaining);
192 }
193
Santos Cordona1610702014-06-04 20:22:56 -0700194 @Override
195 public void onExpiredConferenceCall(Call call) {
196 call.removeListener(this);
197 }
198
199 @Override
200 public void onConfirmedConferenceCall(Call call) {
201 addCall(call);
202 Log.v(this, "confirming Conf call %s", call);
203 for (CallsManagerListener listener : mListeners) {
204 listener.onIsConferencedChanged(call);
205 }
206 }
207
208 @Override
209 public void onParentChanged(Call call) {
210 for (CallsManagerListener listener : mListeners) {
211 listener.onIsConferencedChanged(call);
212 }
213 }
214
215 @Override
216 public void onChildrenChanged(Call call) {
217 for (CallsManagerListener listener : mListeners) {
218 listener.onIsConferencedChanged(call);
219 }
220 }
221
Ihab Awadff7493a2014-06-10 13:47:44 -0700222 @Override
223 public void onCannedSmsResponsesLoaded(Call call) {
224 for (CallsManagerListener listener : mListeners) {
225 listener.onCannedSmsResponsesLoaded(call);
226 }
227 }
228
Nancy Chena65d41f2014-06-24 12:06:03 -0700229 @Override
230 public void onCallVideoProviderChanged(Call call) {
231 for (CallsManagerListener listener : mListeners) {
232 listener.onCallVideoProviderChanged(call);
233 }
234 }
235
Sailesh Nepal810735e2014-03-18 18:15:46 -0700236 ImmutableCollection<Call> getCalls() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700237 return ImmutableList.copyOf(mCalls);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700238 }
239
240 Call getForegroundCall() {
241 return mForegroundCall;
242 }
243
Santos Cordonae193062014-05-21 21:21:49 -0700244 Ringer getRinger() {
245 return mRinger;
246 }
247
Santos Cordonf3671a62014-05-29 21:51:53 -0700248 InCallController getInCallController() {
249 return mInCallController;
250 }
251
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700252 boolean hasEmergencyCall() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700253 for (Call call : mCalls) {
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700254 if (call.isEmergencyCall()) {
255 return true;
256 }
257 }
258 return false;
259 }
260
261 CallAudioState getAudioState() {
262 return mCallAudioManager.getAudioState();
263 }
264
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800265 /**
Santos Cordon493e8f22014-02-19 03:15:12 -0800266 * Starts the incoming call sequence by having switchboard gather more information about the
267 * specified call; using the specified call service descriptor. Upon success, execution returns
Santos Cordon766d04f2014-05-06 10:28:25 -0700268 * to {@link #onSuccessfulIncomingCall} to start the in-call UI.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800269 *
Ben Giladc5b22692014-02-18 20:03:22 -0800270 * @param descriptor The descriptor of the call service to use for this incoming call.
Evan Charltona05805b2014-03-05 08:21:46 -0800271 * @param extras The optional extras Bundle passed with the intent used for the incoming call.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800272 */
Evan Charltona05805b2014-03-05 08:21:46 -0800273 void processIncomingCallIntent(CallServiceDescriptor descriptor, Bundle extras) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800274 Log.d(this, "processIncomingCallIntent");
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800275 // Create a call with no handle. Eventually, switchboard will update the call with
Sailesh Nepale59bb192014-04-01 18:33:59 -0700276 // additional information from the call service, but for now we just need one to pass
277 // around.
Santos Cordona1610702014-06-04 20:22:56 -0700278 Call call = new Call(true /* isIncoming */, false /* isConference */);
Santos Cordon766d04f2014-05-06 10:28:25 -0700279 // TODO(santoscordon): Move this to be a part of addCall()
280 call.addListener(this);
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800281
Santos Cordon766d04f2014-05-06 10:28:25 -0700282 call.startIncoming(descriptor, extras);
Ben Gilada0d9f752014-02-26 11:49:03 -0800283 }
284
285 /**
Yorke Lee33501632014-03-17 19:24:12 -0700286 * Attempts to issue/connect the specified call.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800287 *
Yorke Lee33501632014-03-17 19:24:12 -0700288 * @param handle Handle to connect the call with.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800289 * @param contactInfo Information about the entity being called.
Yorke Lee33501632014-03-17 19:24:12 -0700290 * @param gatewayInfo Optional gateway information that can be used to route the call to the
Santos Cordon5b7b9b32014-03-26 14:00:22 -0700291 * actual dialed handle via a gateway provider. May be null.
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700292 * @param speakerphoneOn Whether or not to turn the speakerphone on once the call connects.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800293 */
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700294 void placeOutgoingCall(Uri handle, ContactInfo contactInfo, GatewayInfo gatewayInfo,
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700295 Subscription subscription, boolean speakerphoneOn) {
Yorke Lee33501632014-03-17 19:24:12 -0700296 final Uri uriHandle = (gatewayInfo == null) ? handle : gatewayInfo.getGatewayHandle();
297
298 if (gatewayInfo == null) {
Santos Cordonb58f4532014-05-29 11:59:06 -0700299 Log.i(this, "Creating a new outgoing call with handle: %s", Log.piiHandle(uriHandle));
Yorke Lee33501632014-03-17 19:24:12 -0700300 } else {
301 Log.i(this, "Creating a new outgoing call with gateway handle: %s, original handle: %s",
302 Log.pii(uriHandle), Log.pii(handle));
303 }
Santos Cordon766d04f2014-05-06 10:28:25 -0700304
Santos Cordona1610702014-06-04 20:22:56 -0700305 Call call = new Call(
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700306 uriHandle, gatewayInfo, subscription,
307 false /* isIncoming */, false /* isConference */);
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700308 call.setStartWithSpeakerphoneOn(speakerphoneOn);
Santos Cordon766d04f2014-05-06 10:28:25 -0700309
310 // TODO(santoscordon): Move this to be a part of addCall()
311 call.addListener(this);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700312 addCall(call);
Santos Cordone3d76ab2014-01-28 17:25:20 -0800313
Santos Cordon766d04f2014-05-06 10:28:25 -0700314 call.startOutgoing();
Yorke Leef98fb572014-03-05 10:56:55 -0800315 }
316
317 /**
Santos Cordona1610702014-06-04 20:22:56 -0700318 * Attempts to start a conference call for the specified call.
319 *
320 * @param call The call to conference with.
321 */
322 void conference(Call call) {
323 Call conferenceCall = new Call(false, true);
324 conferenceCall.addListener(this);
325 call.conferenceInto(conferenceCall);
326 }
327
328 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800329 * Instructs Telecomm to answer the specified call. Intended to be invoked by the in-call
330 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
331 * the user opting to answer said call.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800332 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700333 void answerCall(Call call) {
334 if (!mCalls.contains(call)) {
335 Log.i(this, "Request to answer a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800336 } else {
Santos Cordon40f78c22014-04-07 02:11:42 -0700337 // If the foreground call is not the ringing call and it is currently isActive() or
338 // DIALING, put it on hold before answering the call.
339 if (mForegroundCall != null && mForegroundCall != call &&
340 (mForegroundCall.isActive() ||
341 mForegroundCall.getState() == CallState.DIALING)) {
342 Log.v(this, "Holding active/dialing call %s before answering incoming call %s.",
343 mForegroundCall, call);
344 mForegroundCall.hold();
345 // TODO(santoscordon): Wait until we get confirmation of the active call being
346 // on-hold before answering the new call.
347 // TODO(santoscordon): Import logic from CallManager.acceptCall()
348 }
349
Santos Cordona56f2762014-03-24 15:55:53 -0700350 for (CallsManagerListener listener : mListeners) {
351 listener.onIncomingCallAnswered(call);
352 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800353
Santos Cordon61d0f702014-02-19 02:52:23 -0800354 // We do not update the UI until we get confirmation of the answer() through
Sailesh Nepale59bb192014-04-01 18:33:59 -0700355 // {@link #markCallAsActive}.
Santos Cordon61d0f702014-02-19 02:52:23 -0800356 call.answer();
357 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800358 }
359
360 /**
361 * Instructs Telecomm to reject the specified call. Intended to be invoked by the in-call
362 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
363 * the user opting to reject said call.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800364 */
Ihab Awadff7493a2014-06-10 13:47:44 -0700365 void rejectCall(Call call, boolean rejectWithMessage, String textMessage) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700366 if (!mCalls.contains(call)) {
367 Log.i(this, "Request to reject a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800368 } else {
Santos Cordona56f2762014-03-24 15:55:53 -0700369 for (CallsManagerListener listener : mListeners) {
Ihab Awadff7493a2014-06-10 13:47:44 -0700370 listener.onIncomingCallRejected(call, rejectWithMessage, textMessage);
Santos Cordona56f2762014-03-24 15:55:53 -0700371 }
Ihab Awadff7493a2014-06-10 13:47:44 -0700372 call.reject(rejectWithMessage, textMessage);
Santos Cordon61d0f702014-02-19 02:52:23 -0800373 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800374 }
375
376 /**
Ihab Awad74549ec2014-03-10 15:33:25 -0700377 * Instructs Telecomm to play the specified DTMF tone within the specified call.
378 *
Ihab Awad74549ec2014-03-10 15:33:25 -0700379 * @param digit The DTMF digit to play.
380 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700381 void playDtmfTone(Call call, char digit) {
382 if (!mCalls.contains(call)) {
383 Log.i(this, "Request to play DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700384 } else {
385 call.playDtmfTone(digit);
Santos Cordon92a2d812014-04-30 15:19:01 -0700386 mDtmfLocalTonePlayer.playTone(call, digit);
Ihab Awad74549ec2014-03-10 15:33:25 -0700387 }
388 }
389
390 /**
391 * Instructs Telecomm to stop the currently playing DTMF tone, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -0700392 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700393 void stopDtmfTone(Call call) {
394 if (!mCalls.contains(call)) {
395 Log.i(this, "Request to stop DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700396 } else {
397 call.stopDtmfTone();
Santos Cordon92a2d812014-04-30 15:19:01 -0700398 mDtmfLocalTonePlayer.stopTone(call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700399 }
400 }
401
402 /**
Evan Charlton352105c2014-06-03 14:10:54 -0700403 * Instructs Telecomm to continue (or not) the current post-dial DTMF string, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -0700404 */
Evan Charlton352105c2014-06-03 14:10:54 -0700405 void postDialContinue(Call call, boolean proceed) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700406 if (!mCalls.contains(call)) {
407 Log.i(this, "Request to continue post-dial string in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700408 } else {
Evan Charlton352105c2014-06-03 14:10:54 -0700409 call.postDialContinue(proceed);
Ihab Awad74549ec2014-03-10 15:33:25 -0700410 }
411 }
412
413 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800414 * Instructs Telecomm to disconnect the specified call. Intended to be invoked by the
415 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
416 * the user hitting the end-call button.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800417 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700418 void disconnectCall(Call call) {
Santos Cordon682fe6b2014-05-20 08:56:39 -0700419 Log.v(this, "disconnectCall %s", call);
420
Sailesh Nepale59bb192014-04-01 18:33:59 -0700421 if (!mCalls.contains(call)) {
422 Log.w(this, "Unknown call (%s) asked to disconnect", call);
Santos Cordon049b7b62014-01-30 05:34:26 -0800423 } else {
424 call.disconnect();
425 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800426 }
Santos Cordon681663d2014-01-30 04:32:15 -0800427
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700428 /**
429 * Instructs Telecomm to put the specified call on hold. Intended to be invoked by the
430 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
431 * the user hitting the hold button during an active call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700432 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700433 void holdCall(Call call) {
434 if (!mCalls.contains(call)) {
435 Log.w(this, "Unknown call (%s) asked to be put on hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700436 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700437 Log.d(this, "Putting call on hold: (%s)", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700438 call.hold();
439 }
440 }
441
442 /**
443 * Instructs Telecomm to release the specified call from hold. Intended to be invoked by
444 * the in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered
445 * by the user hitting the hold button during a held call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700446 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700447 void unholdCall(Call call) {
448 if (!mCalls.contains(call)) {
449 Log.w(this, "Unknown call (%s) asked to be removed from hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700450 } else {
Santos Cordonc7e85d42014-05-22 02:51:48 -0700451 Log.d(this, "unholding call: (%s)", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700452 call.unhold();
453 }
454 }
455
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700456 /** Called by the in-call UI to change the mute state. */
457 void mute(boolean shouldMute) {
458 mCallAudioManager.mute(shouldMute);
459 }
460
461 /**
462 * Called by the in-call UI to change the audio route, for example to change from earpiece to
463 * speaker phone.
464 */
465 void setAudioRoute(int route) {
466 mCallAudioManager.setAudioRoute(route);
467 }
468
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700469 void startHandoffForCall(Call originalCall) {
470 if (!mCalls.contains(originalCall)) {
471 Log.w(this, "Unknown call %s asked to be handed off", originalCall);
472 return;
473 }
474
475 for (Call handoffCall : mPendingHandoffCalls) {
476 if (handoffCall.getOriginalCall() == originalCall) {
477 Log.w(this, "Call %s is already being handed off, skipping", originalCall);
478 return;
479 }
480 }
481
482 // Create a new call to be placed in the background. If handoff is successful then the
483 // original call will live on but its state will be updated to the new call's state. In
484 // particular the original call's call service will be updated to the new call's call
485 // service.
Santos Cordona1610702014-06-04 20:22:56 -0700486 Call tempCall = new Call(
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700487 originalCall.getHandoffHandle(), originalCall.getGatewayInfo(),
488 originalCall.getSubscription(), false, false);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700489 tempCall.setOriginalCall(originalCall);
490 tempCall.setExtras(originalCall.getExtras());
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700491 mPendingHandoffCalls.add(tempCall);
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700492 tempCall.addListener(this);
493
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700494 Log.d(this, "Placing handoff call");
Santos Cordon766d04f2014-05-06 10:28:25 -0700495 tempCall.startOutgoing();
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700496 }
497
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700498 /** Called when the audio state changes. */
499 void onAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState) {
500 Log.v(this, "onAudioStateChanged, audioState: %s -> %s", oldAudioState, newAudioState);
Santos Cordona56f2762014-03-24 15:55:53 -0700501 for (CallsManagerListener listener : mListeners) {
502 listener.onAudioStateChanged(oldAudioState, newAudioState);
503 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700504 }
505
Sailesh Nepale59bb192014-04-01 18:33:59 -0700506 void markCallAsRinging(Call call) {
507 setCallState(call, CallState.RINGING);
Santos Cordon681663d2014-01-30 04:32:15 -0800508 }
509
Sailesh Nepale59bb192014-04-01 18:33:59 -0700510 void markCallAsDialing(Call call) {
511 setCallState(call, CallState.DIALING);
Santos Cordon681663d2014-01-30 04:32:15 -0800512 }
513
Sailesh Nepale59bb192014-04-01 18:33:59 -0700514 void markCallAsActive(Call call) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700515 if (call.getConnectTimeMillis() == 0) {
516 call.setConnectTimeMillis(System.currentTimeMillis());
517 }
Sailesh Nepale59bb192014-04-01 18:33:59 -0700518 setCallState(call, CallState.ACTIVE);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700519
520 if (mPendingHandoffCalls.contains(call)) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700521 completeHandoff(call, true);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700522 }
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700523 if (call.getStartWithSpeakerphoneOn()) {
524 setAudioRoute(CallAudioState.ROUTE_SPEAKER);
525 }
Santos Cordon681663d2014-01-30 04:32:15 -0800526 }
527
Sailesh Nepale59bb192014-04-01 18:33:59 -0700528 void markCallAsOnHold(Call call) {
529 setCallState(call, CallState.ON_HOLD);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700530 }
531
Santos Cordon049b7b62014-01-30 05:34:26 -0800532 /**
533 * Marks the specified call as DISCONNECTED and notifies the in-call app. If this was the last
534 * live call, then also disconnect from the in-call controller.
535 *
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700536 * @param disconnectCause The disconnect reason, see {@link android.telephony.DisconnectCause}.
537 * @param disconnectMessage Optional call-service-provided message about the disconnect.
Santos Cordon049b7b62014-01-30 05:34:26 -0800538 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700539 void markCallAsDisconnected(Call call, int disconnectCause, String disconnectMessage) {
540 call.setDisconnectCause(disconnectCause, disconnectMessage);
541 setCallState(call, CallState.DISCONNECTED);
Sailesh Nepal4857f472014-04-07 22:26:27 -0700542
543 // Only remove the call if handoff is not pending.
544 if (call.getHandoffCallServiceDescriptor() == null) {
545 removeCall(call);
546 }
Ben Gilada0d9f752014-02-26 11:49:03 -0800547 }
548
Sailesh Nepal6ab6fb72014-04-01 20:03:19 -0700549 void setHandoffInfo(Call call, Uri handle, Bundle extras) {
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700550 if (!mCalls.contains(call)) {
551 Log.w(this, "Unknown call (%s) asked to set handoff info", call);
552 return;
553 }
554
555 if (extras == null) {
556 call.setExtras(Bundle.EMPTY);
557 } else {
558 call.setExtras(extras);
559 }
560
561 Uri oldHandle = call.getHandoffHandle();
562 Log.v(this, "set handoff handle %s -> %s, for call: %s", oldHandle, handle, call);
563 if (!areUriEqual(oldHandle, handle)) {
564 call.setHandoffHandle(handle);
565 for (CallsManagerListener listener : mListeners) {
566 listener.onCallHandoffHandleChanged(call, oldHandle, handle);
567 }
568 }
Sailesh Nepal6ab6fb72014-04-01 20:03:19 -0700569 }
570
Ben Gilada0d9f752014-02-26 11:49:03 -0800571 /**
Santos Cordon4b2c1192014-03-19 18:15:38 -0700572 * Cleans up any calls currently associated with the specified call service when the
573 * call-service binder disconnects unexpectedly.
574 *
575 * @param callService The call service that disconnected.
576 */
577 void handleCallServiceDeath(CallServiceWrapper callService) {
578 Preconditions.checkNotNull(callService);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700579 for (Call call : ImmutableList.copyOf(mCalls)) {
Santos Cordon4b2c1192014-03-19 18:15:38 -0700580 if (call.getCallService() == callService) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700581 markCallAsDisconnected(call, DisconnectCause.ERROR_UNSPECIFIED, null);
Santos Cordon4b2c1192014-03-19 18:15:38 -0700582 }
583 }
584 }
585
Santos Cordondeb8c892014-05-30 01:38:03 -0700586 boolean hasAnyCalls() {
587 return !mCalls.isEmpty();
588 }
589
Santos Cordonc7e85d42014-05-22 02:51:48 -0700590 boolean hasActiveOrHoldingCall() {
591 for (Call call : mCalls) {
592 CallState state = call.getState();
593 if (state == CallState.ACTIVE || state == CallState.ON_HOLD) {
594 return true;
595 }
596 }
597 return false;
598 }
599
600 boolean hasRingingCall() {
601 for (Call call : mCalls) {
602 if (call.getState() == CallState.RINGING) {
603 return true;
604 }
605 }
606 return false;
607 }
608
Santos Cordondeb8c892014-05-30 01:38:03 -0700609 boolean onMediaButton(int type) {
610 if (hasAnyCalls()) {
611 if (HeadsetMediaButton.SHORT_PRESS == type) {
612 Call ringingCall = getFirstCallWithState(CallState.RINGING);
613 if (ringingCall == null) {
614 mCallAudioManager.toggleMute();
615 return true;
616 } else {
617 ringingCall.answer();
618 return true;
619 }
620 } else if (HeadsetMediaButton.LONG_PRESS == type) {
621 Log.d(this, "handleHeadsetHook: longpress -> hangup");
622 Call callToHangup = getFirstCallWithState(
623 CallState.RINGING, CallState.DIALING, CallState.ACTIVE, CallState.ON_HOLD);
624 if (callToHangup != null) {
625 callToHangup.disconnect();
626 return true;
627 }
628 }
629 }
630 return false;
631 }
632
633 /**
Santos Cordon10838c22014-06-11 17:36:04 -0700634 * Checks to see if the specified call is the only high-level call and if so, enable the
635 * "Add-call" button. We allow you to add a second call but not a third or beyond.
636 *
637 * @param call The call to test for add-call.
638 * @return Whether the add-call feature should be enabled for the call.
639 */
640 protected boolean isAddCallCapable(Call call) {
641 if (call.getParentCall() != null) {
642 // Never true for child calls.
643 return false;
644 }
645
646 // Loop through all the other calls and there exists a top level (has no parent) call
647 // that is not the specified call, return false.
648 for (Call otherCall : mCalls) {
649 if (call != otherCall && otherCall.getParentCall() == null) {
650 return false;
651 }
652 }
653 return true;
654 }
655
656 /**
Santos Cordondeb8c892014-05-30 01:38:03 -0700657 * Returns the first call that it finds with the given states. The states are treated as having
658 * priority order so that any call with the first state will be returned before any call with
659 * states listed later in the parameter list.
660 */
661 private Call getFirstCallWithState(CallState... states) {
662 for (CallState currentState : states) {
663 for (Call call : mCalls) {
664 if (currentState == call.getState()) {
665 return call;
666 }
667 }
668 }
669 return null;
670 }
671
Santos Cordon4b2c1192014-03-19 18:15:38 -0700672 /**
Ben Gilada0d9f752014-02-26 11:49:03 -0800673 * Adds the specified call to the main list of live calls.
674 *
675 * @param call The call to add.
676 */
677 private void addCall(Call call) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700678 mCalls.add(call);
Santos Cordon40f78c22014-04-07 02:11:42 -0700679
680 // TODO(santoscordon): Update mForegroundCall prior to invoking
681 // onCallAdded for calls which immediately take the foreground (like the first call).
Santos Cordona56f2762014-03-24 15:55:53 -0700682 for (CallsManagerListener listener : mListeners) {
683 listener.onCallAdded(call);
684 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700685 updateForegroundCall();
Ben Gilada0d9f752014-02-26 11:49:03 -0800686 }
687
Sailesh Nepal810735e2014-03-18 18:15:46 -0700688 private void removeCall(Call call) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700689 // If a handoff is pending then the original call shouldn't be removed.
690 Preconditions.checkState(call.getHandoffCallServiceDescriptor() == null);
Santos Cordonc499c1c2014-04-14 17:13:14 -0700691 Log.v(this, "removeCall(%s)", call);
Sailesh Nepal4857f472014-04-07 22:26:27 -0700692
Santos Cordon766d04f2014-05-06 10:28:25 -0700693 call.removeListener(this);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700694 call.clearCallService();
Sailesh Nepale59bb192014-04-01 18:33:59 -0700695
696 boolean shouldNotify = false;
697 if (mCalls.contains(call)) {
698 mCalls.remove(call);
699 shouldNotify = true;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700700 } else if (mPendingHandoffCalls.contains(call)) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700701 Log.v(this, "removeCall, marking handoff call as failed");
702 completeHandoff(call, false);
Santos Cordona56f2762014-03-24 15:55:53 -0700703 }
Ben Gilada0d9f752014-02-26 11:49:03 -0800704
Sailesh Nepale59bb192014-04-01 18:33:59 -0700705 // Only broadcast changes for calls that are being tracked.
706 if (shouldNotify) {
707 for (CallsManagerListener listener : mListeners) {
708 listener.onCallRemoved(call);
709 }
710 updateForegroundCall();
Sailesh Nepal810735e2014-03-18 18:15:46 -0700711 }
712 }
Evan Charlton5c670a92014-03-06 14:58:20 -0800713
Sailesh Nepal810735e2014-03-18 18:15:46 -0700714 /**
Santos Cordon1ae2b852014-03-19 03:03:10 -0700715 * Sets the specified state on the specified call.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700716 *
717 * @param call The call.
718 * @param newState The new state of the call.
719 */
720 private void setCallState(Call call, CallState newState) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700721 Preconditions.checkNotNull(newState);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700722 CallState oldState = call.getState();
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700723 Log.i(this, "setCallState %s -> %s, call: %s", oldState, newState, call);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700724 if (newState != oldState) {
725 // Unfortunately, in the telephony world the radio is king. So if the call notifies
726 // us that the call is in a particular state, we allow it even if it doesn't make
727 // sense (e.g., ACTIVE -> RINGING).
728 // TODO(santoscordon): Consider putting a stop to the above and turning CallState
729 // into a well-defined state machine.
730 // TODO(santoscordon): Define expected state transitions here, and log when an
731 // unexpected transition occurs.
732 call.setState(newState);
733
734 // Only broadcast state change for calls that are being tracked.
Sailesh Nepale59bb192014-04-01 18:33:59 -0700735 if (mCalls.contains(call)) {
Santos Cordona56f2762014-03-24 15:55:53 -0700736 for (CallsManagerListener listener : mListeners) {
737 listener.onCallStateChanged(call, oldState, newState);
738 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700739 updateForegroundCall();
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800740 }
741 }
742 }
743
744 /**
Sailesh Nepal810735e2014-03-18 18:15:46 -0700745 * Checks which call should be visible to the user and have audio focus.
Evan Charlton5c670a92014-03-06 14:58:20 -0800746 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700747 private void updateForegroundCall() {
748 Call newForegroundCall = null;
Sailesh Nepale59bb192014-04-01 18:33:59 -0700749 for (Call call : mCalls) {
Santos Cordon40f78c22014-04-07 02:11:42 -0700750 // TODO(santoscordon): Foreground-ness needs to be explicitly set. No call, regardless
751 // of its state will be foreground by default and instead the call service should be
752 // notified when its calls enter and exit foreground state. Foreground will mean that
753 // the call should play audio and listen to microphone if it wants.
754
755 // Active calls have priority.
756 if (call.isActive()) {
Sailesh Nepal810735e2014-03-18 18:15:46 -0700757 newForegroundCall = call;
Evan Charlton5c670a92014-03-06 14:58:20 -0800758 break;
Sailesh Nepal810735e2014-03-18 18:15:46 -0700759 }
Santos Cordon40f78c22014-04-07 02:11:42 -0700760
761 if (call.isAlive() || call.getState() == CallState.RINGING) {
Sailesh Nepal810735e2014-03-18 18:15:46 -0700762 newForegroundCall = call;
Santos Cordon40f78c22014-04-07 02:11:42 -0700763 // Don't break in case there's an active call that has priority.
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800764 }
765 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800766
Sailesh Nepal810735e2014-03-18 18:15:46 -0700767 if (newForegroundCall != mForegroundCall) {
Santos Cordon40f78c22014-04-07 02:11:42 -0700768 Log.v(this, "Updating foreground call, %s -> %s.", mForegroundCall, newForegroundCall);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700769 Call oldForegroundCall = mForegroundCall;
770 mForegroundCall = newForegroundCall;
771
Santos Cordona56f2762014-03-24 15:55:53 -0700772 for (CallsManagerListener listener : mListeners) {
773 listener.onForegroundCallChanged(oldForegroundCall, mForegroundCall);
774 }
Santos Cordon681663d2014-01-30 04:32:15 -0800775 }
776 }
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700777
Sailesh Nepal4857f472014-04-07 22:26:27 -0700778 private void completeHandoff(Call handoffCall, boolean wasSuccessful) {
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700779 Call originalCall = handoffCall.getOriginalCall();
Sailesh Nepal4857f472014-04-07 22:26:27 -0700780 Log.v(this, "complete handoff, %s -> %s, wasSuccessful: %b", handoffCall, originalCall,
781 wasSuccessful);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700782
Sailesh Nepal4857f472014-04-07 22:26:27 -0700783 // Remove the transient handoff call object (don't disconnect because the call could still
784 // be live).
785 mPendingHandoffCalls.remove(handoffCall);
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700786 handoffCall.removeListener(this);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700787
Sailesh Nepal4857f472014-04-07 22:26:27 -0700788 if (wasSuccessful) {
Sailesh Nepaldcd64262014-05-23 17:03:28 -0700789 if (TelephonyUtil.isCurrentlyPSTNCall(originalCall)) {
790 originalCall.disconnect();
791 }
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700792
Sailesh Nepal4857f472014-04-07 22:26:27 -0700793 // Synchronize.
794 originalCall.setCallService(handoffCall.getCallService(), handoffCall);
795 setCallState(originalCall, handoffCall.getState());
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700796
Sailesh Nepal4857f472014-04-07 22:26:27 -0700797 // Force the foreground call changed notification to be sent.
798 for (CallsManagerListener listener : mListeners) {
799 listener.onForegroundCallChanged(mForegroundCall, mForegroundCall);
800 }
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700801
Sailesh Nepal4857f472014-04-07 22:26:27 -0700802 updateHandoffCallServiceDescriptor(originalCall, null);
803 } else {
804 updateHandoffCallServiceDescriptor(originalCall, null);
805 if (originalCall.getState() == CallState.DISCONNECTED ||
806 originalCall.getState() == CallState.ABORTED) {
807 removeCall(originalCall);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700808 }
809 }
810 }
811
Sailesh Nepal4857f472014-04-07 22:26:27 -0700812 private void updateHandoffCallServiceDescriptor(
813 Call originalCall,
814 CallServiceDescriptor newDescriptor) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700815 CallServiceDescriptor oldDescriptor = originalCall.getHandoffCallServiceDescriptor();
Sailesh Nepal4857f472014-04-07 22:26:27 -0700816 Log.v(this, "updateHandoffCallServiceDescriptor, call: %s, pending descriptor: %s -> %s",
817 originalCall, oldDescriptor, newDescriptor);
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700818
819 if (!areDescriptorsEqual(oldDescriptor, newDescriptor)) {
820 originalCall.setHandoffCallServiceDescriptor(newDescriptor);
821 for (CallsManagerListener listener : mListeners) {
822 listener.onCallHandoffCallServiceDescriptorChanged(originalCall, oldDescriptor,
823 newDescriptor);
824 }
825 }
826 }
827
828 private static boolean areDescriptorsEqual(
829 CallServiceDescriptor descriptor1,
830 CallServiceDescriptor descriptor2) {
831 if (descriptor1 == null) {
832 return descriptor2 == null;
833 }
834 return descriptor1.equals(descriptor2);
835 }
836
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700837 private static boolean areUriEqual(Uri handle1, Uri handle2) {
838 if (handle1 == null) {
839 return handle2 == null;
840 }
841 return handle1.equals(handle2);
842 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800843}