blob: 85593ef4ee59c4e4fb4bbb831b20b34d89aa6d73 [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);
Tyler Gunne19cc002014-07-01 11:32:53 -070069 void onFeaturesChanged(Call call);
Sailesh Nepal810735e2014-03-18 18:15:46 -070070 }
71
Santos Cordon8e8b8d22013-12-19 14:14:05 -080072 private static final CallsManager INSTANCE = new CallsManager();
Ben Gilad9f2bed32013-12-12 17:43:26 -080073
Santos Cordon8e8b8d22013-12-19 14:14:05 -080074 /**
Sailesh Nepale59bb192014-04-01 18:33:59 -070075 * The main call repository. Keeps an instance of all live calls. New incoming and outgoing
76 * calls are added to the map and removed when the calls move to the disconnected state.
Santos Cordon681663d2014-01-30 04:32:15 -080077 */
Santos Cordonf3671a62014-05-29 21:51:53 -070078 private final Set<Call> mCalls = new LinkedHashSet<>();
Santos Cordon681663d2014-01-30 04:32:15 -080079
80 /**
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070081 * Set of new calls created to perform a handoff. The calls are added when handoff is initiated
82 * and removed when hadnoff is complete.
83 */
Santos Cordonf3671a62014-05-29 21:51:53 -070084 private final Set<Call> mPendingHandoffCalls = new LinkedHashSet<>();
85
86
87 private final DtmfLocalTonePlayer mDtmfLocalTonePlayer = new DtmfLocalTonePlayer();
88 private final InCallController mInCallController = new InCallController();
89 private final CallAudioManager mCallAudioManager;
90 private final Ringer mRinger;
91 private final Set<CallsManagerListener> mListeners = new HashSet<>();
Santos Cordondeb8c892014-05-30 01:38:03 -070092 private final HeadsetMediaButton mHeadsetMediaButton;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070093
94 /**
Sailesh Nepal810735e2014-03-18 18:15:46 -070095 * The call the user is currently interacting with. This is the call that should have audio
96 * focus and be visible in the in-call UI.
Santos Cordon4e9fffe2014-03-04 18:13:41 -080097 */
Sailesh Nepal810735e2014-03-18 18:15:46 -070098 private Call mForegroundCall;
Santos Cordon4e9fffe2014-03-04 18:13:41 -080099
Santos Cordon766d04f2014-05-06 10:28:25 -0700100 /** Singleton accessor. */
101 static CallsManager getInstance() {
102 return INSTANCE;
103 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800104
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800105 /**
Ben Gilad8bdaa462014-02-05 12:53:19 -0800106 * Initializes the required Telecomm components.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800107 */
108 private CallsManager() {
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700109 TelecommApp app = TelecommApp.getInstance();
Santos Cordona56f2762014-03-24 15:55:53 -0700110
Santos Cordondeb8c892014-05-30 01:38:03 -0700111 StatusBarNotifier statusBarNotifier = new StatusBarNotifier(app, this);
112 mCallAudioManager = new CallAudioManager(app, statusBarNotifier);
Santos Cordonc7b8eba2014-04-01 15:26:28 -0700113 InCallTonePlayer.Factory playerFactory = new InCallTonePlayer.Factory(mCallAudioManager);
Santos Cordonae193062014-05-21 21:21:49 -0700114 mRinger = new Ringer(mCallAudioManager, this, playerFactory, app);
Santos Cordondeb8c892014-05-30 01:38:03 -0700115 mHeadsetMediaButton = new HeadsetMediaButton(app, this);
Santos Cordonae193062014-05-21 21:21:49 -0700116
Santos Cordondeb8c892014-05-30 01:38:03 -0700117 mListeners.add(statusBarNotifier);
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700118 mListeners.add(new CallLogManager(app));
Santos Cordona56f2762014-03-24 15:55:53 -0700119 mListeners.add(new PhoneStateBroadcaster());
Santos Cordonf3671a62014-05-29 21:51:53 -0700120 mListeners.add(mInCallController);
Santos Cordonae193062014-05-21 21:21:49 -0700121 mListeners.add(mRinger);
Santos Cordonc7b8eba2014-04-01 15:26:28 -0700122 mListeners.add(new RingbackPlayer(this, playerFactory));
123 mListeners.add(new InCallToneMonitor(playerFactory, this));
Santos Cordona56f2762014-03-24 15:55:53 -0700124 mListeners.add(mCallAudioManager);
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700125 mListeners.add(app.getMissedCallNotifier());
Santos Cordon92a2d812014-04-30 15:19:01 -0700126 mListeners.add(mDtmfLocalTonePlayer);
Santos Cordon81289982014-06-03 16:03:08 -0700127 mListeners.add(mHeadsetMediaButton);
Ihab Awadff7493a2014-06-10 13:47:44 -0700128 mListeners.add(RespondViaSmsManager.getInstance());
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800129 }
130
Santos Cordon766d04f2014-05-06 10:28:25 -0700131 @Override
132 public void onSuccessfulOutgoingCall(Call call) {
133 Log.v(this, "onSuccessfulOutgoingCall, %s", call);
134 if (mCalls.contains(call)) {
135 // The call's CallService has been updated.
136 for (CallsManagerListener listener : mListeners) {
137 listener.onCallServiceChanged(call, null, call.getCallService());
138 }
139 } else if (mPendingHandoffCalls.contains(call)) {
140 updateHandoffCallServiceDescriptor(call.getOriginalCall(),
141 call.getCallService().getDescriptor());
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700142 } else {
143 Log.wtf(this, "unexpected successful call notification: %s", call);
144 return;
Santos Cordon766d04f2014-05-06 10:28:25 -0700145 }
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700146
147 markCallAsDialing(call);
Santos Cordon766d04f2014-05-06 10:28:25 -0700148 }
149
150 @Override
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700151 public void onFailedOutgoingCall(Call call, int errorCode, String errorMsg) {
152 Log.v(this, "onFailedOutgoingCall, call: %s", call);
153 // TODO: Replace disconnect cause with more specific disconnect causes.
154 markCallAsDisconnected(call, errorCode, errorMsg);
155 }
156
157 @Override
158 public void onCancelledOutgoingCall(Call call) {
159 Log.v(this, "onCancelledOutgoingCall, call: %s", call);
160 setCallState(call, CallState.ABORTED);
161 removeCall(call);
Santos Cordon766d04f2014-05-06 10:28:25 -0700162 }
163
164 @Override
165 public void onSuccessfulIncomingCall(Call call, CallInfo callInfo) {
166 Log.d(this, "onSuccessfulIncomingCall");
167 setCallState(call, callInfo.getState());
168 addCall(call);
169 }
170
171 @Override
172 public void onFailedIncomingCall(Call call) {
173 call.removeListener(this);
Ben Gilada0d9f752014-02-26 11:49:03 -0800174 }
175
Ihab Awadcb387ac2014-05-28 16:49:38 -0700176 @Override
Santos Cordona1610702014-06-04 20:22:56 -0700177 public void onIsConferenceCapableChanged(Call call, boolean isConferenceCapable) {
178 for (CallsManagerListener listener : mListeners) {
179 listener.onIsConferenceCapableChanged(call, isConferenceCapable);
180 }
181 }
182
183 @Override
Ihab Awadcb387ac2014-05-28 16:49:38 -0700184 public void onRequestingRingback(Call call, boolean ringback) {
185 for (CallsManagerListener listener : mListeners) {
186 listener.onRequestingRingback(call, ringback);
187 }
188 }
189
Evan Charlton352105c2014-06-03 14:10:54 -0700190 @Override
191 public void onPostDialWait(Call call, String remaining) {
192 mInCallController.onPostDialWait(call, remaining);
193 }
194
Santos Cordona1610702014-06-04 20:22:56 -0700195 @Override
196 public void onExpiredConferenceCall(Call call) {
197 call.removeListener(this);
198 }
199
200 @Override
201 public void onConfirmedConferenceCall(Call call) {
202 addCall(call);
203 Log.v(this, "confirming Conf call %s", call);
204 for (CallsManagerListener listener : mListeners) {
205 listener.onIsConferencedChanged(call);
206 }
207 }
208
209 @Override
210 public void onParentChanged(Call call) {
211 for (CallsManagerListener listener : mListeners) {
212 listener.onIsConferencedChanged(call);
213 }
214 }
215
216 @Override
217 public void onChildrenChanged(Call call) {
218 for (CallsManagerListener listener : mListeners) {
219 listener.onIsConferencedChanged(call);
220 }
221 }
222
Ihab Awadff7493a2014-06-10 13:47:44 -0700223 @Override
224 public void onCannedSmsResponsesLoaded(Call call) {
225 for (CallsManagerListener listener : mListeners) {
226 listener.onCannedSmsResponsesLoaded(call);
227 }
228 }
229
Nancy Chena65d41f2014-06-24 12:06:03 -0700230 @Override
231 public void onCallVideoProviderChanged(Call call) {
232 for (CallsManagerListener listener : mListeners) {
233 listener.onCallVideoProviderChanged(call);
234 }
235 }
236
Tyler Gunne19cc002014-07-01 11:32:53 -0700237 @Override
238 public void onFeaturesChanged(Call call) {
239 Log.v(this, "onFeaturesChanged: %d", call.getFeatures());
240 for (CallsManagerListener listener : mListeners) {
241 listener.onFeaturesChanged(call);
242 }
243 }
244
Sailesh Nepal810735e2014-03-18 18:15:46 -0700245 ImmutableCollection<Call> getCalls() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700246 return ImmutableList.copyOf(mCalls);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700247 }
248
249 Call getForegroundCall() {
250 return mForegroundCall;
251 }
252
Santos Cordonae193062014-05-21 21:21:49 -0700253 Ringer getRinger() {
254 return mRinger;
255 }
256
Santos Cordonf3671a62014-05-29 21:51:53 -0700257 InCallController getInCallController() {
258 return mInCallController;
259 }
260
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700261 boolean hasEmergencyCall() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700262 for (Call call : mCalls) {
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700263 if (call.isEmergencyCall()) {
264 return true;
265 }
266 }
267 return false;
268 }
269
270 CallAudioState getAudioState() {
271 return mCallAudioManager.getAudioState();
272 }
273
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800274 /**
Santos Cordon493e8f22014-02-19 03:15:12 -0800275 * Starts the incoming call sequence by having switchboard gather more information about the
276 * specified call; using the specified call service descriptor. Upon success, execution returns
Santos Cordon766d04f2014-05-06 10:28:25 -0700277 * to {@link #onSuccessfulIncomingCall} to start the in-call UI.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800278 *
Ben Giladc5b22692014-02-18 20:03:22 -0800279 * @param descriptor The descriptor of the call service to use for this incoming call.
Evan Charltona05805b2014-03-05 08:21:46 -0800280 * @param extras The optional extras Bundle passed with the intent used for the incoming call.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800281 */
Evan Charltona05805b2014-03-05 08:21:46 -0800282 void processIncomingCallIntent(CallServiceDescriptor descriptor, Bundle extras) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800283 Log.d(this, "processIncomingCallIntent");
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800284 // Create a call with no handle. Eventually, switchboard will update the call with
Sailesh Nepale59bb192014-04-01 18:33:59 -0700285 // additional information from the call service, but for now we just need one to pass
286 // around.
Santos Cordona1610702014-06-04 20:22:56 -0700287 Call call = new Call(true /* isIncoming */, false /* isConference */);
Santos Cordon766d04f2014-05-06 10:28:25 -0700288 // TODO(santoscordon): Move this to be a part of addCall()
289 call.addListener(this);
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800290
Santos Cordon766d04f2014-05-06 10:28:25 -0700291 call.startIncoming(descriptor, extras);
Ben Gilada0d9f752014-02-26 11:49:03 -0800292 }
293
294 /**
Yorke Lee33501632014-03-17 19:24:12 -0700295 * Attempts to issue/connect the specified call.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800296 *
Yorke Lee33501632014-03-17 19:24:12 -0700297 * @param handle Handle to connect the call with.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800298 * @param contactInfo Information about the entity being called.
Yorke Lee33501632014-03-17 19:24:12 -0700299 * @param gatewayInfo Optional gateway information that can be used to route the call to the
Santos Cordon5b7b9b32014-03-26 14:00:22 -0700300 * actual dialed handle via a gateway provider. May be null.
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700301 * @param speakerphoneOn Whether or not to turn the speakerphone on once the call connects.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800302 */
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700303 void placeOutgoingCall(Uri handle, ContactInfo contactInfo, GatewayInfo gatewayInfo,
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700304 Subscription subscription, boolean speakerphoneOn) {
Yorke Lee33501632014-03-17 19:24:12 -0700305 final Uri uriHandle = (gatewayInfo == null) ? handle : gatewayInfo.getGatewayHandle();
306
307 if (gatewayInfo == null) {
Santos Cordonb58f4532014-05-29 11:59:06 -0700308 Log.i(this, "Creating a new outgoing call with handle: %s", Log.piiHandle(uriHandle));
Yorke Lee33501632014-03-17 19:24:12 -0700309 } else {
310 Log.i(this, "Creating a new outgoing call with gateway handle: %s, original handle: %s",
311 Log.pii(uriHandle), Log.pii(handle));
312 }
Santos Cordon766d04f2014-05-06 10:28:25 -0700313
Santos Cordona1610702014-06-04 20:22:56 -0700314 Call call = new Call(
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700315 uriHandle, gatewayInfo, subscription,
316 false /* isIncoming */, false /* isConference */);
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700317 call.setStartWithSpeakerphoneOn(speakerphoneOn);
Santos Cordon766d04f2014-05-06 10:28:25 -0700318
319 // TODO(santoscordon): Move this to be a part of addCall()
320 call.addListener(this);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700321 addCall(call);
Santos Cordone3d76ab2014-01-28 17:25:20 -0800322
Santos Cordon766d04f2014-05-06 10:28:25 -0700323 call.startOutgoing();
Yorke Leef98fb572014-03-05 10:56:55 -0800324 }
325
326 /**
Santos Cordona1610702014-06-04 20:22:56 -0700327 * Attempts to start a conference call for the specified call.
328 *
329 * @param call The call to conference with.
330 */
331 void conference(Call call) {
332 Call conferenceCall = new Call(false, true);
333 conferenceCall.addListener(this);
334 call.conferenceInto(conferenceCall);
335 }
336
337 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800338 * Instructs Telecomm to answer the specified call. Intended to be invoked by the in-call
339 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
340 * the user opting to answer said call.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800341 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700342 void answerCall(Call call) {
343 if (!mCalls.contains(call)) {
344 Log.i(this, "Request to answer a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800345 } else {
Santos Cordon40f78c22014-04-07 02:11:42 -0700346 // If the foreground call is not the ringing call and it is currently isActive() or
347 // DIALING, put it on hold before answering the call.
348 if (mForegroundCall != null && mForegroundCall != call &&
349 (mForegroundCall.isActive() ||
350 mForegroundCall.getState() == CallState.DIALING)) {
351 Log.v(this, "Holding active/dialing call %s before answering incoming call %s.",
352 mForegroundCall, call);
353 mForegroundCall.hold();
354 // TODO(santoscordon): Wait until we get confirmation of the active call being
355 // on-hold before answering the new call.
356 // TODO(santoscordon): Import logic from CallManager.acceptCall()
357 }
358
Santos Cordona56f2762014-03-24 15:55:53 -0700359 for (CallsManagerListener listener : mListeners) {
360 listener.onIncomingCallAnswered(call);
361 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800362
Santos Cordon61d0f702014-02-19 02:52:23 -0800363 // We do not update the UI until we get confirmation of the answer() through
Sailesh Nepale59bb192014-04-01 18:33:59 -0700364 // {@link #markCallAsActive}.
Santos Cordon61d0f702014-02-19 02:52:23 -0800365 call.answer();
366 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800367 }
368
369 /**
370 * Instructs Telecomm to reject the specified call. Intended to be invoked by the in-call
371 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
372 * the user opting to reject said call.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800373 */
Ihab Awadff7493a2014-06-10 13:47:44 -0700374 void rejectCall(Call call, boolean rejectWithMessage, String textMessage) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700375 if (!mCalls.contains(call)) {
376 Log.i(this, "Request to reject a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800377 } else {
Santos Cordona56f2762014-03-24 15:55:53 -0700378 for (CallsManagerListener listener : mListeners) {
Ihab Awadff7493a2014-06-10 13:47:44 -0700379 listener.onIncomingCallRejected(call, rejectWithMessage, textMessage);
Santos Cordona56f2762014-03-24 15:55:53 -0700380 }
Ihab Awadff7493a2014-06-10 13:47:44 -0700381 call.reject(rejectWithMessage, textMessage);
Santos Cordon61d0f702014-02-19 02:52:23 -0800382 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800383 }
384
385 /**
Ihab Awad74549ec2014-03-10 15:33:25 -0700386 * Instructs Telecomm to play the specified DTMF tone within the specified call.
387 *
Ihab Awad74549ec2014-03-10 15:33:25 -0700388 * @param digit The DTMF digit to play.
389 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700390 void playDtmfTone(Call call, char digit) {
391 if (!mCalls.contains(call)) {
392 Log.i(this, "Request to play DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700393 } else {
394 call.playDtmfTone(digit);
Santos Cordon92a2d812014-04-30 15:19:01 -0700395 mDtmfLocalTonePlayer.playTone(call, digit);
Ihab Awad74549ec2014-03-10 15:33:25 -0700396 }
397 }
398
399 /**
400 * Instructs Telecomm to stop the currently playing DTMF tone, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -0700401 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700402 void stopDtmfTone(Call call) {
403 if (!mCalls.contains(call)) {
404 Log.i(this, "Request to stop DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700405 } else {
406 call.stopDtmfTone();
Santos Cordon92a2d812014-04-30 15:19:01 -0700407 mDtmfLocalTonePlayer.stopTone(call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700408 }
409 }
410
411 /**
Evan Charlton352105c2014-06-03 14:10:54 -0700412 * Instructs Telecomm to continue (or not) the current post-dial DTMF string, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -0700413 */
Evan Charlton352105c2014-06-03 14:10:54 -0700414 void postDialContinue(Call call, boolean proceed) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700415 if (!mCalls.contains(call)) {
416 Log.i(this, "Request to continue post-dial string in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700417 } else {
Evan Charlton352105c2014-06-03 14:10:54 -0700418 call.postDialContinue(proceed);
Ihab Awad74549ec2014-03-10 15:33:25 -0700419 }
420 }
421
422 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800423 * Instructs Telecomm to disconnect the specified call. Intended to be invoked by the
424 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
425 * the user hitting the end-call button.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800426 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700427 void disconnectCall(Call call) {
Santos Cordon682fe6b2014-05-20 08:56:39 -0700428 Log.v(this, "disconnectCall %s", call);
429
Sailesh Nepale59bb192014-04-01 18:33:59 -0700430 if (!mCalls.contains(call)) {
431 Log.w(this, "Unknown call (%s) asked to disconnect", call);
Santos Cordon049b7b62014-01-30 05:34:26 -0800432 } else {
433 call.disconnect();
434 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800435 }
Santos Cordon681663d2014-01-30 04:32:15 -0800436
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700437 /**
438 * Instructs Telecomm to put the specified call on hold. Intended to be invoked by the
439 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
440 * the user hitting the hold button during an active call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700441 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700442 void holdCall(Call call) {
443 if (!mCalls.contains(call)) {
444 Log.w(this, "Unknown call (%s) asked to be put on hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700445 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700446 Log.d(this, "Putting call on hold: (%s)", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700447 call.hold();
448 }
449 }
450
451 /**
452 * Instructs Telecomm to release the specified call from hold. Intended to be invoked by
453 * the in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered
454 * by the user hitting the hold button during a held call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700455 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700456 void unholdCall(Call call) {
457 if (!mCalls.contains(call)) {
458 Log.w(this, "Unknown call (%s) asked to be removed from hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700459 } else {
Santos Cordonc7e85d42014-05-22 02:51:48 -0700460 Log.d(this, "unholding call: (%s)", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700461 call.unhold();
462 }
463 }
464
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700465 /** Called by the in-call UI to change the mute state. */
466 void mute(boolean shouldMute) {
467 mCallAudioManager.mute(shouldMute);
468 }
469
470 /**
471 * Called by the in-call UI to change the audio route, for example to change from earpiece to
472 * speaker phone.
473 */
474 void setAudioRoute(int route) {
475 mCallAudioManager.setAudioRoute(route);
476 }
477
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700478 void startHandoffForCall(Call originalCall) {
479 if (!mCalls.contains(originalCall)) {
480 Log.w(this, "Unknown call %s asked to be handed off", originalCall);
481 return;
482 }
483
484 for (Call handoffCall : mPendingHandoffCalls) {
485 if (handoffCall.getOriginalCall() == originalCall) {
486 Log.w(this, "Call %s is already being handed off, skipping", originalCall);
487 return;
488 }
489 }
490
491 // Create a new call to be placed in the background. If handoff is successful then the
492 // original call will live on but its state will be updated to the new call's state. In
493 // particular the original call's call service will be updated to the new call's call
494 // service.
Santos Cordona1610702014-06-04 20:22:56 -0700495 Call tempCall = new Call(
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700496 originalCall.getHandoffHandle(), originalCall.getGatewayInfo(),
497 originalCall.getSubscription(), false, false);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700498 tempCall.setOriginalCall(originalCall);
499 tempCall.setExtras(originalCall.getExtras());
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700500 mPendingHandoffCalls.add(tempCall);
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700501 tempCall.addListener(this);
502
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700503 Log.d(this, "Placing handoff call");
Santos Cordon766d04f2014-05-06 10:28:25 -0700504 tempCall.startOutgoing();
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700505 }
506
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700507 /** Called when the audio state changes. */
508 void onAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState) {
509 Log.v(this, "onAudioStateChanged, audioState: %s -> %s", oldAudioState, newAudioState);
Santos Cordona56f2762014-03-24 15:55:53 -0700510 for (CallsManagerListener listener : mListeners) {
511 listener.onAudioStateChanged(oldAudioState, newAudioState);
512 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700513 }
514
Sailesh Nepale59bb192014-04-01 18:33:59 -0700515 void markCallAsRinging(Call call) {
516 setCallState(call, CallState.RINGING);
Santos Cordon681663d2014-01-30 04:32:15 -0800517 }
518
Sailesh Nepale59bb192014-04-01 18:33:59 -0700519 void markCallAsDialing(Call call) {
520 setCallState(call, CallState.DIALING);
Santos Cordon681663d2014-01-30 04:32:15 -0800521 }
522
Sailesh Nepale59bb192014-04-01 18:33:59 -0700523 void markCallAsActive(Call call) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700524 if (call.getConnectTimeMillis() == 0) {
525 call.setConnectTimeMillis(System.currentTimeMillis());
526 }
Sailesh Nepale59bb192014-04-01 18:33:59 -0700527 setCallState(call, CallState.ACTIVE);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700528
529 if (mPendingHandoffCalls.contains(call)) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700530 completeHandoff(call, true);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700531 }
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700532 if (call.getStartWithSpeakerphoneOn()) {
533 setAudioRoute(CallAudioState.ROUTE_SPEAKER);
534 }
Santos Cordon681663d2014-01-30 04:32:15 -0800535 }
536
Sailesh Nepale59bb192014-04-01 18:33:59 -0700537 void markCallAsOnHold(Call call) {
538 setCallState(call, CallState.ON_HOLD);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700539 }
540
Santos Cordon049b7b62014-01-30 05:34:26 -0800541 /**
542 * Marks the specified call as DISCONNECTED and notifies the in-call app. If this was the last
543 * live call, then also disconnect from the in-call controller.
544 *
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700545 * @param disconnectCause The disconnect reason, see {@link android.telephony.DisconnectCause}.
546 * @param disconnectMessage Optional call-service-provided message about the disconnect.
Santos Cordon049b7b62014-01-30 05:34:26 -0800547 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700548 void markCallAsDisconnected(Call call, int disconnectCause, String disconnectMessage) {
549 call.setDisconnectCause(disconnectCause, disconnectMessage);
550 setCallState(call, CallState.DISCONNECTED);
Sailesh Nepal4857f472014-04-07 22:26:27 -0700551
552 // Only remove the call if handoff is not pending.
553 if (call.getHandoffCallServiceDescriptor() == null) {
554 removeCall(call);
555 }
Ben Gilada0d9f752014-02-26 11:49:03 -0800556 }
557
Sailesh Nepal6ab6fb72014-04-01 20:03:19 -0700558 void setHandoffInfo(Call call, Uri handle, Bundle extras) {
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700559 if (!mCalls.contains(call)) {
560 Log.w(this, "Unknown call (%s) asked to set handoff info", call);
561 return;
562 }
563
564 if (extras == null) {
565 call.setExtras(Bundle.EMPTY);
566 } else {
567 call.setExtras(extras);
568 }
569
570 Uri oldHandle = call.getHandoffHandle();
571 Log.v(this, "set handoff handle %s -> %s, for call: %s", oldHandle, handle, call);
572 if (!areUriEqual(oldHandle, handle)) {
573 call.setHandoffHandle(handle);
574 for (CallsManagerListener listener : mListeners) {
575 listener.onCallHandoffHandleChanged(call, oldHandle, handle);
576 }
577 }
Sailesh Nepal6ab6fb72014-04-01 20:03:19 -0700578 }
579
Ben Gilada0d9f752014-02-26 11:49:03 -0800580 /**
Santos Cordon4b2c1192014-03-19 18:15:38 -0700581 * Cleans up any calls currently associated with the specified call service when the
582 * call-service binder disconnects unexpectedly.
583 *
584 * @param callService The call service that disconnected.
585 */
586 void handleCallServiceDeath(CallServiceWrapper callService) {
587 Preconditions.checkNotNull(callService);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700588 for (Call call : ImmutableList.copyOf(mCalls)) {
Santos Cordon4b2c1192014-03-19 18:15:38 -0700589 if (call.getCallService() == callService) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700590 markCallAsDisconnected(call, DisconnectCause.ERROR_UNSPECIFIED, null);
Santos Cordon4b2c1192014-03-19 18:15:38 -0700591 }
592 }
593 }
594
Santos Cordondeb8c892014-05-30 01:38:03 -0700595 boolean hasAnyCalls() {
596 return !mCalls.isEmpty();
597 }
598
Santos Cordonc7e85d42014-05-22 02:51:48 -0700599 boolean hasActiveOrHoldingCall() {
600 for (Call call : mCalls) {
601 CallState state = call.getState();
602 if (state == CallState.ACTIVE || state == CallState.ON_HOLD) {
603 return true;
604 }
605 }
606 return false;
607 }
608
609 boolean hasRingingCall() {
610 for (Call call : mCalls) {
611 if (call.getState() == CallState.RINGING) {
612 return true;
613 }
614 }
615 return false;
616 }
617
Santos Cordondeb8c892014-05-30 01:38:03 -0700618 boolean onMediaButton(int type) {
619 if (hasAnyCalls()) {
620 if (HeadsetMediaButton.SHORT_PRESS == type) {
621 Call ringingCall = getFirstCallWithState(CallState.RINGING);
622 if (ringingCall == null) {
623 mCallAudioManager.toggleMute();
624 return true;
625 } else {
626 ringingCall.answer();
627 return true;
628 }
629 } else if (HeadsetMediaButton.LONG_PRESS == type) {
630 Log.d(this, "handleHeadsetHook: longpress -> hangup");
631 Call callToHangup = getFirstCallWithState(
632 CallState.RINGING, CallState.DIALING, CallState.ACTIVE, CallState.ON_HOLD);
633 if (callToHangup != null) {
634 callToHangup.disconnect();
635 return true;
636 }
637 }
638 }
639 return false;
640 }
641
642 /**
Santos Cordon10838c22014-06-11 17:36:04 -0700643 * Checks to see if the specified call is the only high-level call and if so, enable the
644 * "Add-call" button. We allow you to add a second call but not a third or beyond.
645 *
646 * @param call The call to test for add-call.
647 * @return Whether the add-call feature should be enabled for the call.
648 */
649 protected boolean isAddCallCapable(Call call) {
650 if (call.getParentCall() != null) {
651 // Never true for child calls.
652 return false;
653 }
654
655 // Loop through all the other calls and there exists a top level (has no parent) call
656 // that is not the specified call, return false.
657 for (Call otherCall : mCalls) {
658 if (call != otherCall && otherCall.getParentCall() == null) {
659 return false;
660 }
661 }
662 return true;
663 }
664
665 /**
Santos Cordondeb8c892014-05-30 01:38:03 -0700666 * Returns the first call that it finds with the given states. The states are treated as having
667 * priority order so that any call with the first state will be returned before any call with
668 * states listed later in the parameter list.
669 */
670 private Call getFirstCallWithState(CallState... states) {
671 for (CallState currentState : states) {
672 for (Call call : mCalls) {
673 if (currentState == call.getState()) {
674 return call;
675 }
676 }
677 }
678 return null;
679 }
680
Santos Cordon4b2c1192014-03-19 18:15:38 -0700681 /**
Ben Gilada0d9f752014-02-26 11:49:03 -0800682 * Adds the specified call to the main list of live calls.
683 *
684 * @param call The call to add.
685 */
686 private void addCall(Call call) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700687 mCalls.add(call);
Santos Cordon40f78c22014-04-07 02:11:42 -0700688
689 // TODO(santoscordon): Update mForegroundCall prior to invoking
690 // onCallAdded for calls which immediately take the foreground (like the first call).
Santos Cordona56f2762014-03-24 15:55:53 -0700691 for (CallsManagerListener listener : mListeners) {
692 listener.onCallAdded(call);
693 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700694 updateForegroundCall();
Ben Gilada0d9f752014-02-26 11:49:03 -0800695 }
696
Sailesh Nepal810735e2014-03-18 18:15:46 -0700697 private void removeCall(Call call) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700698 // If a handoff is pending then the original call shouldn't be removed.
699 Preconditions.checkState(call.getHandoffCallServiceDescriptor() == null);
Santos Cordonc499c1c2014-04-14 17:13:14 -0700700 Log.v(this, "removeCall(%s)", call);
Sailesh Nepal4857f472014-04-07 22:26:27 -0700701
Santos Cordon766d04f2014-05-06 10:28:25 -0700702 call.removeListener(this);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700703 call.clearCallService();
Sailesh Nepale59bb192014-04-01 18:33:59 -0700704
705 boolean shouldNotify = false;
706 if (mCalls.contains(call)) {
707 mCalls.remove(call);
708 shouldNotify = true;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700709 } else if (mPendingHandoffCalls.contains(call)) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700710 Log.v(this, "removeCall, marking handoff call as failed");
711 completeHandoff(call, false);
Santos Cordona56f2762014-03-24 15:55:53 -0700712 }
Ben Gilada0d9f752014-02-26 11:49:03 -0800713
Sailesh Nepale59bb192014-04-01 18:33:59 -0700714 // Only broadcast changes for calls that are being tracked.
715 if (shouldNotify) {
716 for (CallsManagerListener listener : mListeners) {
717 listener.onCallRemoved(call);
718 }
719 updateForegroundCall();
Sailesh Nepal810735e2014-03-18 18:15:46 -0700720 }
721 }
Evan Charlton5c670a92014-03-06 14:58:20 -0800722
Sailesh Nepal810735e2014-03-18 18:15:46 -0700723 /**
Santos Cordon1ae2b852014-03-19 03:03:10 -0700724 * Sets the specified state on the specified call.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700725 *
726 * @param call The call.
727 * @param newState The new state of the call.
728 */
729 private void setCallState(Call call, CallState newState) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700730 Preconditions.checkNotNull(newState);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700731 CallState oldState = call.getState();
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700732 Log.i(this, "setCallState %s -> %s, call: %s", oldState, newState, call);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700733 if (newState != oldState) {
734 // Unfortunately, in the telephony world the radio is king. So if the call notifies
735 // us that the call is in a particular state, we allow it even if it doesn't make
736 // sense (e.g., ACTIVE -> RINGING).
737 // TODO(santoscordon): Consider putting a stop to the above and turning CallState
738 // into a well-defined state machine.
739 // TODO(santoscordon): Define expected state transitions here, and log when an
740 // unexpected transition occurs.
741 call.setState(newState);
742
743 // Only broadcast state change for calls that are being tracked.
Sailesh Nepale59bb192014-04-01 18:33:59 -0700744 if (mCalls.contains(call)) {
Santos Cordona56f2762014-03-24 15:55:53 -0700745 for (CallsManagerListener listener : mListeners) {
746 listener.onCallStateChanged(call, oldState, newState);
747 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700748 updateForegroundCall();
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800749 }
750 }
751 }
752
753 /**
Sailesh Nepal810735e2014-03-18 18:15:46 -0700754 * Checks which call should be visible to the user and have audio focus.
Evan Charlton5c670a92014-03-06 14:58:20 -0800755 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700756 private void updateForegroundCall() {
757 Call newForegroundCall = null;
Sailesh Nepale59bb192014-04-01 18:33:59 -0700758 for (Call call : mCalls) {
Santos Cordon40f78c22014-04-07 02:11:42 -0700759 // TODO(santoscordon): Foreground-ness needs to be explicitly set. No call, regardless
760 // of its state will be foreground by default and instead the call service should be
761 // notified when its calls enter and exit foreground state. Foreground will mean that
762 // the call should play audio and listen to microphone if it wants.
763
764 // Active calls have priority.
765 if (call.isActive()) {
Sailesh Nepal810735e2014-03-18 18:15:46 -0700766 newForegroundCall = call;
Evan Charlton5c670a92014-03-06 14:58:20 -0800767 break;
Sailesh Nepal810735e2014-03-18 18:15:46 -0700768 }
Santos Cordon40f78c22014-04-07 02:11:42 -0700769
770 if (call.isAlive() || call.getState() == CallState.RINGING) {
Sailesh Nepal810735e2014-03-18 18:15:46 -0700771 newForegroundCall = call;
Santos Cordon40f78c22014-04-07 02:11:42 -0700772 // Don't break in case there's an active call that has priority.
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800773 }
774 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800775
Sailesh Nepal810735e2014-03-18 18:15:46 -0700776 if (newForegroundCall != mForegroundCall) {
Santos Cordon40f78c22014-04-07 02:11:42 -0700777 Log.v(this, "Updating foreground call, %s -> %s.", mForegroundCall, newForegroundCall);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700778 Call oldForegroundCall = mForegroundCall;
779 mForegroundCall = newForegroundCall;
780
Santos Cordona56f2762014-03-24 15:55:53 -0700781 for (CallsManagerListener listener : mListeners) {
782 listener.onForegroundCallChanged(oldForegroundCall, mForegroundCall);
783 }
Santos Cordon681663d2014-01-30 04:32:15 -0800784 }
785 }
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700786
Sailesh Nepal4857f472014-04-07 22:26:27 -0700787 private void completeHandoff(Call handoffCall, boolean wasSuccessful) {
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700788 Call originalCall = handoffCall.getOriginalCall();
Sailesh Nepal4857f472014-04-07 22:26:27 -0700789 Log.v(this, "complete handoff, %s -> %s, wasSuccessful: %b", handoffCall, originalCall,
790 wasSuccessful);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700791
Sailesh Nepal4857f472014-04-07 22:26:27 -0700792 // Remove the transient handoff call object (don't disconnect because the call could still
793 // be live).
794 mPendingHandoffCalls.remove(handoffCall);
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700795 handoffCall.removeListener(this);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700796
Sailesh Nepal4857f472014-04-07 22:26:27 -0700797 if (wasSuccessful) {
Sailesh Nepaldcd64262014-05-23 17:03:28 -0700798 if (TelephonyUtil.isCurrentlyPSTNCall(originalCall)) {
799 originalCall.disconnect();
800 }
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700801
Sailesh Nepal4857f472014-04-07 22:26:27 -0700802 // Synchronize.
803 originalCall.setCallService(handoffCall.getCallService(), handoffCall);
804 setCallState(originalCall, handoffCall.getState());
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700805
Sailesh Nepal4857f472014-04-07 22:26:27 -0700806 // Force the foreground call changed notification to be sent.
807 for (CallsManagerListener listener : mListeners) {
808 listener.onForegroundCallChanged(mForegroundCall, mForegroundCall);
809 }
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700810
Sailesh Nepal4857f472014-04-07 22:26:27 -0700811 updateHandoffCallServiceDescriptor(originalCall, null);
812 } else {
813 updateHandoffCallServiceDescriptor(originalCall, null);
814 if (originalCall.getState() == CallState.DISCONNECTED ||
815 originalCall.getState() == CallState.ABORTED) {
816 removeCall(originalCall);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700817 }
818 }
819 }
820
Sailesh Nepal4857f472014-04-07 22:26:27 -0700821 private void updateHandoffCallServiceDescriptor(
822 Call originalCall,
823 CallServiceDescriptor newDescriptor) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700824 CallServiceDescriptor oldDescriptor = originalCall.getHandoffCallServiceDescriptor();
Sailesh Nepal4857f472014-04-07 22:26:27 -0700825 Log.v(this, "updateHandoffCallServiceDescriptor, call: %s, pending descriptor: %s -> %s",
826 originalCall, oldDescriptor, newDescriptor);
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700827
828 if (!areDescriptorsEqual(oldDescriptor, newDescriptor)) {
829 originalCall.setHandoffCallServiceDescriptor(newDescriptor);
830 for (CallsManagerListener listener : mListeners) {
831 listener.onCallHandoffCallServiceDescriptorChanged(originalCall, oldDescriptor,
832 newDescriptor);
833 }
834 }
835 }
836
837 private static boolean areDescriptorsEqual(
838 CallServiceDescriptor descriptor1,
839 CallServiceDescriptor descriptor2) {
840 if (descriptor1 == null) {
841 return descriptor2 == null;
842 }
843 return descriptor1.equals(descriptor2);
844 }
845
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700846 private static boolean areUriEqual(Uri handle1, Uri handle2) {
847 if (handle1 == null) {
848 return handle2 == null;
849 }
850 return handle1.equals(handle2);
851 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800852}