blob: d53b58351e39b06e0cd580135f9a2ca6ccbe3081 [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);
Sailesh Nepal810735e2014-03-18 18:15:46 -070068 }
69
Santos Cordon8e8b8d22013-12-19 14:14:05 -080070 private static final CallsManager INSTANCE = new CallsManager();
Ben Gilad9f2bed32013-12-12 17:43:26 -080071
Santos Cordon8e8b8d22013-12-19 14:14:05 -080072 /**
Sailesh Nepale59bb192014-04-01 18:33:59 -070073 * The main call repository. Keeps an instance of all live calls. New incoming and outgoing
74 * calls are added to the map and removed when the calls move to the disconnected state.
Santos Cordon681663d2014-01-30 04:32:15 -080075 */
Santos Cordonf3671a62014-05-29 21:51:53 -070076 private final Set<Call> mCalls = new LinkedHashSet<>();
Santos Cordon681663d2014-01-30 04:32:15 -080077
78 /**
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070079 * Set of new calls created to perform a handoff. The calls are added when handoff is initiated
80 * and removed when hadnoff is complete.
81 */
Santos Cordonf3671a62014-05-29 21:51:53 -070082 private final Set<Call> mPendingHandoffCalls = new LinkedHashSet<>();
83
84
85 private final DtmfLocalTonePlayer mDtmfLocalTonePlayer = new DtmfLocalTonePlayer();
86 private final InCallController mInCallController = new InCallController();
87 private final CallAudioManager mCallAudioManager;
88 private final Ringer mRinger;
89 private final Set<CallsManagerListener> mListeners = new HashSet<>();
Santos Cordondeb8c892014-05-30 01:38:03 -070090 private final HeadsetMediaButton mHeadsetMediaButton;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070091
92 /**
Sailesh Nepal810735e2014-03-18 18:15:46 -070093 * The call the user is currently interacting with. This is the call that should have audio
94 * focus and be visible in the in-call UI.
Santos Cordon4e9fffe2014-03-04 18:13:41 -080095 */
Sailesh Nepal810735e2014-03-18 18:15:46 -070096 private Call mForegroundCall;
Santos Cordon4e9fffe2014-03-04 18:13:41 -080097
Santos Cordon766d04f2014-05-06 10:28:25 -070098 /** Singleton accessor. */
99 static CallsManager getInstance() {
100 return INSTANCE;
101 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800102
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800103 /**
Ben Gilad8bdaa462014-02-05 12:53:19 -0800104 * Initializes the required Telecomm components.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800105 */
106 private CallsManager() {
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700107 TelecommApp app = TelecommApp.getInstance();
Santos Cordona56f2762014-03-24 15:55:53 -0700108
Santos Cordondeb8c892014-05-30 01:38:03 -0700109 StatusBarNotifier statusBarNotifier = new StatusBarNotifier(app, this);
110 mCallAudioManager = new CallAudioManager(app, statusBarNotifier);
Santos Cordonc7b8eba2014-04-01 15:26:28 -0700111 InCallTonePlayer.Factory playerFactory = new InCallTonePlayer.Factory(mCallAudioManager);
Santos Cordonae193062014-05-21 21:21:49 -0700112 mRinger = new Ringer(mCallAudioManager, this, playerFactory, app);
Santos Cordondeb8c892014-05-30 01:38:03 -0700113 mHeadsetMediaButton = new HeadsetMediaButton(app, this);
Santos Cordonae193062014-05-21 21:21:49 -0700114
Santos Cordondeb8c892014-05-30 01:38:03 -0700115 mListeners.add(statusBarNotifier);
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700116 mListeners.add(new CallLogManager(app));
Santos Cordona56f2762014-03-24 15:55:53 -0700117 mListeners.add(new PhoneStateBroadcaster());
Santos Cordonf3671a62014-05-29 21:51:53 -0700118 mListeners.add(mInCallController);
Santos Cordonae193062014-05-21 21:21:49 -0700119 mListeners.add(mRinger);
Santos Cordonc7b8eba2014-04-01 15:26:28 -0700120 mListeners.add(new RingbackPlayer(this, playerFactory));
121 mListeners.add(new InCallToneMonitor(playerFactory, this));
Santos Cordona56f2762014-03-24 15:55:53 -0700122 mListeners.add(mCallAudioManager);
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700123 mListeners.add(app.getMissedCallNotifier());
Santos Cordon92a2d812014-04-30 15:19:01 -0700124 mListeners.add(mDtmfLocalTonePlayer);
Santos Cordon81289982014-06-03 16:03:08 -0700125 mListeners.add(mHeadsetMediaButton);
Ihab Awadff7493a2014-06-10 13:47:44 -0700126 mListeners.add(RespondViaSmsManager.getInstance());
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800127 }
128
Santos Cordon766d04f2014-05-06 10:28:25 -0700129 @Override
130 public void onSuccessfulOutgoingCall(Call call) {
131 Log.v(this, "onSuccessfulOutgoingCall, %s", call);
132 if (mCalls.contains(call)) {
133 // The call's CallService has been updated.
134 for (CallsManagerListener listener : mListeners) {
135 listener.onCallServiceChanged(call, null, call.getCallService());
136 }
137 } else if (mPendingHandoffCalls.contains(call)) {
138 updateHandoffCallServiceDescriptor(call.getOriginalCall(),
139 call.getCallService().getDescriptor());
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700140 } else {
141 Log.wtf(this, "unexpected successful call notification: %s", call);
142 return;
Santos Cordon766d04f2014-05-06 10:28:25 -0700143 }
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700144
145 markCallAsDialing(call);
Santos Cordon766d04f2014-05-06 10:28:25 -0700146 }
147
148 @Override
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700149 public void onFailedOutgoingCall(Call call, int errorCode, String errorMsg) {
150 Log.v(this, "onFailedOutgoingCall, call: %s", call);
151 // TODO: Replace disconnect cause with more specific disconnect causes.
152 markCallAsDisconnected(call, errorCode, errorMsg);
153 }
154
155 @Override
156 public void onCancelledOutgoingCall(Call call) {
157 Log.v(this, "onCancelledOutgoingCall, call: %s", call);
158 setCallState(call, CallState.ABORTED);
159 removeCall(call);
Santos Cordon766d04f2014-05-06 10:28:25 -0700160 }
161
162 @Override
163 public void onSuccessfulIncomingCall(Call call, CallInfo callInfo) {
164 Log.d(this, "onSuccessfulIncomingCall");
165 setCallState(call, callInfo.getState());
166 addCall(call);
167 }
168
169 @Override
170 public void onFailedIncomingCall(Call call) {
171 call.removeListener(this);
Ben Gilada0d9f752014-02-26 11:49:03 -0800172 }
173
Ihab Awadcb387ac2014-05-28 16:49:38 -0700174 @Override
Santos Cordona1610702014-06-04 20:22:56 -0700175 public void onIsConferenceCapableChanged(Call call, boolean isConferenceCapable) {
176 for (CallsManagerListener listener : mListeners) {
177 listener.onIsConferenceCapableChanged(call, isConferenceCapable);
178 }
179 }
180
181 @Override
Ihab Awadcb387ac2014-05-28 16:49:38 -0700182 public void onRequestingRingback(Call call, boolean ringback) {
183 for (CallsManagerListener listener : mListeners) {
184 listener.onRequestingRingback(call, ringback);
185 }
186 }
187
Evan Charlton352105c2014-06-03 14:10:54 -0700188 @Override
189 public void onPostDialWait(Call call, String remaining) {
190 mInCallController.onPostDialWait(call, remaining);
191 }
192
Santos Cordona1610702014-06-04 20:22:56 -0700193 @Override
194 public void onExpiredConferenceCall(Call call) {
195 call.removeListener(this);
196 }
197
198 @Override
199 public void onConfirmedConferenceCall(Call call) {
200 addCall(call);
201 Log.v(this, "confirming Conf call %s", call);
202 for (CallsManagerListener listener : mListeners) {
203 listener.onIsConferencedChanged(call);
204 }
205 }
206
207 @Override
208 public void onParentChanged(Call call) {
209 for (CallsManagerListener listener : mListeners) {
210 listener.onIsConferencedChanged(call);
211 }
212 }
213
214 @Override
215 public void onChildrenChanged(Call call) {
216 for (CallsManagerListener listener : mListeners) {
217 listener.onIsConferencedChanged(call);
218 }
219 }
220
Ihab Awadff7493a2014-06-10 13:47:44 -0700221 @Override
222 public void onCannedSmsResponsesLoaded(Call call) {
223 for (CallsManagerListener listener : mListeners) {
224 listener.onCannedSmsResponsesLoaded(call);
225 }
226 }
227
Sailesh Nepal810735e2014-03-18 18:15:46 -0700228 ImmutableCollection<Call> getCalls() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700229 return ImmutableList.copyOf(mCalls);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700230 }
231
232 Call getForegroundCall() {
233 return mForegroundCall;
234 }
235
Santos Cordonae193062014-05-21 21:21:49 -0700236 Ringer getRinger() {
237 return mRinger;
238 }
239
Santos Cordonf3671a62014-05-29 21:51:53 -0700240 InCallController getInCallController() {
241 return mInCallController;
242 }
243
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700244 boolean hasEmergencyCall() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700245 for (Call call : mCalls) {
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700246 if (call.isEmergencyCall()) {
247 return true;
248 }
249 }
250 return false;
251 }
252
253 CallAudioState getAudioState() {
254 return mCallAudioManager.getAudioState();
255 }
256
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800257 /**
Santos Cordon493e8f22014-02-19 03:15:12 -0800258 * Starts the incoming call sequence by having switchboard gather more information about the
259 * specified call; using the specified call service descriptor. Upon success, execution returns
Santos Cordon766d04f2014-05-06 10:28:25 -0700260 * to {@link #onSuccessfulIncomingCall} to start the in-call UI.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800261 *
Ben Giladc5b22692014-02-18 20:03:22 -0800262 * @param descriptor The descriptor of the call service to use for this incoming call.
Evan Charltona05805b2014-03-05 08:21:46 -0800263 * @param extras The optional extras Bundle passed with the intent used for the incoming call.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800264 */
Evan Charltona05805b2014-03-05 08:21:46 -0800265 void processIncomingCallIntent(CallServiceDescriptor descriptor, Bundle extras) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800266 Log.d(this, "processIncomingCallIntent");
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800267 // Create a call with no handle. Eventually, switchboard will update the call with
Sailesh Nepale59bb192014-04-01 18:33:59 -0700268 // additional information from the call service, but for now we just need one to pass
269 // around.
Santos Cordona1610702014-06-04 20:22:56 -0700270 Call call = new Call(true /* isIncoming */, false /* isConference */);
Santos Cordon766d04f2014-05-06 10:28:25 -0700271 // TODO(santoscordon): Move this to be a part of addCall()
272 call.addListener(this);
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800273
Santos Cordon766d04f2014-05-06 10:28:25 -0700274 call.startIncoming(descriptor, extras);
Ben Gilada0d9f752014-02-26 11:49:03 -0800275 }
276
277 /**
Yorke Lee33501632014-03-17 19:24:12 -0700278 * Attempts to issue/connect the specified call.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800279 *
Yorke Lee33501632014-03-17 19:24:12 -0700280 * @param handle Handle to connect the call with.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800281 * @param contactInfo Information about the entity being called.
Yorke Lee33501632014-03-17 19:24:12 -0700282 * @param gatewayInfo Optional gateway information that can be used to route the call to the
Santos Cordon5b7b9b32014-03-26 14:00:22 -0700283 * actual dialed handle via a gateway provider. May be null.
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700284 * @param speakerphoneOn Whether or not to turn the speakerphone on once the call connects.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800285 */
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700286 void placeOutgoingCall(Uri handle, ContactInfo contactInfo, GatewayInfo gatewayInfo,
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700287 Subscription subscription, boolean speakerphoneOn) {
Yorke Lee33501632014-03-17 19:24:12 -0700288 final Uri uriHandle = (gatewayInfo == null) ? handle : gatewayInfo.getGatewayHandle();
289
290 if (gatewayInfo == null) {
Santos Cordonb58f4532014-05-29 11:59:06 -0700291 Log.i(this, "Creating a new outgoing call with handle: %s", Log.piiHandle(uriHandle));
Yorke Lee33501632014-03-17 19:24:12 -0700292 } else {
293 Log.i(this, "Creating a new outgoing call with gateway handle: %s, original handle: %s",
294 Log.pii(uriHandle), Log.pii(handle));
295 }
Santos Cordon766d04f2014-05-06 10:28:25 -0700296
Santos Cordona1610702014-06-04 20:22:56 -0700297 Call call = new Call(
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700298 uriHandle, gatewayInfo, subscription,
299 false /* isIncoming */, false /* isConference */);
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700300 call.setStartWithSpeakerphoneOn(speakerphoneOn);
Santos Cordon766d04f2014-05-06 10:28:25 -0700301
302 // TODO(santoscordon): Move this to be a part of addCall()
303 call.addListener(this);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700304 addCall(call);
Santos Cordone3d76ab2014-01-28 17:25:20 -0800305
Santos Cordon766d04f2014-05-06 10:28:25 -0700306 call.startOutgoing();
Yorke Leef98fb572014-03-05 10:56:55 -0800307 }
308
309 /**
Santos Cordona1610702014-06-04 20:22:56 -0700310 * Attempts to start a conference call for the specified call.
311 *
312 * @param call The call to conference with.
313 */
314 void conference(Call call) {
315 Call conferenceCall = new Call(false, true);
316 conferenceCall.addListener(this);
317 call.conferenceInto(conferenceCall);
318 }
319
320 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800321 * Instructs Telecomm to answer the specified call. Intended to be invoked by the in-call
322 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
323 * the user opting to answer said call.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800324 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700325 void answerCall(Call call) {
326 if (!mCalls.contains(call)) {
327 Log.i(this, "Request to answer a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800328 } else {
Santos Cordon40f78c22014-04-07 02:11:42 -0700329 // If the foreground call is not the ringing call and it is currently isActive() or
330 // DIALING, put it on hold before answering the call.
331 if (mForegroundCall != null && mForegroundCall != call &&
332 (mForegroundCall.isActive() ||
333 mForegroundCall.getState() == CallState.DIALING)) {
334 Log.v(this, "Holding active/dialing call %s before answering incoming call %s.",
335 mForegroundCall, call);
336 mForegroundCall.hold();
337 // TODO(santoscordon): Wait until we get confirmation of the active call being
338 // on-hold before answering the new call.
339 // TODO(santoscordon): Import logic from CallManager.acceptCall()
340 }
341
Santos Cordona56f2762014-03-24 15:55:53 -0700342 for (CallsManagerListener listener : mListeners) {
343 listener.onIncomingCallAnswered(call);
344 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800345
Santos Cordon61d0f702014-02-19 02:52:23 -0800346 // We do not update the UI until we get confirmation of the answer() through
Sailesh Nepale59bb192014-04-01 18:33:59 -0700347 // {@link #markCallAsActive}.
Santos Cordon61d0f702014-02-19 02:52:23 -0800348 call.answer();
349 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800350 }
351
352 /**
353 * Instructs Telecomm to reject the specified call. Intended to be invoked by the in-call
354 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
355 * the user opting to reject said call.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800356 */
Ihab Awadff7493a2014-06-10 13:47:44 -0700357 void rejectCall(Call call, boolean rejectWithMessage, String textMessage) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700358 if (!mCalls.contains(call)) {
359 Log.i(this, "Request to reject a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800360 } else {
Santos Cordona56f2762014-03-24 15:55:53 -0700361 for (CallsManagerListener listener : mListeners) {
Ihab Awadff7493a2014-06-10 13:47:44 -0700362 listener.onIncomingCallRejected(call, rejectWithMessage, textMessage);
Santos Cordona56f2762014-03-24 15:55:53 -0700363 }
Ihab Awadff7493a2014-06-10 13:47:44 -0700364 call.reject(rejectWithMessage, textMessage);
Santos Cordon61d0f702014-02-19 02:52:23 -0800365 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800366 }
367
368 /**
Ihab Awad74549ec2014-03-10 15:33:25 -0700369 * Instructs Telecomm to play the specified DTMF tone within the specified call.
370 *
Ihab Awad74549ec2014-03-10 15:33:25 -0700371 * @param digit The DTMF digit to play.
372 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700373 void playDtmfTone(Call call, char digit) {
374 if (!mCalls.contains(call)) {
375 Log.i(this, "Request to play DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700376 } else {
377 call.playDtmfTone(digit);
Santos Cordon92a2d812014-04-30 15:19:01 -0700378 mDtmfLocalTonePlayer.playTone(call, digit);
Ihab Awad74549ec2014-03-10 15:33:25 -0700379 }
380 }
381
382 /**
383 * Instructs Telecomm to stop the currently playing DTMF tone, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -0700384 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700385 void stopDtmfTone(Call call) {
386 if (!mCalls.contains(call)) {
387 Log.i(this, "Request to stop DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700388 } else {
389 call.stopDtmfTone();
Santos Cordon92a2d812014-04-30 15:19:01 -0700390 mDtmfLocalTonePlayer.stopTone(call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700391 }
392 }
393
394 /**
Evan Charlton352105c2014-06-03 14:10:54 -0700395 * Instructs Telecomm to continue (or not) the current post-dial DTMF string, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -0700396 */
Evan Charlton352105c2014-06-03 14:10:54 -0700397 void postDialContinue(Call call, boolean proceed) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700398 if (!mCalls.contains(call)) {
399 Log.i(this, "Request to continue post-dial string in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700400 } else {
Evan Charlton352105c2014-06-03 14:10:54 -0700401 call.postDialContinue(proceed);
Ihab Awad74549ec2014-03-10 15:33:25 -0700402 }
403 }
404
405 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800406 * Instructs Telecomm to disconnect the specified call. Intended to be invoked by the
407 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
408 * the user hitting the end-call button.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800409 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700410 void disconnectCall(Call call) {
Santos Cordon682fe6b2014-05-20 08:56:39 -0700411 Log.v(this, "disconnectCall %s", call);
412
Sailesh Nepale59bb192014-04-01 18:33:59 -0700413 if (!mCalls.contains(call)) {
414 Log.w(this, "Unknown call (%s) asked to disconnect", call);
Santos Cordon049b7b62014-01-30 05:34:26 -0800415 } else {
416 call.disconnect();
417 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800418 }
Santos Cordon681663d2014-01-30 04:32:15 -0800419
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700420 /**
421 * Instructs Telecomm to put the specified call on hold. Intended to be invoked by the
422 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
423 * the user hitting the hold button during an active call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700424 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700425 void holdCall(Call call) {
426 if (!mCalls.contains(call)) {
427 Log.w(this, "Unknown call (%s) asked to be put on hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700428 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700429 Log.d(this, "Putting call on hold: (%s)", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700430 call.hold();
431 }
432 }
433
434 /**
435 * Instructs Telecomm to release the specified call from hold. Intended to be invoked by
436 * the in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered
437 * by the user hitting the hold button during a held call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700438 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700439 void unholdCall(Call call) {
440 if (!mCalls.contains(call)) {
441 Log.w(this, "Unknown call (%s) asked to be removed from hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700442 } else {
Santos Cordonc7e85d42014-05-22 02:51:48 -0700443 Log.d(this, "unholding call: (%s)", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700444 call.unhold();
445 }
446 }
447
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700448 /** Called by the in-call UI to change the mute state. */
449 void mute(boolean shouldMute) {
450 mCallAudioManager.mute(shouldMute);
451 }
452
453 /**
454 * Called by the in-call UI to change the audio route, for example to change from earpiece to
455 * speaker phone.
456 */
457 void setAudioRoute(int route) {
458 mCallAudioManager.setAudioRoute(route);
459 }
460
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700461 void startHandoffForCall(Call originalCall) {
462 if (!mCalls.contains(originalCall)) {
463 Log.w(this, "Unknown call %s asked to be handed off", originalCall);
464 return;
465 }
466
467 for (Call handoffCall : mPendingHandoffCalls) {
468 if (handoffCall.getOriginalCall() == originalCall) {
469 Log.w(this, "Call %s is already being handed off, skipping", originalCall);
470 return;
471 }
472 }
473
474 // Create a new call to be placed in the background. If handoff is successful then the
475 // original call will live on but its state will be updated to the new call's state. In
476 // particular the original call's call service will be updated to the new call's call
477 // service.
Santos Cordona1610702014-06-04 20:22:56 -0700478 Call tempCall = new Call(
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700479 originalCall.getHandoffHandle(), originalCall.getGatewayInfo(),
480 originalCall.getSubscription(), false, false);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700481 tempCall.setOriginalCall(originalCall);
482 tempCall.setExtras(originalCall.getExtras());
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700483 mPendingHandoffCalls.add(tempCall);
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700484 tempCall.addListener(this);
485
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700486 Log.d(this, "Placing handoff call");
Santos Cordon766d04f2014-05-06 10:28:25 -0700487 tempCall.startOutgoing();
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700488 }
489
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700490 /** Called when the audio state changes. */
491 void onAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState) {
492 Log.v(this, "onAudioStateChanged, audioState: %s -> %s", oldAudioState, newAudioState);
Santos Cordona56f2762014-03-24 15:55:53 -0700493 for (CallsManagerListener listener : mListeners) {
494 listener.onAudioStateChanged(oldAudioState, newAudioState);
495 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700496 }
497
Sailesh Nepale59bb192014-04-01 18:33:59 -0700498 void markCallAsRinging(Call call) {
499 setCallState(call, CallState.RINGING);
Santos Cordon681663d2014-01-30 04:32:15 -0800500 }
501
Sailesh Nepale59bb192014-04-01 18:33:59 -0700502 void markCallAsDialing(Call call) {
503 setCallState(call, CallState.DIALING);
Santos Cordon681663d2014-01-30 04:32:15 -0800504 }
505
Sailesh Nepale59bb192014-04-01 18:33:59 -0700506 void markCallAsActive(Call call) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700507 if (call.getConnectTimeMillis() == 0) {
508 call.setConnectTimeMillis(System.currentTimeMillis());
509 }
Sailesh Nepale59bb192014-04-01 18:33:59 -0700510 setCallState(call, CallState.ACTIVE);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700511
512 if (mPendingHandoffCalls.contains(call)) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700513 completeHandoff(call, true);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700514 }
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700515 if (call.getStartWithSpeakerphoneOn()) {
516 setAudioRoute(CallAudioState.ROUTE_SPEAKER);
517 }
Santos Cordon681663d2014-01-30 04:32:15 -0800518 }
519
Sailesh Nepale59bb192014-04-01 18:33:59 -0700520 void markCallAsOnHold(Call call) {
521 setCallState(call, CallState.ON_HOLD);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700522 }
523
Santos Cordon049b7b62014-01-30 05:34:26 -0800524 /**
525 * Marks the specified call as DISCONNECTED and notifies the in-call app. If this was the last
526 * live call, then also disconnect from the in-call controller.
527 *
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700528 * @param disconnectCause The disconnect reason, see {@link android.telephony.DisconnectCause}.
529 * @param disconnectMessage Optional call-service-provided message about the disconnect.
Santos Cordon049b7b62014-01-30 05:34:26 -0800530 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700531 void markCallAsDisconnected(Call call, int disconnectCause, String disconnectMessage) {
532 call.setDisconnectCause(disconnectCause, disconnectMessage);
533 setCallState(call, CallState.DISCONNECTED);
Sailesh Nepal4857f472014-04-07 22:26:27 -0700534
535 // Only remove the call if handoff is not pending.
536 if (call.getHandoffCallServiceDescriptor() == null) {
537 removeCall(call);
538 }
Ben Gilada0d9f752014-02-26 11:49:03 -0800539 }
540
Sailesh Nepal6ab6fb72014-04-01 20:03:19 -0700541 void setHandoffInfo(Call call, Uri handle, Bundle extras) {
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700542 if (!mCalls.contains(call)) {
543 Log.w(this, "Unknown call (%s) asked to set handoff info", call);
544 return;
545 }
546
547 if (extras == null) {
548 call.setExtras(Bundle.EMPTY);
549 } else {
550 call.setExtras(extras);
551 }
552
553 Uri oldHandle = call.getHandoffHandle();
554 Log.v(this, "set handoff handle %s -> %s, for call: %s", oldHandle, handle, call);
555 if (!areUriEqual(oldHandle, handle)) {
556 call.setHandoffHandle(handle);
557 for (CallsManagerListener listener : mListeners) {
558 listener.onCallHandoffHandleChanged(call, oldHandle, handle);
559 }
560 }
Sailesh Nepal6ab6fb72014-04-01 20:03:19 -0700561 }
562
Ben Gilada0d9f752014-02-26 11:49:03 -0800563 /**
Santos Cordon4b2c1192014-03-19 18:15:38 -0700564 * Cleans up any calls currently associated with the specified call service when the
565 * call-service binder disconnects unexpectedly.
566 *
567 * @param callService The call service that disconnected.
568 */
569 void handleCallServiceDeath(CallServiceWrapper callService) {
570 Preconditions.checkNotNull(callService);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700571 for (Call call : ImmutableList.copyOf(mCalls)) {
Santos Cordon4b2c1192014-03-19 18:15:38 -0700572 if (call.getCallService() == callService) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700573 markCallAsDisconnected(call, DisconnectCause.ERROR_UNSPECIFIED, null);
Santos Cordon4b2c1192014-03-19 18:15:38 -0700574 }
575 }
576 }
577
Santos Cordondeb8c892014-05-30 01:38:03 -0700578 boolean hasAnyCalls() {
579 return !mCalls.isEmpty();
580 }
581
Santos Cordonc7e85d42014-05-22 02:51:48 -0700582 boolean hasActiveOrHoldingCall() {
583 for (Call call : mCalls) {
584 CallState state = call.getState();
585 if (state == CallState.ACTIVE || state == CallState.ON_HOLD) {
586 return true;
587 }
588 }
589 return false;
590 }
591
592 boolean hasRingingCall() {
593 for (Call call : mCalls) {
594 if (call.getState() == CallState.RINGING) {
595 return true;
596 }
597 }
598 return false;
599 }
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 */
653 private Call getFirstCallWithState(CallState... states) {
654 for (CallState currentState : states) {
655 for (Call call : mCalls) {
656 if (currentState == call.getState()) {
657 return call;
658 }
659 }
660 }
661 return null;
662 }
663
Santos Cordon4b2c1192014-03-19 18:15:38 -0700664 /**
Ben Gilada0d9f752014-02-26 11:49:03 -0800665 * Adds the specified call to the main list of live calls.
666 *
667 * @param call The call to add.
668 */
669 private void addCall(Call call) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700670 mCalls.add(call);
Santos Cordon40f78c22014-04-07 02:11:42 -0700671
672 // TODO(santoscordon): Update mForegroundCall prior to invoking
673 // onCallAdded for calls which immediately take the foreground (like the first call).
Santos Cordona56f2762014-03-24 15:55:53 -0700674 for (CallsManagerListener listener : mListeners) {
675 listener.onCallAdded(call);
676 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700677 updateForegroundCall();
Ben Gilada0d9f752014-02-26 11:49:03 -0800678 }
679
Sailesh Nepal810735e2014-03-18 18:15:46 -0700680 private void removeCall(Call call) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700681 // If a handoff is pending then the original call shouldn't be removed.
682 Preconditions.checkState(call.getHandoffCallServiceDescriptor() == null);
Santos Cordonc499c1c2014-04-14 17:13:14 -0700683 Log.v(this, "removeCall(%s)", call);
Sailesh Nepal4857f472014-04-07 22:26:27 -0700684
Santos Cordon766d04f2014-05-06 10:28:25 -0700685 call.removeListener(this);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700686 call.clearCallService();
Sailesh Nepale59bb192014-04-01 18:33:59 -0700687
688 boolean shouldNotify = false;
689 if (mCalls.contains(call)) {
690 mCalls.remove(call);
691 shouldNotify = true;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700692 } else if (mPendingHandoffCalls.contains(call)) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700693 Log.v(this, "removeCall, marking handoff call as failed");
694 completeHandoff(call, false);
Santos Cordona56f2762014-03-24 15:55:53 -0700695 }
Ben Gilada0d9f752014-02-26 11:49:03 -0800696
Sailesh Nepale59bb192014-04-01 18:33:59 -0700697 // Only broadcast changes for calls that are being tracked.
698 if (shouldNotify) {
699 for (CallsManagerListener listener : mListeners) {
700 listener.onCallRemoved(call);
701 }
702 updateForegroundCall();
Sailesh Nepal810735e2014-03-18 18:15:46 -0700703 }
704 }
Evan Charlton5c670a92014-03-06 14:58:20 -0800705
Sailesh Nepal810735e2014-03-18 18:15:46 -0700706 /**
Santos Cordon1ae2b852014-03-19 03:03:10 -0700707 * Sets the specified state on the specified call.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700708 *
709 * @param call The call.
710 * @param newState The new state of the call.
711 */
712 private void setCallState(Call call, CallState newState) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700713 Preconditions.checkNotNull(newState);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700714 CallState oldState = call.getState();
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700715 Log.i(this, "setCallState %s -> %s, call: %s", oldState, newState, call);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700716 if (newState != oldState) {
717 // Unfortunately, in the telephony world the radio is king. So if the call notifies
718 // us that the call is in a particular state, we allow it even if it doesn't make
719 // sense (e.g., ACTIVE -> RINGING).
720 // TODO(santoscordon): Consider putting a stop to the above and turning CallState
721 // into a well-defined state machine.
722 // TODO(santoscordon): Define expected state transitions here, and log when an
723 // unexpected transition occurs.
724 call.setState(newState);
725
726 // Only broadcast state change for calls that are being tracked.
Sailesh Nepale59bb192014-04-01 18:33:59 -0700727 if (mCalls.contains(call)) {
Santos Cordona56f2762014-03-24 15:55:53 -0700728 for (CallsManagerListener listener : mListeners) {
729 listener.onCallStateChanged(call, oldState, newState);
730 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700731 updateForegroundCall();
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800732 }
733 }
734 }
735
736 /**
Sailesh Nepal810735e2014-03-18 18:15:46 -0700737 * Checks which call should be visible to the user and have audio focus.
Evan Charlton5c670a92014-03-06 14:58:20 -0800738 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700739 private void updateForegroundCall() {
740 Call newForegroundCall = null;
Sailesh Nepale59bb192014-04-01 18:33:59 -0700741 for (Call call : mCalls) {
Santos Cordon40f78c22014-04-07 02:11:42 -0700742 // TODO(santoscordon): Foreground-ness needs to be explicitly set. No call, regardless
743 // of its state will be foreground by default and instead the call service should be
744 // notified when its calls enter and exit foreground state. Foreground will mean that
745 // the call should play audio and listen to microphone if it wants.
746
747 // Active calls have priority.
748 if (call.isActive()) {
Sailesh Nepal810735e2014-03-18 18:15:46 -0700749 newForegroundCall = call;
Evan Charlton5c670a92014-03-06 14:58:20 -0800750 break;
Sailesh Nepal810735e2014-03-18 18:15:46 -0700751 }
Santos Cordon40f78c22014-04-07 02:11:42 -0700752
753 if (call.isAlive() || call.getState() == CallState.RINGING) {
Sailesh Nepal810735e2014-03-18 18:15:46 -0700754 newForegroundCall = call;
Santos Cordon40f78c22014-04-07 02:11:42 -0700755 // Don't break in case there's an active call that has priority.
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800756 }
757 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800758
Sailesh Nepal810735e2014-03-18 18:15:46 -0700759 if (newForegroundCall != mForegroundCall) {
Santos Cordon40f78c22014-04-07 02:11:42 -0700760 Log.v(this, "Updating foreground call, %s -> %s.", mForegroundCall, newForegroundCall);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700761 Call oldForegroundCall = mForegroundCall;
762 mForegroundCall = newForegroundCall;
763
Santos Cordona56f2762014-03-24 15:55:53 -0700764 for (CallsManagerListener listener : mListeners) {
765 listener.onForegroundCallChanged(oldForegroundCall, mForegroundCall);
766 }
Santos Cordon681663d2014-01-30 04:32:15 -0800767 }
768 }
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700769
Sailesh Nepal4857f472014-04-07 22:26:27 -0700770 private void completeHandoff(Call handoffCall, boolean wasSuccessful) {
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700771 Call originalCall = handoffCall.getOriginalCall();
Sailesh Nepal4857f472014-04-07 22:26:27 -0700772 Log.v(this, "complete handoff, %s -> %s, wasSuccessful: %b", handoffCall, originalCall,
773 wasSuccessful);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700774
Sailesh Nepal4857f472014-04-07 22:26:27 -0700775 // Remove the transient handoff call object (don't disconnect because the call could still
776 // be live).
777 mPendingHandoffCalls.remove(handoffCall);
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700778 handoffCall.removeListener(this);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700779
Sailesh Nepal4857f472014-04-07 22:26:27 -0700780 if (wasSuccessful) {
Sailesh Nepaldcd64262014-05-23 17:03:28 -0700781 if (TelephonyUtil.isCurrentlyPSTNCall(originalCall)) {
782 originalCall.disconnect();
783 }
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700784
Sailesh Nepal4857f472014-04-07 22:26:27 -0700785 // Synchronize.
786 originalCall.setCallService(handoffCall.getCallService(), handoffCall);
787 setCallState(originalCall, handoffCall.getState());
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700788
Sailesh Nepal4857f472014-04-07 22:26:27 -0700789 // Force the foreground call changed notification to be sent.
790 for (CallsManagerListener listener : mListeners) {
791 listener.onForegroundCallChanged(mForegroundCall, mForegroundCall);
792 }
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700793
Sailesh Nepal4857f472014-04-07 22:26:27 -0700794 updateHandoffCallServiceDescriptor(originalCall, null);
795 } else {
796 updateHandoffCallServiceDescriptor(originalCall, null);
797 if (originalCall.getState() == CallState.DISCONNECTED ||
798 originalCall.getState() == CallState.ABORTED) {
799 removeCall(originalCall);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700800 }
801 }
802 }
803
Sailesh Nepal4857f472014-04-07 22:26:27 -0700804 private void updateHandoffCallServiceDescriptor(
805 Call originalCall,
806 CallServiceDescriptor newDescriptor) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700807 CallServiceDescriptor oldDescriptor = originalCall.getHandoffCallServiceDescriptor();
Sailesh Nepal4857f472014-04-07 22:26:27 -0700808 Log.v(this, "updateHandoffCallServiceDescriptor, call: %s, pending descriptor: %s -> %s",
809 originalCall, oldDescriptor, newDescriptor);
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700810
811 if (!areDescriptorsEqual(oldDescriptor, newDescriptor)) {
812 originalCall.setHandoffCallServiceDescriptor(newDescriptor);
813 for (CallsManagerListener listener : mListeners) {
814 listener.onCallHandoffCallServiceDescriptorChanged(originalCall, oldDescriptor,
815 newDescriptor);
816 }
817 }
818 }
819
820 private static boolean areDescriptorsEqual(
821 CallServiceDescriptor descriptor1,
822 CallServiceDescriptor descriptor2) {
823 if (descriptor1 == null) {
824 return descriptor2 == null;
825 }
826 return descriptor1.equals(descriptor2);
827 }
828
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700829 private static boolean areUriEqual(Uri handle1, Uri handle2) {
830 if (handle1 == null) {
831 return handle2 == null;
832 }
833 return handle1.equals(handle2);
834 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800835}