blob: 5753d187e4f0f621015e9732d9d57a40b4fb643f [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
Ihab Awad0fea3f22014-06-03 18:45:05 -0700148 public void onFailedOutgoingCall(Call call, boolean isAborted, int errorCode, String errorMsg) {
Santos Cordon766d04f2014-05-06 10:28:25 -0700149 Log.v(this, "onFailedOutgoingCall, call: %s, isAborted: %b", call, isAborted);
150 if (isAborted) {
151 setCallState(call, CallState.ABORTED);
152 removeCall(call);
153 } else {
154 // TODO: Replace disconnect cause with more specific disconnect causes.
Ihab Awad0fea3f22014-06-03 18:45:05 -0700155 markCallAsDisconnected(call, errorCode, errorMsg);
Santos Cordon766d04f2014-05-06 10:28:25 -0700156 }
157 }
158
159 @Override
160 public void onSuccessfulIncomingCall(Call call, CallInfo callInfo) {
161 Log.d(this, "onSuccessfulIncomingCall");
162 setCallState(call, callInfo.getState());
163 addCall(call);
164 }
165
166 @Override
167 public void onFailedIncomingCall(Call call) {
168 call.removeListener(this);
Ben Gilada0d9f752014-02-26 11:49:03 -0800169 }
170
Ihab Awadcb387ac2014-05-28 16:49:38 -0700171 @Override
Santos Cordona1610702014-06-04 20:22:56 -0700172 public void onIsConferenceCapableChanged(Call call, boolean isConferenceCapable) {
173 for (CallsManagerListener listener : mListeners) {
174 listener.onIsConferenceCapableChanged(call, isConferenceCapable);
175 }
176 }
177
178 @Override
Ihab Awadcb387ac2014-05-28 16:49:38 -0700179 public void onRequestingRingback(Call call, boolean ringback) {
180 for (CallsManagerListener listener : mListeners) {
181 listener.onRequestingRingback(call, ringback);
182 }
183 }
184
Evan Charlton352105c2014-06-03 14:10:54 -0700185 @Override
186 public void onPostDialWait(Call call, String remaining) {
187 mInCallController.onPostDialWait(call, remaining);
188 }
189
Santos Cordona1610702014-06-04 20:22:56 -0700190 @Override
191 public void onExpiredConferenceCall(Call call) {
192 call.removeListener(this);
193 }
194
195 @Override
196 public void onConfirmedConferenceCall(Call call) {
197 addCall(call);
198 Log.v(this, "confirming Conf call %s", call);
199 for (CallsManagerListener listener : mListeners) {
200 listener.onIsConferencedChanged(call);
201 }
202 }
203
204 @Override
205 public void onParentChanged(Call call) {
206 for (CallsManagerListener listener : mListeners) {
207 listener.onIsConferencedChanged(call);
208 }
209 }
210
211 @Override
212 public void onChildrenChanged(Call call) {
213 for (CallsManagerListener listener : mListeners) {
214 listener.onIsConferencedChanged(call);
215 }
216 }
217
Ihab Awadff7493a2014-06-10 13:47:44 -0700218 @Override
219 public void onCannedSmsResponsesLoaded(Call call) {
220 for (CallsManagerListener listener : mListeners) {
221 listener.onCannedSmsResponsesLoaded(call);
222 }
223 }
224
Sailesh Nepal810735e2014-03-18 18:15:46 -0700225 ImmutableCollection<Call> getCalls() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700226 return ImmutableList.copyOf(mCalls);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700227 }
228
229 Call getForegroundCall() {
230 return mForegroundCall;
231 }
232
Santos Cordonae193062014-05-21 21:21:49 -0700233 Ringer getRinger() {
234 return mRinger;
235 }
236
Santos Cordonf3671a62014-05-29 21:51:53 -0700237 InCallController getInCallController() {
238 return mInCallController;
239 }
240
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700241 boolean hasEmergencyCall() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700242 for (Call call : mCalls) {
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700243 if (call.isEmergencyCall()) {
244 return true;
245 }
246 }
247 return false;
248 }
249
250 CallAudioState getAudioState() {
251 return mCallAudioManager.getAudioState();
252 }
253
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800254 /**
Santos Cordon493e8f22014-02-19 03:15:12 -0800255 * Starts the incoming call sequence by having switchboard gather more information about the
256 * specified call; using the specified call service descriptor. Upon success, execution returns
Santos Cordon766d04f2014-05-06 10:28:25 -0700257 * to {@link #onSuccessfulIncomingCall} to start the in-call UI.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800258 *
Ben Giladc5b22692014-02-18 20:03:22 -0800259 * @param descriptor The descriptor of the call service to use for this incoming call.
Evan Charltona05805b2014-03-05 08:21:46 -0800260 * @param extras The optional extras Bundle passed with the intent used for the incoming call.
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800261 */
Evan Charltona05805b2014-03-05 08:21:46 -0800262 void processIncomingCallIntent(CallServiceDescriptor descriptor, Bundle extras) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800263 Log.d(this, "processIncomingCallIntent");
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800264 // Create a call with no handle. Eventually, switchboard will update the call with
Sailesh Nepale59bb192014-04-01 18:33:59 -0700265 // additional information from the call service, but for now we just need one to pass
266 // around.
Santos Cordona1610702014-06-04 20:22:56 -0700267 Call call = new Call(true /* isIncoming */, false /* isConference */);
Santos Cordon766d04f2014-05-06 10:28:25 -0700268 // TODO(santoscordon): Move this to be a part of addCall()
269 call.addListener(this);
Santos Cordon80d9bdc2014-02-13 18:28:46 -0800270
Santos Cordon766d04f2014-05-06 10:28:25 -0700271 call.startIncoming(descriptor, extras);
Ben Gilada0d9f752014-02-26 11:49:03 -0800272 }
273
274 /**
Yorke Lee33501632014-03-17 19:24:12 -0700275 * Attempts to issue/connect the specified call.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800276 *
Yorke Lee33501632014-03-17 19:24:12 -0700277 * @param handle Handle to connect the call with.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800278 * @param contactInfo Information about the entity being called.
Yorke Lee33501632014-03-17 19:24:12 -0700279 * @param gatewayInfo Optional gateway information that can be used to route the call to the
Santos Cordon5b7b9b32014-03-26 14:00:22 -0700280 * actual dialed handle via a gateway provider. May be null.
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700281 * @param speakerphoneOn Whether or not to turn the speakerphone on once the call connects.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800282 */
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700283 void placeOutgoingCall(Uri handle, ContactInfo contactInfo, GatewayInfo gatewayInfo,
284 boolean speakerphoneOn) {
Yorke Lee33501632014-03-17 19:24:12 -0700285 final Uri uriHandle = (gatewayInfo == null) ? handle : gatewayInfo.getGatewayHandle();
286
287 if (gatewayInfo == null) {
Santos Cordonb58f4532014-05-29 11:59:06 -0700288 Log.i(this, "Creating a new outgoing call with handle: %s", Log.piiHandle(uriHandle));
Yorke Lee33501632014-03-17 19:24:12 -0700289 } else {
290 Log.i(this, "Creating a new outgoing call with gateway handle: %s, original handle: %s",
291 Log.pii(uriHandle), Log.pii(handle));
292 }
Santos Cordon766d04f2014-05-06 10:28:25 -0700293
Santos Cordona1610702014-06-04 20:22:56 -0700294 Call call = new Call(
295 uriHandle, gatewayInfo, false /* isIncoming */, false /* isConference */);
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700296 call.setStartWithSpeakerphoneOn(speakerphoneOn);
Santos Cordon766d04f2014-05-06 10:28:25 -0700297
298 // TODO(santoscordon): Move this to be a part of addCall()
299 call.addListener(this);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700300 addCall(call);
Santos Cordone3d76ab2014-01-28 17:25:20 -0800301
Santos Cordon766d04f2014-05-06 10:28:25 -0700302 call.startOutgoing();
Yorke Leef98fb572014-03-05 10:56:55 -0800303 }
304
305 /**
Santos Cordona1610702014-06-04 20:22:56 -0700306 * Attempts to start a conference call for the specified call.
307 *
308 * @param call The call to conference with.
309 */
310 void conference(Call call) {
311 Call conferenceCall = new Call(false, true);
312 conferenceCall.addListener(this);
313 call.conferenceInto(conferenceCall);
314 }
315
316 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800317 * Instructs Telecomm to answer the specified call. Intended to be invoked by the in-call
318 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
319 * the user opting to answer said call.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800320 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700321 void answerCall(Call call) {
322 if (!mCalls.contains(call)) {
323 Log.i(this, "Request to answer a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800324 } else {
Santos Cordon40f78c22014-04-07 02:11:42 -0700325 // If the foreground call is not the ringing call and it is currently isActive() or
326 // DIALING, put it on hold before answering the call.
327 if (mForegroundCall != null && mForegroundCall != call &&
328 (mForegroundCall.isActive() ||
329 mForegroundCall.getState() == CallState.DIALING)) {
330 Log.v(this, "Holding active/dialing call %s before answering incoming call %s.",
331 mForegroundCall, call);
332 mForegroundCall.hold();
333 // TODO(santoscordon): Wait until we get confirmation of the active call being
334 // on-hold before answering the new call.
335 // TODO(santoscordon): Import logic from CallManager.acceptCall()
336 }
337
Santos Cordona56f2762014-03-24 15:55:53 -0700338 for (CallsManagerListener listener : mListeners) {
339 listener.onIncomingCallAnswered(call);
340 }
Santos Cordon4e9fffe2014-03-04 18:13:41 -0800341
Santos Cordon61d0f702014-02-19 02:52:23 -0800342 // We do not update the UI until we get confirmation of the answer() through
Sailesh Nepale59bb192014-04-01 18:33:59 -0700343 // {@link #markCallAsActive}.
Santos Cordon61d0f702014-02-19 02:52:23 -0800344 call.answer();
345 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800346 }
347
348 /**
349 * Instructs Telecomm to reject the specified call. Intended to be invoked by the in-call
350 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
351 * the user opting to reject said call.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800352 */
Ihab Awadff7493a2014-06-10 13:47:44 -0700353 void rejectCall(Call call, boolean rejectWithMessage, String textMessage) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700354 if (!mCalls.contains(call)) {
355 Log.i(this, "Request to reject a non-existent call %s", call);
Santos Cordon61d0f702014-02-19 02:52:23 -0800356 } else {
Santos Cordona56f2762014-03-24 15:55:53 -0700357 for (CallsManagerListener listener : mListeners) {
Ihab Awadff7493a2014-06-10 13:47:44 -0700358 listener.onIncomingCallRejected(call, rejectWithMessage, textMessage);
Santos Cordona56f2762014-03-24 15:55:53 -0700359 }
Ihab Awadff7493a2014-06-10 13:47:44 -0700360 call.reject(rejectWithMessage, textMessage);
Santos Cordon61d0f702014-02-19 02:52:23 -0800361 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800362 }
363
364 /**
Ihab Awad74549ec2014-03-10 15:33:25 -0700365 * Instructs Telecomm to play the specified DTMF tone within the specified call.
366 *
Ihab Awad74549ec2014-03-10 15:33:25 -0700367 * @param digit The DTMF digit to play.
368 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700369 void playDtmfTone(Call call, char digit) {
370 if (!mCalls.contains(call)) {
371 Log.i(this, "Request to play DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700372 } else {
373 call.playDtmfTone(digit);
Santos Cordon92a2d812014-04-30 15:19:01 -0700374 mDtmfLocalTonePlayer.playTone(call, digit);
Ihab Awad74549ec2014-03-10 15:33:25 -0700375 }
376 }
377
378 /**
379 * Instructs Telecomm to stop the currently playing DTMF tone, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -0700380 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700381 void stopDtmfTone(Call call) {
382 if (!mCalls.contains(call)) {
383 Log.i(this, "Request to stop DTMF in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700384 } else {
385 call.stopDtmfTone();
Santos Cordon92a2d812014-04-30 15:19:01 -0700386 mDtmfLocalTonePlayer.stopTone(call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700387 }
388 }
389
390 /**
Evan Charlton352105c2014-06-03 14:10:54 -0700391 * Instructs Telecomm to continue (or not) the current post-dial DTMF string, if any.
Ihab Awad74549ec2014-03-10 15:33:25 -0700392 */
Evan Charlton352105c2014-06-03 14:10:54 -0700393 void postDialContinue(Call call, boolean proceed) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700394 if (!mCalls.contains(call)) {
395 Log.i(this, "Request to continue post-dial string in a non-existent call %s", call);
Ihab Awad74549ec2014-03-10 15:33:25 -0700396 } else {
Evan Charlton352105c2014-06-03 14:10:54 -0700397 call.postDialContinue(proceed);
Ihab Awad74549ec2014-03-10 15:33:25 -0700398 }
399 }
400
401 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800402 * Instructs Telecomm to disconnect the specified call. Intended to be invoked by the
403 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
404 * the user hitting the end-call button.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800405 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700406 void disconnectCall(Call call) {
Santos Cordon682fe6b2014-05-20 08:56:39 -0700407 Log.v(this, "disconnectCall %s", call);
408
Sailesh Nepale59bb192014-04-01 18:33:59 -0700409 if (!mCalls.contains(call)) {
410 Log.w(this, "Unknown call (%s) asked to disconnect", call);
Santos Cordon049b7b62014-01-30 05:34:26 -0800411 } else {
412 call.disconnect();
413 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800414 }
Santos Cordon681663d2014-01-30 04:32:15 -0800415
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700416 /**
417 * Instructs Telecomm to put the specified call on hold. Intended to be invoked by the
418 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
419 * the user hitting the hold button during an active call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700420 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700421 void holdCall(Call call) {
422 if (!mCalls.contains(call)) {
423 Log.w(this, "Unknown call (%s) asked to be put on hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700424 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700425 Log.d(this, "Putting call on hold: (%s)", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700426 call.hold();
427 }
428 }
429
430 /**
431 * Instructs Telecomm to release the specified call from hold. Intended to be invoked by
432 * the in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered
433 * by the user hitting the hold button during a held call.
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700434 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700435 void unholdCall(Call call) {
436 if (!mCalls.contains(call)) {
437 Log.w(this, "Unknown call (%s) asked to be removed from hold", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700438 } else {
Santos Cordonc7e85d42014-05-22 02:51:48 -0700439 Log.d(this, "unholding call: (%s)", call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700440 call.unhold();
441 }
442 }
443
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700444 /** Called by the in-call UI to change the mute state. */
445 void mute(boolean shouldMute) {
446 mCallAudioManager.mute(shouldMute);
447 }
448
449 /**
450 * Called by the in-call UI to change the audio route, for example to change from earpiece to
451 * speaker phone.
452 */
453 void setAudioRoute(int route) {
454 mCallAudioManager.setAudioRoute(route);
455 }
456
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700457 void startHandoffForCall(Call originalCall) {
458 if (!mCalls.contains(originalCall)) {
459 Log.w(this, "Unknown call %s asked to be handed off", originalCall);
460 return;
461 }
462
463 for (Call handoffCall : mPendingHandoffCalls) {
464 if (handoffCall.getOriginalCall() == originalCall) {
465 Log.w(this, "Call %s is already being handed off, skipping", originalCall);
466 return;
467 }
468 }
469
470 // Create a new call to be placed in the background. If handoff is successful then the
471 // original call will live on but its state will be updated to the new call's state. In
472 // particular the original call's call service will be updated to the new call's call
473 // service.
Santos Cordona1610702014-06-04 20:22:56 -0700474 Call tempCall = new Call(
475 originalCall.getHandoffHandle(), originalCall.getGatewayInfo(), false, false);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700476 tempCall.setOriginalCall(originalCall);
477 tempCall.setExtras(originalCall.getExtras());
478 tempCall.setCallServiceSelector(originalCall.getCallServiceSelector());
479 mPendingHandoffCalls.add(tempCall);
Santos Cordon6cb7ba92014-05-23 14:09:32 -0700480 tempCall.addListener(this);
481
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700482 Log.d(this, "Placing handoff call");
Santos Cordon766d04f2014-05-06 10:28:25 -0700483 tempCall.startOutgoing();
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700484 }
485
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700486 /** Called when the audio state changes. */
487 void onAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState) {
488 Log.v(this, "onAudioStateChanged, audioState: %s -> %s", oldAudioState, newAudioState);
Santos Cordona56f2762014-03-24 15:55:53 -0700489 for (CallsManagerListener listener : mListeners) {
490 listener.onAudioStateChanged(oldAudioState, newAudioState);
491 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700492 }
493
Sailesh Nepale59bb192014-04-01 18:33:59 -0700494 void markCallAsRinging(Call call) {
495 setCallState(call, CallState.RINGING);
Santos Cordon681663d2014-01-30 04:32:15 -0800496 }
497
Sailesh Nepale59bb192014-04-01 18:33:59 -0700498 void markCallAsDialing(Call call) {
499 setCallState(call, CallState.DIALING);
Santos Cordon681663d2014-01-30 04:32:15 -0800500 }
501
Sailesh Nepale59bb192014-04-01 18:33:59 -0700502 void markCallAsActive(Call call) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700503 if (call.getConnectTimeMillis() == 0) {
504 call.setConnectTimeMillis(System.currentTimeMillis());
505 }
Sailesh Nepale59bb192014-04-01 18:33:59 -0700506 setCallState(call, CallState.ACTIVE);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700507
508 if (mPendingHandoffCalls.contains(call)) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700509 completeHandoff(call, true);
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700510 }
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700511 if (call.getStartWithSpeakerphoneOn()) {
512 setAudioRoute(CallAudioState.ROUTE_SPEAKER);
513 }
Santos Cordon681663d2014-01-30 04:32:15 -0800514 }
515
Sailesh Nepale59bb192014-04-01 18:33:59 -0700516 void markCallAsOnHold(Call call) {
517 setCallState(call, CallState.ON_HOLD);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700518 }
519
Santos Cordon049b7b62014-01-30 05:34:26 -0800520 /**
521 * Marks the specified call as DISCONNECTED and notifies the in-call app. If this was the last
522 * live call, then also disconnect from the in-call controller.
523 *
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700524 * @param disconnectCause The disconnect reason, see {@link android.telephony.DisconnectCause}.
525 * @param disconnectMessage Optional call-service-provided message about the disconnect.
Santos Cordon049b7b62014-01-30 05:34:26 -0800526 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700527 void markCallAsDisconnected(Call call, int disconnectCause, String disconnectMessage) {
528 call.setDisconnectCause(disconnectCause, disconnectMessage);
529 setCallState(call, CallState.DISCONNECTED);
Sailesh Nepal4857f472014-04-07 22:26:27 -0700530
531 // Only remove the call if handoff is not pending.
532 if (call.getHandoffCallServiceDescriptor() == null) {
533 removeCall(call);
534 }
Ben Gilada0d9f752014-02-26 11:49:03 -0800535 }
536
Sailesh Nepal6ab6fb72014-04-01 20:03:19 -0700537 void setHandoffInfo(Call call, Uri handle, Bundle extras) {
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700538 if (!mCalls.contains(call)) {
539 Log.w(this, "Unknown call (%s) asked to set handoff info", call);
540 return;
541 }
542
543 if (extras == null) {
544 call.setExtras(Bundle.EMPTY);
545 } else {
546 call.setExtras(extras);
547 }
548
549 Uri oldHandle = call.getHandoffHandle();
550 Log.v(this, "set handoff handle %s -> %s, for call: %s", oldHandle, handle, call);
551 if (!areUriEqual(oldHandle, handle)) {
552 call.setHandoffHandle(handle);
553 for (CallsManagerListener listener : mListeners) {
554 listener.onCallHandoffHandleChanged(call, oldHandle, handle);
555 }
556 }
Sailesh Nepal6ab6fb72014-04-01 20:03:19 -0700557 }
558
Ben Gilada0d9f752014-02-26 11:49:03 -0800559 /**
Santos Cordon4b2c1192014-03-19 18:15:38 -0700560 * Cleans up any calls currently associated with the specified call service when the
561 * call-service binder disconnects unexpectedly.
562 *
563 * @param callService The call service that disconnected.
564 */
565 void handleCallServiceDeath(CallServiceWrapper callService) {
566 Preconditions.checkNotNull(callService);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700567 for (Call call : ImmutableList.copyOf(mCalls)) {
Santos Cordon4b2c1192014-03-19 18:15:38 -0700568 if (call.getCallService() == callService) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700569 markCallAsDisconnected(call, DisconnectCause.ERROR_UNSPECIFIED, null);
Santos Cordon4b2c1192014-03-19 18:15:38 -0700570 }
571 }
572 }
573
Santos Cordondeb8c892014-05-30 01:38:03 -0700574 boolean hasAnyCalls() {
575 return !mCalls.isEmpty();
576 }
577
Santos Cordonc7e85d42014-05-22 02:51:48 -0700578 boolean hasActiveOrHoldingCall() {
579 for (Call call : mCalls) {
580 CallState state = call.getState();
581 if (state == CallState.ACTIVE || state == CallState.ON_HOLD) {
582 return true;
583 }
584 }
585 return false;
586 }
587
588 boolean hasRingingCall() {
589 for (Call call : mCalls) {
590 if (call.getState() == CallState.RINGING) {
591 return true;
592 }
593 }
594 return false;
595 }
596
Santos Cordondeb8c892014-05-30 01:38:03 -0700597 boolean onMediaButton(int type) {
598 if (hasAnyCalls()) {
599 if (HeadsetMediaButton.SHORT_PRESS == type) {
600 Call ringingCall = getFirstCallWithState(CallState.RINGING);
601 if (ringingCall == null) {
602 mCallAudioManager.toggleMute();
603 return true;
604 } else {
605 ringingCall.answer();
606 return true;
607 }
608 } else if (HeadsetMediaButton.LONG_PRESS == type) {
609 Log.d(this, "handleHeadsetHook: longpress -> hangup");
610 Call callToHangup = getFirstCallWithState(
611 CallState.RINGING, CallState.DIALING, CallState.ACTIVE, CallState.ON_HOLD);
612 if (callToHangup != null) {
613 callToHangup.disconnect();
614 return true;
615 }
616 }
617 }
618 return false;
619 }
620
621 /**
Santos Cordon10838c22014-06-11 17:36:04 -0700622 * Checks to see if the specified call is the only high-level call and if so, enable the
623 * "Add-call" button. We allow you to add a second call but not a third or beyond.
624 *
625 * @param call The call to test for add-call.
626 * @return Whether the add-call feature should be enabled for the call.
627 */
628 protected boolean isAddCallCapable(Call call) {
629 if (call.getParentCall() != null) {
630 // Never true for child calls.
631 return false;
632 }
633
634 // Loop through all the other calls and there exists a top level (has no parent) call
635 // that is not the specified call, return false.
636 for (Call otherCall : mCalls) {
637 if (call != otherCall && otherCall.getParentCall() == null) {
638 return false;
639 }
640 }
641 return true;
642 }
643
644 /**
Santos Cordondeb8c892014-05-30 01:38:03 -0700645 * Returns the first call that it finds with the given states. The states are treated as having
646 * priority order so that any call with the first state will be returned before any call with
647 * states listed later in the parameter list.
648 */
649 private Call getFirstCallWithState(CallState... states) {
650 for (CallState currentState : states) {
651 for (Call call : mCalls) {
652 if (currentState == call.getState()) {
653 return call;
654 }
655 }
656 }
657 return null;
658 }
659
Santos Cordon4b2c1192014-03-19 18:15:38 -0700660 /**
Ben Gilada0d9f752014-02-26 11:49:03 -0800661 * Adds the specified call to the main list of live calls.
662 *
663 * @param call The call to add.
664 */
665 private void addCall(Call call) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700666 mCalls.add(call);
Santos Cordon40f78c22014-04-07 02:11:42 -0700667
668 // TODO(santoscordon): Update mForegroundCall prior to invoking
669 // onCallAdded for calls which immediately take the foreground (like the first call).
Santos Cordona56f2762014-03-24 15:55:53 -0700670 for (CallsManagerListener listener : mListeners) {
671 listener.onCallAdded(call);
672 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700673 updateForegroundCall();
Ben Gilada0d9f752014-02-26 11:49:03 -0800674 }
675
Sailesh Nepal810735e2014-03-18 18:15:46 -0700676 private void removeCall(Call call) {
Sailesh Nepal4857f472014-04-07 22:26:27 -0700677 // If a handoff is pending then the original call shouldn't be removed.
678 Preconditions.checkState(call.getHandoffCallServiceDescriptor() == null);
Santos Cordonc499c1c2014-04-14 17:13:14 -0700679 Log.v(this, "removeCall(%s)", call);
Sailesh Nepal4857f472014-04-07 22:26:27 -0700680
Santos Cordon766d04f2014-05-06 10:28:25 -0700681 call.removeListener(this);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700682 call.clearCallService();
Sailesh Nepale59bb192014-04-01 18:33:59 -0700683 call.clearCallServiceSelector();
684
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}