blob: 174e59f06a600f12f1028ed2ee4000371a8b8f82 [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;
Santos Cordon79ff2bc2014-03-27 15:31:27 -070026import android.telephony.DisconnectCause;
Santos Cordon8e8b8d22013-12-19 14:14:05 -080027
Santos Cordon681663d2014-01-30 04:32:15 -080028import com.google.common.base.Preconditions;
Sailesh Nepal810735e2014-03-18 18:15:46 -070029import com.google.common.collect.ImmutableCollection;
30import com.google.common.collect.ImmutableList;
Ben Gilad9f2bed32013-12-12 17:43:26 -080031
Santos Cordonf3671a62014-05-29 21:51:53 -070032import java.util.HashSet;
33import java.util.LinkedHashSet;
Santos Cordona56f2762014-03-24 15:55:53 -070034import java.util.Set;
Ben Gilad9f2bed32013-12-12 17:43:26 -080035
Ben Giladdd8c6082013-12-30 14:44:08 -080036/**
37 * Singleton.
38 *
39 * NOTE(gilad): by design most APIs are package private, use the relevant adapter/s to allow
40 * access from other packages specifically refraining from passing the CallsManager instance
41 * beyond the com.android.telecomm package boundary.
42 */
Santos Cordon766d04f2014-05-06 10:28:25 -070043public final class CallsManager implements Call.Listener {
Ben Gilada0d9f752014-02-26 11:49:03 -080044
Santos Cordon74d420b2014-05-07 14:38:47 -070045 // TODO(santoscordon): Consider renaming this CallsManagerPlugin.
Sailesh Nepal810735e2014-03-18 18:15:46 -070046 interface CallsManagerListener {
47 void onCallAdded(Call call);
48 void onCallRemoved(Call call);
49 void onCallStateChanged(Call call, CallState oldState, CallState newState);
Sailesh Nepal8c85dee2014-04-07 22:21:40 -070050 void onCallHandoffHandleChanged(Call call, Uri oldHandle, Uri newHandle);
51 void onCallServiceChanged(
52 Call call,
53 CallServiceWrapper oldCallService,
54 CallServiceWrapper newCallService);
55 void onCallHandoffCallServiceDescriptorChanged(
56 Call call,
57 CallServiceDescriptor oldDescriptor,
58 CallServiceDescriptor newDescriptor);
Sailesh Nepal810735e2014-03-18 18:15:46 -070059 void onIncomingCallAnswered(Call call);
Ihab Awadff7493a2014-06-10 13:47:44 -070060 void onIncomingCallRejected(Call call, boolean rejectWithMessage, String textMessage);
Sailesh Nepal810735e2014-03-18 18:15:46 -070061 void onForegroundCallChanged(Call oldForegroundCall, Call newForegroundCall);
Sailesh Nepal6aca10a2014-03-24 16:11:02 -070062 void onAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState);
Ihab Awadcb387ac2014-05-28 16:49:38 -070063 void onRequestingRingback(Call call, boolean ringback);
Santos Cordona1610702014-06-04 20:22:56 -070064 void onIsConferenceCapableChanged(Call call, boolean isConferenceCapable);
65 void onIsConferencedChanged(Call call);
Ihab Awadff7493a2014-06-10 13:47:44 -070066 void onCannedSmsResponsesLoaded(Call call);
Sailesh Nepal810735e2014-03-18 18:15:46 -070067 }
68
Santos Cordon8e8b8d22013-12-19 14:14:05 -080069 private static final CallsManager INSTANCE = new CallsManager();
Ben Gilad9f2bed32013-12-12 17:43:26 -080070
Santos Cordon8e8b8d22013-12-19 14:14:05 -080071 /**
Sailesh Nepale59bb192014-04-01 18:33:59 -070072 * The main call repository. Keeps an instance of all live calls. New incoming and outgoing
73 * calls are added to the map and removed when the calls move to the disconnected state.
Santos Cordon681663d2014-01-30 04:32:15 -080074 */
Santos Cordonf3671a62014-05-29 21:51:53 -070075 private final Set<Call> mCalls = new LinkedHashSet<>();
Santos Cordon681663d2014-01-30 04:32:15 -080076
77 /**
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070078 * Set of new calls created to perform a handoff. The calls are added when handoff is initiated
79 * and removed when hadnoff is complete.
80 */
Santos Cordonf3671a62014-05-29 21:51:53 -070081 private final Set<Call> mPendingHandoffCalls = new LinkedHashSet<>();
82
83
84 private final DtmfLocalTonePlayer mDtmfLocalTonePlayer = new DtmfLocalTonePlayer();
85 private final InCallController mInCallController = new InCallController();
86 private final CallAudioManager mCallAudioManager;
87 private final Ringer mRinger;
88 private final Set<CallsManagerListener> mListeners = new HashSet<>();
Santos Cordondeb8c892014-05-30 01:38:03 -070089 private final HeadsetMediaButton mHeadsetMediaButton;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070090
91 /**
Sailesh Nepal810735e2014-03-18 18:15:46 -070092 * The call the user is currently interacting with. This is the call that should have audio
93 * focus and be visible in the in-call UI.
Santos Cordon4e9fffe2014-03-04 18:13:41 -080094 */
Sailesh Nepal810735e2014-03-18 18:15:46 -070095 private Call mForegroundCall;
Santos Cordon4e9fffe2014-03-04 18:13:41 -080096
Santos Cordon766d04f2014-05-06 10:28:25 -070097 /** Singleton accessor. */
98 static CallsManager getInstance() {
99 return INSTANCE;
100 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800101
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800102 /**
Ben Gilad8bdaa462014-02-05 12:53:19 -0800103 * Initializes the required Telecomm components.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800104 */
105 private CallsManager() {
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700106 TelecommApp app = TelecommApp.getInstance();
Santos Cordona56f2762014-03-24 15:55:53 -0700107
Santos Cordondeb8c892014-05-30 01:38:03 -0700108 StatusBarNotifier statusBarNotifier = new StatusBarNotifier(app, this);
109 mCallAudioManager = new CallAudioManager(app, statusBarNotifier);
Santos Cordonc7b8eba2014-04-01 15:26:28 -0700110 InCallTonePlayer.Factory playerFactory = new InCallTonePlayer.Factory(mCallAudioManager);
Santos Cordonae193062014-05-21 21:21:49 -0700111 mRinger = new Ringer(mCallAudioManager, this, playerFactory, app);
Santos Cordondeb8c892014-05-30 01:38:03 -0700112 mHeadsetMediaButton = new HeadsetMediaButton(app, this);
Santos Cordonae193062014-05-21 21:21:49 -0700113
Santos Cordondeb8c892014-05-30 01:38:03 -0700114 mListeners.add(statusBarNotifier);
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700115 mListeners.add(new CallLogManager(app));
Santos Cordona56f2762014-03-24 15:55:53 -0700116 mListeners.add(new PhoneStateBroadcaster());
Santos Cordonf3671a62014-05-29 21:51:53 -0700117 mListeners.add(mInCallController);
Santos Cordonae193062014-05-21 21:21:49 -0700118 mListeners.add(mRinger);
Santos Cordonc7b8eba2014-04-01 15:26:28 -0700119 mListeners.add(new RingbackPlayer(this, playerFactory));
120 mListeners.add(new InCallToneMonitor(playerFactory, this));
Santos Cordona56f2762014-03-24 15:55:53 -0700121 mListeners.add(mCallAudioManager);
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700122 mListeners.add(app.getMissedCallNotifier());
Santos Cordon92a2d812014-04-30 15:19:01 -0700123 mListeners.add(mDtmfLocalTonePlayer);
Santos Cordon81289982014-06-03 16:03:08 -0700124 mListeners.add(mHeadsetMediaButton);
Ihab Awadff7493a2014-06-10 13:47:44 -0700125 mListeners.add(RespondViaSmsManager.getInstance());
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800126 }
127
Santos Cordon766d04f2014-05-06 10:28:25 -0700128 @Override
129 public void onSuccessfulOutgoingCall(Call call) {
130 Log.v(this, "onSuccessfulOutgoingCall, %s", call);
131 if (mCalls.contains(call)) {
132 // The call's CallService has been updated.
133 for (CallsManagerListener listener : mListeners) {
134 listener.onCallServiceChanged(call, null, call.getCallService());
135 }
136 } else if (mPendingHandoffCalls.contains(call)) {
137 updateHandoffCallServiceDescriptor(call.getOriginalCall(),
138 call.getCallService().getDescriptor());
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700139 } else {
140 Log.wtf(this, "unexpected successful call notification: %s", call);
141 return;
Santos Cordon766d04f2014-05-06 10:28:25 -0700142 }
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700143
144 markCallAsDialing(call);
Santos Cordon766d04f2014-05-06 10:28:25 -0700145 }
146
147 @Override
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700148 public void onFailedOutgoingCall(Call call, int errorCode, String errorMsg) {
149 Log.v(this, "onFailedOutgoingCall, call: %s", call);
150 // TODO: Replace disconnect cause with more specific disconnect causes.
151 markCallAsDisconnected(call, errorCode, errorMsg);
152 }
153
154 @Override
155 public void onCancelledOutgoingCall(Call call) {
156 Log.v(this, "onCancelledOutgoingCall, call: %s", call);
157 setCallState(call, CallState.ABORTED);
158 removeCall(call);
Santos Cordon766d04f2014-05-06 10:28:25 -0700159 }
160
161 @Override
162 public void onSuccessfulIncomingCall(Call call, CallInfo callInfo) {
163 Log.d(this, "onSuccessfulIncomingCall");
164 setCallState(call, callInfo.getState());
165 addCall(call);
166 }
167
168 @Override
169 public void onFailedIncomingCall(Call call) {
170 call.removeListener(this);
Ben Gilada0d9f752014-02-26 11:49:03 -0800171 }
172
Ihab Awadcb387ac2014-05-28 16:49:38 -0700173 @Override
Santos Cordona1610702014-06-04 20:22:56 -0700174 public void onIsConferenceCapableChanged(Call call, boolean isConferenceCapable) {
175 for (CallsManagerListener listener : mListeners) {
176 listener.onIsConferenceCapableChanged(call, isConferenceCapable);
177 }
178 }
179
180 @Override
Ihab Awadcb387ac2014-05-28 16:49:38 -0700181 public void onRequestingRingback(Call call, boolean ringback) {
182 for (CallsManagerListener listener : mListeners) {
183 listener.onRequestingRingback(call, ringback);
184 }
185 }
186
Evan Charlton352105c2014-06-03 14:10:54 -0700187 @Override
188 public void onPostDialWait(Call call, String remaining) {
189 mInCallController.onPostDialWait(call, remaining);
190 }
191
Santos Cordona1610702014-06-04 20:22:56 -0700192 @Override
193 public void onExpiredConferenceCall(Call call) {
194 call.removeListener(this);
195 }
196
197 @Override
198 public void onConfirmedConferenceCall(Call call) {
199 addCall(call);
200 Log.v(this, "confirming Conf call %s", call);
201 for (CallsManagerListener listener : mListeners) {
202 listener.onIsConferencedChanged(call);
203 }
204 }
205
206 @Override
207 public void onParentChanged(Call call) {
208 for (CallsManagerListener listener : mListeners) {
209 listener.onIsConferencedChanged(call);
210 }
211 }
212
213 @Override
214 public void onChildrenChanged(Call call) {
215 for (CallsManagerListener listener : mListeners) {
216 listener.onIsConferencedChanged(call);
217 }
218 }
219
Ihab Awadff7493a2014-06-10 13:47:44 -0700220 @Override
221 public void onCannedSmsResponsesLoaded(Call call) {
222 for (CallsManagerListener listener : mListeners) {
223 listener.onCannedSmsResponsesLoaded(call);
224 }
225 }
226
Sailesh Nepal810735e2014-03-18 18:15:46 -0700227 ImmutableCollection<Call> getCalls() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700228 return ImmutableList.copyOf(mCalls);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700229 }
230
231 Call getForegroundCall() {
232 return mForegroundCall;
233 }
234
Santos Cordonae193062014-05-21 21:21:49 -0700235 Ringer getRinger() {
236 return mRinger;
237 }
238
Santos Cordonf3671a62014-05-29 21:51:53 -0700239 InCallController getInCallController() {
240 return mInCallController;
241 }
242
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700243 boolean hasEmergencyCall() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700244 for (Call call : mCalls) {
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700245 if (call.isEmergencyCall()) {
246 return true;
247 }
248 }
249 return false;
250 }
251
252 CallAudioState getAudioState() {
253 return mCallAudioManager.getAudioState();
254 }
255
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800256 /**
Santos Cordon493e8f22014-02-19 03:15:12 -0800257 * Starts the incoming call sequence by having switchboard gather more information about the
258 * specified call; using the specified call service descriptor. Upon success, execution returns
Santos Cordon766d04f2014-05-06 10:28:25 -0700259 * to {@link #onSuccessfulIncomingCall} to start the in-call UI.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800260 *
Ben Giladc5b22692014-02-18 20:03:22 -0800261 * @param descriptor The descriptor of the call service to use for this incoming call.
Evan Charltona05805b2014-03-05 08:21:46 -0800262 * @param extras The optional extras Bundle passed with the intent used for the incoming call.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800263 */
Evan Charltona05805b2014-03-05 08:21:46 -0800264 void processIncomingCallIntent(CallServiceDescriptor descriptor, Bundle extras) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800265 Log.d(this, "processIncomingCallIntent");
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800266 // Create a call with no handle. Eventually, switchboard will update the call with
Sailesh Nepale59bb192014-04-01 18:33:59 -0700267 // additional information from the call service, but for now we just need one to pass
268 // around.
Santos Cordona1610702014-06-04 20:22:56 -0700269 Call call = new Call(true /* isIncoming */, false /* isConference */);
Santos Cordon766d04f2014-05-06 10:28:25 -0700270 // TODO(santoscordon): Move this to be a part of addCall()
271 call.addListener(this);
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800272
Santos Cordon766d04f2014-05-06 10:28:25 -0700273 call.startIncoming(descriptor, extras);
Ben Gilada0d9f752014-02-26 11:49:03 -0800274 }
275
276 /**
Yorke Lee33501632014-03-17 19:24:12 -0700277 * Attempts to issue/connect the specified call.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800278 *
Yorke Lee33501632014-03-17 19:24:12 -0700279 * @param handle Handle to connect the call with.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800280 * @param contactInfo Information about the entity being called.
Yorke Lee33501632014-03-17 19:24:12 -0700281 * @param gatewayInfo Optional gateway information that can be used to route the call to the
Santos Cordon5b7b9b32014-03-26 14:00:22 -0700282 * actual dialed handle via a gateway provider. May be null.
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700283 * @param speakerphoneOn Whether or not to turn the speakerphone on once the call connects.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800284 */
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700285 void placeOutgoingCall(Uri handle, ContactInfo contactInfo, GatewayInfo gatewayInfo,
286 boolean speakerphoneOn) {
Yorke Lee33501632014-03-17 19:24:12 -0700287 final Uri uriHandle = (gatewayInfo == null) ? handle : gatewayInfo.getGatewayHandle();
288
289 if (gatewayInfo == null) {
Santos Cordonb58f4532014-05-29 11:59:06 -0700290 Log.i(this, "Creating a new outgoing call with handle: %s", Log.piiHandle(uriHandle));
Yorke Lee33501632014-03-17 19:24:12 -0700291 } else {
292 Log.i(this, "Creating a new outgoing call with gateway handle: %s, original handle: %s",
293 Log.pii(uriHandle), Log.pii(handle));
294 }
Santos Cordon766d04f2014-05-06 10:28:25 -0700295
Santos Cordona1610702014-06-04 20:22:56 -0700296 Call call = new Call(
297 uriHandle, gatewayInfo, false /* isIncoming */, false /* isConference */);
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700298 call.setStartWithSpeakerphoneOn(speakerphoneOn);
Santos Cordon766d04f2014-05-06 10:28:25 -0700299
300 // TODO(santoscordon): Move this to be a part of addCall()
301 call.addListener(this);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700302 addCall(call);
Santos Cordone3d76ab2014-01-28 17:25:20 -0800303
Santos Cordon766d04f2014-05-06 10:28:25 -0700304 call.startOutgoing();
Yorke Leef98fb572014-03-05 10:56:55 -0800305 }
306
307 /**
Santos Cordona1610702014-06-04 20:22:56 -0700308 * Attempts to start a conference call for the specified call.
309 *
310 * @param call The call to conference with.
311 */
312 void conference(Call call) {
313 Call conferenceCall = new Call(false, true);
314 conferenceCall.addListener(this);
315 call.conferenceInto(conferenceCall);
316 }
317
318 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800319 * Instructs Telecomm to answer the specified call. Intended to be invoked by the in-call
320 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
321 * the user opting to answer said call.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800322 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700323 void answerCall(Call call) {
324 if (!mCalls.contains(call)) {
325 Log.i(this, "Request to answer a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800326 } else {
Santos Cordon40f78c22014-04-07 02:11:42 -0700327 // If the foreground call is not the ringing call and it is currently isActive() or
328 // DIALING, put it on hold before answering the call.
329 if (mForegroundCall != null && mForegroundCall != call &&
330 (mForegroundCall.isActive() ||
331 mForegroundCall.getState() == CallState.DIALING)) {
332 Log.v(this, "Holding active/dialing call %s before answering incoming call %s.",
333 mForegroundCall, call);
334 mForegroundCall.hold();
335 // TODO(santoscordon): Wait until we get confirmation of the active call being
336 // on-hold before answering the new call.
337 // TODO(santoscordon): Import logic from CallManager.acceptCall()
338 }
339
Santos Cordona56f2762014-03-24 15:55:53 -0700340 for (CallsManagerListener listener : mListeners) {
341 listener.onIncomingCallAnswered(call);
342 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800343
Santos Cordon61d0f702014-02-19 02:52:23 -0800344 // We do not update the UI until we get confirmation of the answer() through
Sailesh Nepale59bb192014-04-01 18:33:59 -0700345 // {@link #markCallAsActive}.
Santos Cordon61d0f702014-02-19 02:52:23 -0800346 call.answer();
347 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800348 }
349
350 /**
351 * Instructs Telecomm to reject the specified call. Intended to be invoked by the in-call
352 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
353 * the user opting to reject said call.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800354 */
Ihab Awadff7493a2014-06-10 13:47:44 -0700355 void rejectCall(Call call, boolean rejectWithMessage, String textMessage) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700356 if (!mCalls.contains(call)) {
357 Log.i(this, "Request to reject a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800358 } else {
Santos Cordona56f2762014-03-24 15:55:53 -0700359 for (CallsManagerListener listener : mListeners) {
Ihab Awadff7493a2014-06-10 13:47:44 -0700360 listener.onIncomingCallRejected(call, rejectWithMessage, textMessage);
Santos Cordona56f2762014-03-24 15:55:53 -0700361 }
Ihab Awadff7493a2014-06-10 13:47:44 -0700362 call.reject(rejectWithMessage, textMessage);
Santos Cordon61d0f702014-02-19 02:52:23 -0800363 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800364 }
365
366 /**
Ihab Awad74549ec2014-03-10 15:33:25 -0700367 * Instructs Telecomm to play the specified DTMF tone within the specified call.
368 *
Ihab Awad74549ec2014-03-10 15:33:25 -0700369 * @param digit The DTMF digit to play.
370 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700371 void playDtmfTone(Call call, char digit) {
372 if (!mCalls.contains(call)) {
373 Log.i(this, "Request to play DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700374 } else {
375 call.playDtmfTone(digit);
Santos Cordon92a2d812014-04-30 15:19:01 -0700376 mDtmfLocalTonePlayer.playTone(call, digit);
Ihab Awad74549ec2014-03-10 15:33:25 -0700377 }
378 }
379
380 /**
381 * Instructs Telecomm to stop the currently playing DTMF tone, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -0700382 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700383 void stopDtmfTone(Call call) {
384 if (!mCalls.contains(call)) {
385 Log.i(this, "Request to stop DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700386 } else {
387 call.stopDtmfTone();
Santos Cordon92a2d812014-04-30 15:19:01 -0700388 mDtmfLocalTonePlayer.stopTone(call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700389 }
390 }
391
392 /**
Evan Charlton352105c2014-06-03 14:10:54 -0700393 * Instructs Telecomm to continue (or not) the current post-dial DTMF string, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -0700394 */
Evan Charlton352105c2014-06-03 14:10:54 -0700395 void postDialContinue(Call call, boolean proceed) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700396 if (!mCalls.contains(call)) {
397 Log.i(this, "Request to continue post-dial string in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700398 } else {
Evan Charlton352105c2014-06-03 14:10:54 -0700399 call.postDialContinue(proceed);
Ihab Awad74549ec2014-03-10 15:33:25 -0700400 }
401 }
402
403 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800404 * Instructs Telecomm to disconnect the specified call. Intended to be invoked by the
405 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
406 * the user hitting the end-call button.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800407 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700408 void disconnectCall(Call call) {
Santos Cordon682fe6b2014-05-20 08:56:39 -0700409 Log.v(this, "disconnectCall %s", call);
410
Sailesh Nepale59bb192014-04-01 18:33:59 -0700411 if (!mCalls.contains(call)) {
412 Log.w(this, "Unknown call (%s) asked to disconnect", call);
Santos Cordon049b7b62014-01-30 05:34:26 -0800413 } else {
414 call.disconnect();
415 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800416 }
Santos Cordon681663d2014-01-30 04:32:15 -0800417
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700418 /**
419 * Instructs Telecomm to put the specified call on hold. Intended to be invoked by the
420 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
421 * the user hitting the hold button during an active call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700422 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700423 void holdCall(Call call) {
424 if (!mCalls.contains(call)) {
425 Log.w(this, "Unknown call (%s) asked to be put on hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700426 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700427 Log.d(this, "Putting call on hold: (%s)", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700428 call.hold();
429 }
430 }
431
432 /**
433 * Instructs Telecomm to release the specified call from hold. Intended to be invoked by
434 * the in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered
435 * by the user hitting the hold button during a held call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700436 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700437 void unholdCall(Call call) {
438 if (!mCalls.contains(call)) {
439 Log.w(this, "Unknown call (%s) asked to be removed from hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700440 } else {
Santos Cordonc7e85d42014-05-22 02:51:48 -0700441 Log.d(this, "unholding call: (%s)", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700442 call.unhold();
443 }
444 }
445
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700446 /** Called by the in-call UI to change the mute state. */
447 void mute(boolean shouldMute) {
448 mCallAudioManager.mute(shouldMute);
449 }
450
451 /**
452 * Called by the in-call UI to change the audio route, for example to change from earpiece to
453 * speaker phone.
454 */
455 void setAudioRoute(int route) {
456 mCallAudioManager.setAudioRoute(route);
457 }
458
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700459 void startHandoffForCall(Call originalCall) {
460 if (!mCalls.contains(originalCall)) {
461 Log.w(this, "Unknown call %s asked to be handed off", originalCall);
462 return;
463 }
464
465 for (Call handoffCall : mPendingHandoffCalls) {
466 if (handoffCall.getOriginalCall() == originalCall) {
467 Log.w(this, "Call %s is already being handed off, skipping", originalCall);
468 return;
469 }
470 }
471
472 // Create a new call to be placed in the background. If handoff is successful then the
473 // original call will live on but its state will be updated to the new call's state. In
474 // particular the original call's call service will be updated to the new call's call
475 // service.
Santos Cordona1610702014-06-04 20:22:56 -0700476 Call tempCall = new Call(
477 originalCall.getHandoffHandle(), originalCall.getGatewayInfo(), false, false);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700478 tempCall.setOriginalCall(originalCall);
479 tempCall.setExtras(originalCall.getExtras());
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700480 mPendingHandoffCalls.add(tempCall);
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700481 tempCall.addListener(this);
482
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700483 Log.d(this, "Placing handoff call");
Santos Cordon766d04f2014-05-06 10:28:25 -0700484 tempCall.startOutgoing();
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700485 }
486
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700487 /** Called when the audio state changes. */
488 void onAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState) {
489 Log.v(this, "onAudioStateChanged, audioState: %s -> %s", oldAudioState, newAudioState);
Santos Cordona56f2762014-03-24 15:55:53 -0700490 for (CallsManagerListener listener : mListeners) {
491 listener.onAudioStateChanged(oldAudioState, newAudioState);
492 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700493 }
494
Sailesh Nepale59bb192014-04-01 18:33:59 -0700495 void markCallAsRinging(Call call) {
496 setCallState(call, CallState.RINGING);
Santos Cordon681663d2014-01-30 04:32:15 -0800497 }
498
Sailesh Nepale59bb192014-04-01 18:33:59 -0700499 void markCallAsDialing(Call call) {
500 setCallState(call, CallState.DIALING);
Santos Cordon681663d2014-01-30 04:32:15 -0800501 }
502
Sailesh Nepale59bb192014-04-01 18:33:59 -0700503 void markCallAsActive(Call call) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700504 if (call.getConnectTimeMillis() == 0) {
505 call.setConnectTimeMillis(System.currentTimeMillis());
506 }
Sailesh Nepale59bb192014-04-01 18:33:59 -0700507 setCallState(call, CallState.ACTIVE);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700508
509 if (mPendingHandoffCalls.contains(call)) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700510 completeHandoff(call, true);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700511 }
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700512 if (call.getStartWithSpeakerphoneOn()) {
513 setAudioRoute(CallAudioState.ROUTE_SPEAKER);
514 }
Santos Cordon681663d2014-01-30 04:32:15 -0800515 }
516
Sailesh Nepale59bb192014-04-01 18:33:59 -0700517 void markCallAsOnHold(Call call) {
518 setCallState(call, CallState.ON_HOLD);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700519 }
520
Santos Cordon049b7b62014-01-30 05:34:26 -0800521 /**
522 * Marks the specified call as DISCONNECTED and notifies the in-call app. If this was the last
523 * live call, then also disconnect from the in-call controller.
524 *
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700525 * @param disconnectCause The disconnect reason, see {@link android.telephony.DisconnectCause}.
526 * @param disconnectMessage Optional call-service-provided message about the disconnect.
Santos Cordon049b7b62014-01-30 05:34:26 -0800527 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700528 void markCallAsDisconnected(Call call, int disconnectCause, String disconnectMessage) {
529 call.setDisconnectCause(disconnectCause, disconnectMessage);
530 setCallState(call, CallState.DISCONNECTED);
Sailesh Nepal4857f472014-04-07 22:26:27 -0700531
532 // Only remove the call if handoff is not pending.
533 if (call.getHandoffCallServiceDescriptor() == null) {
534 removeCall(call);
535 }
Ben Gilada0d9f752014-02-26 11:49:03 -0800536 }
537
Sailesh Nepal6ab6fb72014-04-01 20:03:19 -0700538 void setHandoffInfo(Call call, Uri handle, Bundle extras) {
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700539 if (!mCalls.contains(call)) {
540 Log.w(this, "Unknown call (%s) asked to set handoff info", call);
541 return;
542 }
543
544 if (extras == null) {
545 call.setExtras(Bundle.EMPTY);
546 } else {
547 call.setExtras(extras);
548 }
549
550 Uri oldHandle = call.getHandoffHandle();
551 Log.v(this, "set handoff handle %s -> %s, for call: %s", oldHandle, handle, call);
552 if (!areUriEqual(oldHandle, handle)) {
553 call.setHandoffHandle(handle);
554 for (CallsManagerListener listener : mListeners) {
555 listener.onCallHandoffHandleChanged(call, oldHandle, handle);
556 }
557 }
Sailesh Nepal6ab6fb72014-04-01 20:03:19 -0700558 }
559
Ben Gilada0d9f752014-02-26 11:49:03 -0800560 /**
Santos Cordon4b2c1192014-03-19 18:15:38 -0700561 * Cleans up any calls currently associated with the specified call service when the
562 * call-service binder disconnects unexpectedly.
563 *
564 * @param callService The call service that disconnected.
565 */
566 void handleCallServiceDeath(CallServiceWrapper callService) {
567 Preconditions.checkNotNull(callService);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700568 for (Call call : ImmutableList.copyOf(mCalls)) {
Santos Cordon4b2c1192014-03-19 18:15:38 -0700569 if (call.getCallService() == callService) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700570 markCallAsDisconnected(call, DisconnectCause.ERROR_UNSPECIFIED, null);
Santos Cordon4b2c1192014-03-19 18:15:38 -0700571 }
572 }
573 }
574
Santos Cordondeb8c892014-05-30 01:38:03 -0700575 boolean hasAnyCalls() {
576 return !mCalls.isEmpty();
577 }
578
Santos Cordonc7e85d42014-05-22 02:51:48 -0700579 boolean hasActiveOrHoldingCall() {
580 for (Call call : mCalls) {
581 CallState state = call.getState();
582 if (state == CallState.ACTIVE || state == CallState.ON_HOLD) {
583 return true;
584 }
585 }
586 return false;
587 }
588
589 boolean hasRingingCall() {
590 for (Call call : mCalls) {
591 if (call.getState() == CallState.RINGING) {
592 return true;
593 }
594 }
595 return false;
596 }
597
Santos Cordondeb8c892014-05-30 01:38:03 -0700598 boolean onMediaButton(int type) {
599 if (hasAnyCalls()) {
600 if (HeadsetMediaButton.SHORT_PRESS == type) {
601 Call ringingCall = getFirstCallWithState(CallState.RINGING);
602 if (ringingCall == null) {
603 mCallAudioManager.toggleMute();
604 return true;
605 } else {
606 ringingCall.answer();
607 return true;
608 }
609 } else if (HeadsetMediaButton.LONG_PRESS == type) {
610 Log.d(this, "handleHeadsetHook: longpress -> hangup");
611 Call callToHangup = getFirstCallWithState(
612 CallState.RINGING, CallState.DIALING, CallState.ACTIVE, CallState.ON_HOLD);
613 if (callToHangup != null) {
614 callToHangup.disconnect();
615 return true;
616 }
617 }
618 }
619 return false;
620 }
621
622 /**
Santos Cordon10838c22014-06-11 17:36:04 -0700623 * Checks to see if the specified call is the only high-level call and if so, enable the
624 * "Add-call" button. We allow you to add a second call but not a third or beyond.
625 *
626 * @param call The call to test for add-call.
627 * @return Whether the add-call feature should be enabled for the call.
628 */
629 protected boolean isAddCallCapable(Call call) {
630 if (call.getParentCall() != null) {
631 // Never true for child calls.
632 return false;
633 }
634
635 // Loop through all the other calls and there exists a top level (has no parent) call
636 // that is not the specified call, return false.
637 for (Call otherCall : mCalls) {
638 if (call != otherCall && otherCall.getParentCall() == null) {
639 return false;
640 }
641 }
642 return true;
643 }
644
645 /**
Santos Cordondeb8c892014-05-30 01:38:03 -0700646 * Returns the first call that it finds with the given states. The states are treated as having
647 * priority order so that any call with the first state will be returned before any call with
648 * states listed later in the parameter list.
649 */
650 private Call getFirstCallWithState(CallState... states) {
651 for (CallState currentState : states) {
652 for (Call call : mCalls) {
653 if (currentState == call.getState()) {
654 return call;
655 }
656 }
657 }
658 return null;
659 }
660
Santos Cordon4b2c1192014-03-19 18:15:38 -0700661 /**
Ben Gilada0d9f752014-02-26 11:49:03 -0800662 * Adds the specified call to the main list of live calls.
663 *
664 * @param call The call to add.
665 */
666 private void addCall(Call call) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700667 mCalls.add(call);
Santos Cordon40f78c22014-04-07 02:11:42 -0700668
669 // TODO(santoscordon): Update mForegroundCall prior to invoking
670 // onCallAdded for calls which immediately take the foreground (like the first call).
Santos Cordona56f2762014-03-24 15:55:53 -0700671 for (CallsManagerListener listener : mListeners) {
672 listener.onCallAdded(call);
673 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700674 updateForegroundCall();
Ben Gilada0d9f752014-02-26 11:49:03 -0800675 }
676
Sailesh Nepal810735e2014-03-18 18:15:46 -0700677 private void removeCall(Call call) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700678 // If a handoff is pending then the original call shouldn't be removed.
679 Preconditions.checkState(call.getHandoffCallServiceDescriptor() == null);
Santos Cordonc499c1c2014-04-14 17:13:14 -0700680 Log.v(this, "removeCall(%s)", call);
Sailesh Nepal4857f472014-04-07 22:26:27 -0700681
Santos Cordon766d04f2014-05-06 10:28:25 -0700682 call.removeListener(this);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700683 call.clearCallService();
Sailesh Nepale59bb192014-04-01 18:33:59 -0700684
685 boolean shouldNotify = false;
686 if (mCalls.contains(call)) {
687 mCalls.remove(call);
688 shouldNotify = true;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700689 } else if (mPendingHandoffCalls.contains(call)) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700690 Log.v(this, "removeCall, marking handoff call as failed");
691 completeHandoff(call, false);
Santos Cordona56f2762014-03-24 15:55:53 -0700692 }
Ben Gilada0d9f752014-02-26 11:49:03 -0800693
Sailesh Nepale59bb192014-04-01 18:33:59 -0700694 // Only broadcast changes for calls that are being tracked.
695 if (shouldNotify) {
696 for (CallsManagerListener listener : mListeners) {
697 listener.onCallRemoved(call);
698 }
699 updateForegroundCall();
Sailesh Nepal810735e2014-03-18 18:15:46 -0700700 }
701 }
Evan Charlton5c670a92014-03-06 14:58:20 -0800702
Sailesh Nepal810735e2014-03-18 18:15:46 -0700703 /**
Santos Cordon1ae2b852014-03-19 03:03:10 -0700704 * Sets the specified state on the specified call.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700705 *
706 * @param call The call.
707 * @param newState The new state of the call.
708 */
709 private void setCallState(Call call, CallState newState) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700710 Preconditions.checkNotNull(newState);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700711 CallState oldState = call.getState();
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700712 Log.i(this, "setCallState %s -> %s, call: %s", oldState, newState, call);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700713 if (newState != oldState) {
714 // Unfortunately, in the telephony world the radio is king. So if the call notifies
715 // us that the call is in a particular state, we allow it even if it doesn't make
716 // sense (e.g., ACTIVE -> RINGING).
717 // TODO(santoscordon): Consider putting a stop to the above and turning CallState
718 // into a well-defined state machine.
719 // TODO(santoscordon): Define expected state transitions here, and log when an
720 // unexpected transition occurs.
721 call.setState(newState);
722
723 // Only broadcast state change for calls that are being tracked.
Sailesh Nepale59bb192014-04-01 18:33:59 -0700724 if (mCalls.contains(call)) {
Santos Cordona56f2762014-03-24 15:55:53 -0700725 for (CallsManagerListener listener : mListeners) {
726 listener.onCallStateChanged(call, oldState, newState);
727 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700728 updateForegroundCall();
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800729 }
730 }
731 }
732
733 /**
Sailesh Nepal810735e2014-03-18 18:15:46 -0700734 * Checks which call should be visible to the user and have audio focus.
Evan Charlton5c670a92014-03-06 14:58:20 -0800735 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700736 private void updateForegroundCall() {
737 Call newForegroundCall = null;
Sailesh Nepale59bb192014-04-01 18:33:59 -0700738 for (Call call : mCalls) {
Santos Cordon40f78c22014-04-07 02:11:42 -0700739 // TODO(santoscordon): Foreground-ness needs to be explicitly set. No call, regardless
740 // of its state will be foreground by default and instead the call service should be
741 // notified when its calls enter and exit foreground state. Foreground will mean that
742 // the call should play audio and listen to microphone if it wants.
743
744 // Active calls have priority.
745 if (call.isActive()) {
Sailesh Nepal810735e2014-03-18 18:15:46 -0700746 newForegroundCall = call;
Evan Charlton5c670a92014-03-06 14:58:20 -0800747 break;
Sailesh Nepal810735e2014-03-18 18:15:46 -0700748 }
Santos Cordon40f78c22014-04-07 02:11:42 -0700749
750 if (call.isAlive() || call.getState() == CallState.RINGING) {
Sailesh Nepal810735e2014-03-18 18:15:46 -0700751 newForegroundCall = call;
Santos Cordon40f78c22014-04-07 02:11:42 -0700752 // Don't break in case there's an active call that has priority.
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800753 }
754 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800755
Sailesh Nepal810735e2014-03-18 18:15:46 -0700756 if (newForegroundCall != mForegroundCall) {
Santos Cordon40f78c22014-04-07 02:11:42 -0700757 Log.v(this, "Updating foreground call, %s -> %s.", mForegroundCall, newForegroundCall);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700758 Call oldForegroundCall = mForegroundCall;
759 mForegroundCall = newForegroundCall;
760
Santos Cordona56f2762014-03-24 15:55:53 -0700761 for (CallsManagerListener listener : mListeners) {
762 listener.onForegroundCallChanged(oldForegroundCall, mForegroundCall);
763 }
Santos Cordon681663d2014-01-30 04:32:15 -0800764 }
765 }
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700766
Sailesh Nepal4857f472014-04-07 22:26:27 -0700767 private void completeHandoff(Call handoffCall, boolean wasSuccessful) {
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700768 Call originalCall = handoffCall.getOriginalCall();
Sailesh Nepal4857f472014-04-07 22:26:27 -0700769 Log.v(this, "complete handoff, %s -> %s, wasSuccessful: %b", handoffCall, originalCall,
770 wasSuccessful);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700771
Sailesh Nepal4857f472014-04-07 22:26:27 -0700772 // Remove the transient handoff call object (don't disconnect because the call could still
773 // be live).
774 mPendingHandoffCalls.remove(handoffCall);
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700775 handoffCall.removeListener(this);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700776
Sailesh Nepal4857f472014-04-07 22:26:27 -0700777 if (wasSuccessful) {
Sailesh Nepaldcd64262014-05-23 17:03:28 -0700778 if (TelephonyUtil.isCurrentlyPSTNCall(originalCall)) {
779 originalCall.disconnect();
780 }
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700781
Sailesh Nepal4857f472014-04-07 22:26:27 -0700782 // Synchronize.
783 originalCall.setCallService(handoffCall.getCallService(), handoffCall);
784 setCallState(originalCall, handoffCall.getState());
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700785
Sailesh Nepal4857f472014-04-07 22:26:27 -0700786 // Force the foreground call changed notification to be sent.
787 for (CallsManagerListener listener : mListeners) {
788 listener.onForegroundCallChanged(mForegroundCall, mForegroundCall);
789 }
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700790
Sailesh Nepal4857f472014-04-07 22:26:27 -0700791 updateHandoffCallServiceDescriptor(originalCall, null);
792 } else {
793 updateHandoffCallServiceDescriptor(originalCall, null);
794 if (originalCall.getState() == CallState.DISCONNECTED ||
795 originalCall.getState() == CallState.ABORTED) {
796 removeCall(originalCall);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700797 }
798 }
799 }
800
Sailesh Nepal4857f472014-04-07 22:26:27 -0700801 private void updateHandoffCallServiceDescriptor(
802 Call originalCall,
803 CallServiceDescriptor newDescriptor) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700804 CallServiceDescriptor oldDescriptor = originalCall.getHandoffCallServiceDescriptor();
Sailesh Nepal4857f472014-04-07 22:26:27 -0700805 Log.v(this, "updateHandoffCallServiceDescriptor, call: %s, pending descriptor: %s -> %s",
806 originalCall, oldDescriptor, newDescriptor);
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700807
808 if (!areDescriptorsEqual(oldDescriptor, newDescriptor)) {
809 originalCall.setHandoffCallServiceDescriptor(newDescriptor);
810 for (CallsManagerListener listener : mListeners) {
811 listener.onCallHandoffCallServiceDescriptorChanged(originalCall, oldDescriptor,
812 newDescriptor);
813 }
814 }
815 }
816
817 private static boolean areDescriptorsEqual(
818 CallServiceDescriptor descriptor1,
819 CallServiceDescriptor descriptor2) {
820 if (descriptor1 == null) {
821 return descriptor2 == null;
822 }
823 return descriptor1.equals(descriptor2);
824 }
825
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700826 private static boolean areUriEqual(Uri handle1, Uri handle2) {
827 if (handle1 == null) {
828 return handle2 == null;
829 }
830 return handle1.equals(handle2);
831 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800832}