blob: 2e7bc4578c2dcef0c6050851a983792736446464 [file] [log] [blame]
Santos Cordone3d76ab2014-01-28 17:25:20 -08001/*
2 * Copyright (C) 2014 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
17package com.android.telecomm;
18
Tyler Gunn61b92102014-08-19 07:42:20 -070019import android.Manifest;
Sailesh Nepal9d58de52014-07-18 14:53:19 -070020import android.app.PendingIntent;
Santos Cordone3d76ab2014-01-28 17:25:20 -080021import android.content.ComponentName;
22import android.content.Context;
23import android.content.Intent;
24import android.content.ServiceConnection;
Tyler Gunn61b92102014-08-19 07:42:20 -070025import android.content.pm.PackageManager;
26import android.content.pm.ResolveInfo;
27import android.content.pm.ServiceInfo;
Santos Cordonfdfcafa2014-06-26 14:49:05 -070028import android.content.res.Resources;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070029import android.net.Uri;
Santos Cordone3d76ab2014-01-28 17:25:20 -080030import android.os.IBinder;
31import android.os.RemoteException;
Amith Yamasani60e75842014-05-23 10:09:14 -070032import android.os.UserHandle;
Ihab Awad6fb37c82014-08-07 19:48:57 -070033import android.telecomm.AudioState;
Tyler Gunn61b92102014-08-19 07:42:20 -070034import android.telecomm.CallState;
35import android.telecomm.InCallService;
36import android.telecomm.ParcelableCall;
Ihab Awad6fb37c82014-08-07 19:48:57 -070037import android.telecomm.PhoneCapabilities;
38import android.telecomm.PropertyPresentation;
Tyler Gunn61b92102014-08-19 07:42:20 -070039import android.util.ArrayMap;
Sailesh Nepala439e1b2014-03-11 18:19:58 -070040
41import com.android.internal.telecomm.IInCallService;
Sailesh Nepal810735e2014-03-18 18:15:46 -070042import com.google.common.collect.ImmutableCollection;
Santos Cordone3d76ab2014-01-28 17:25:20 -080043
Santos Cordona1610702014-06-04 20:22:56 -070044import java.util.ArrayList;
Tyler Gunn61b92102014-08-19 07:42:20 -070045import java.util.Iterator;
Santos Cordona1610702014-06-04 20:22:56 -070046import java.util.List;
Tyler Gunn61b92102014-08-19 07:42:20 -070047import java.util.Map;
48import java.util.concurrent.ConcurrentHashMap;
Santos Cordona1610702014-06-04 20:22:56 -070049
Santos Cordone3d76ab2014-01-28 17:25:20 -080050/**
51 * Binds to {@link IInCallService} and provides the service to {@link CallsManager} through which it
52 * can send updates to the in-call app. This class is created and owned by CallsManager and retains
Sailesh Nepale59bb192014-04-01 18:33:59 -070053 * a binding to the {@link IInCallService} (implemented by the in-call app).
Santos Cordone3d76ab2014-01-28 17:25:20 -080054 */
Sailesh Nepal810735e2014-03-18 18:15:46 -070055public final class InCallController extends CallsManagerListenerBase {
Santos Cordone3d76ab2014-01-28 17:25:20 -080056 /**
57 * Used to bind to the in-call app and triggers the start of communication between
Sailesh Nepale59bb192014-04-01 18:33:59 -070058 * this class and in-call app.
Santos Cordone3d76ab2014-01-28 17:25:20 -080059 */
60 private class InCallServiceConnection implements ServiceConnection {
61 /** {@inheritDoc} */
62 @Override public void onServiceConnected(ComponentName name, IBinder service) {
Tyler Gunn61b92102014-08-19 07:42:20 -070063 onConnected(name, service);
Santos Cordone3d76ab2014-01-28 17:25:20 -080064 }
65
66 /** {@inheritDoc} */
67 @Override public void onServiceDisconnected(ComponentName name) {
Tyler Gunn61b92102014-08-19 07:42:20 -070068 onDisconnected(name);
Santos Cordone3d76ab2014-01-28 17:25:20 -080069 }
70 }
71
Sailesh Nepale8ecb982014-07-11 17:19:42 -070072 private final Call.Listener mCallListener = new Call.ListenerBase() {
73 @Override
74 public void onCallCapabilitiesChanged(Call call) {
75 updateCall(call);
76 }
77
78 @Override
79 public void onCannedSmsResponsesLoaded(Call call) {
80 updateCall(call);
81 }
82
83 @Override
Andrew Lee3bcf9352014-07-23 12:36:05 -070084 public void onVideoCallProviderChanged(Call call) {
Sailesh Nepale8ecb982014-07-11 17:19:42 -070085 updateCall(call);
86 }
87
88 @Override
89 public void onStatusHintsChanged(Call call) {
90 updateCall(call);
91 }
92
93 @Override
94 public void onHandleChanged(Call call) {
95 updateCall(call);
96 }
97
98 @Override
99 public void onCallerDisplayNameChanged(Call call) {
100 updateCall(call);
101 }
Andrew Lee4a796602014-07-11 17:23:03 -0700102
103 @Override
104 public void onVideoStateChanged(Call call) {
105 updateCall(call);
106 }
Sailesh Nepal9d58de52014-07-18 14:53:19 -0700107
108 @Override
109 public void onStartActivityFromInCall(Call call, PendingIntent intent) {
Tyler Gunn61b92102014-08-19 07:42:20 -0700110 if (!mInCallServices.isEmpty()) {
Sailesh Nepal9d58de52014-07-18 14:53:19 -0700111 Log.i(this, "Calling startActivity, intent: %s", intent);
Tyler Gunn61b92102014-08-19 07:42:20 -0700112 for (IInCallService inCallService : mInCallServices.values()) {
113 try {
114 inCallService.startActivity(mCallIdMapper.getCallId(call), intent);
115 } catch (RemoteException ignored) {
116 }
Sailesh Nepal9d58de52014-07-18 14:53:19 -0700117 }
118 }
119 }
Ihab Awad69eb0f52014-07-18 11:20:37 -0700120
121 @Override
Ihab Awadb78b2762014-07-25 15:16:23 -0700122 public void onTargetPhoneAccountChanged(Call call) {
Ihab Awad69eb0f52014-07-18 11:20:37 -0700123 updateCall(call);
124 }
Santos Cordon12d61822014-07-29 16:02:20 -0700125
126 @Override
127 public void onConferenceableCallsChanged(Call call) {
128 updateCall(call);
129 }
Sailesh Nepale8ecb982014-07-11 17:19:42 -0700130 };
131
Tyler Gunn61b92102014-08-19 07:42:20 -0700132 /**
133 * Maintains a binding connection to the in-call app(s).
134 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
135 * load factor before resizing, 1 means we only expect a single thread to
136 * access the map so make only a single shard
137 */
138 private final Map<ComponentName, InCallServiceConnection> mServiceConnections =
139 new ConcurrentHashMap<ComponentName, InCallServiceConnection>(8, 0.9f, 1);
Santos Cordone3d76ab2014-01-28 17:25:20 -0800140
Tyler Gunn61b92102014-08-19 07:42:20 -0700141 /** The in-call app implementations, see {@link IInCallService}. */
142 private final Map<ComponentName, IInCallService> mInCallServices = new ArrayMap<>();
Santos Cordone3d76ab2014-01-28 17:25:20 -0800143
Sailesh Nepale59bb192014-04-01 18:33:59 -0700144 private final CallIdMapper mCallIdMapper = new CallIdMapper("InCall");
145
Tyler Gunn12bccad2014-08-21 13:52:03 -0700146 /** The {@link ComponentName} of the default InCall UI. */
Tyler Gunn61b92102014-08-19 07:42:20 -0700147 private ComponentName mInCallComponentName;
148
149 public InCallController() {
150 Context context = TelecommApp.getInstance();
151 Resources resources = context.getResources();
152
153 mInCallComponentName = new ComponentName(
154 resources.getString(R.string.ui_default_package),
155 resources.getString(R.string.incall_default_class));
Santos Cordone3d76ab2014-01-28 17:25:20 -0800156 }
157
Sailesh Nepal810735e2014-03-18 18:15:46 -0700158 @Override
159 public void onCallAdded(Call call) {
Tyler Gunn61b92102014-08-19 07:42:20 -0700160 if (mInCallServices.isEmpty()) {
Sailesh Nepal810735e2014-03-18 18:15:46 -0700161 bind();
162 } else {
163 Log.i(this, "Adding call: %s", call);
Tyler Gunn61b92102014-08-19 07:42:20 -0700164 // Track the call if we don't already know about it.
165 addCall(call);
166
Tyler Gunn12bccad2014-08-21 13:52:03 -0700167 for (Map.Entry<ComponentName, IInCallService> entry : mInCallServices.entrySet()) {
168 ComponentName componentName = entry.getKey();
169 IInCallService inCallService = entry.getValue();
170
171 ParcelableCall parcelableCall = toParcelableCall(call,
172 componentName.equals(mInCallComponentName) /* includeVideoProvider */);
Ihab Awadff7493a2014-06-10 13:47:44 -0700173 try {
Tyler Gunn61b92102014-08-19 07:42:20 -0700174 inCallService.addCall(parcelableCall);
Ihab Awadff7493a2014-06-10 13:47:44 -0700175 } catch (RemoteException ignored) {
176 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800177 }
Santos Cordon049b7b62014-01-30 05:34:26 -0800178 }
179 }
180
Sailesh Nepal810735e2014-03-18 18:15:46 -0700181 @Override
182 public void onCallRemoved(Call call) {
183 if (CallsManager.getInstance().getCalls().isEmpty()) {
Santos Cordondf399862014-08-06 04:39:15 -0700184 // TODO: Wait for all messages to be delivered to the service before unbinding.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700185 unbind();
Santos Cordon049b7b62014-01-30 05:34:26 -0800186 }
Sailesh Nepale8ecb982014-07-11 17:19:42 -0700187 call.removeListener(mCallListener);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700188 mCallIdMapper.removeCall(call);
Santos Cordon049b7b62014-01-30 05:34:26 -0800189 }
190
Sailesh Nepal810735e2014-03-18 18:15:46 -0700191 @Override
Ihab Awad6fb37c82014-08-07 19:48:57 -0700192 public void onCallStateChanged(Call call, int oldState, int newState) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700193 updateCall(call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700194 }
195
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700196 @Override
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700197 public void onConnectionServiceChanged(
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700198 Call call,
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700199 ConnectionServiceWrapper oldService,
200 ConnectionServiceWrapper newService) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700201 updateCall(call);
202 }
203
204 @Override
Ihab Awad6fb37c82014-08-07 19:48:57 -0700205 public void onAudioStateChanged(AudioState oldAudioState, AudioState newAudioState) {
Tyler Gunn61b92102014-08-19 07:42:20 -0700206 if (!mInCallServices.isEmpty()) {
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700207 Log.i(this, "Calling onAudioStateChanged, audioState: %s -> %s", oldAudioState,
208 newAudioState);
Tyler Gunn61b92102014-08-19 07:42:20 -0700209 for (IInCallService inCallService : mInCallServices.values()) {
210 try {
211 inCallService.onAudioStateChanged(newAudioState);
212 } catch (RemoteException ignored) {
213 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700214 }
215 }
216 }
217
Evan Charlton352105c2014-06-03 14:10:54 -0700218 void onPostDialWait(Call call, String remaining) {
Tyler Gunn61b92102014-08-19 07:42:20 -0700219 if (!mInCallServices.isEmpty()) {
Evan Charlton352105c2014-06-03 14:10:54 -0700220 Log.i(this, "Calling onPostDialWait, remaining = %s", remaining);
Tyler Gunn61b92102014-08-19 07:42:20 -0700221 for (IInCallService inCallService : mInCallServices.values()) {
222 try {
223 inCallService.setPostDialWait(mCallIdMapper.getCallId(call), remaining);
224 } catch (RemoteException ignored) {
225 }
Evan Charlton352105c2014-06-03 14:10:54 -0700226 }
227 }
228 }
229
Santos Cordona1610702014-06-04 20:22:56 -0700230 @Override
Santos Cordona1610702014-06-04 20:22:56 -0700231 public void onIsConferencedChanged(Call call) {
Santos Cordon0fbe6322014-08-14 04:04:25 -0700232 Log.d(this, "onIsConferencedChanged %s", call);
Santos Cordona1610702014-06-04 20:22:56 -0700233 updateCall(call);
234 }
235
Santos Cordonf3671a62014-05-29 21:51:53 -0700236 void bringToForeground(boolean showDialpad) {
Tyler Gunn61b92102014-08-19 07:42:20 -0700237 if (!mInCallServices.isEmpty()) {
238 for (IInCallService inCallService : mInCallServices.values()) {
239 try {
240 inCallService.bringToForeground(showDialpad);
241 } catch (RemoteException ignored) {
242 }
Santos Cordonf3671a62014-05-29 21:51:53 -0700243 }
244 } else {
245 Log.w(this, "Asking to bring unbound in-call UI to foreground.");
246 }
247 }
248
Santos Cordone3d76ab2014-01-28 17:25:20 -0800249 /**
250 * Unbinds an existing bound connection to the in-call app.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800251 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700252 private void unbind() {
Santos Cordone3d76ab2014-01-28 17:25:20 -0800253 ThreadUtil.checkOnMainThread();
Tyler Gunn61b92102014-08-19 07:42:20 -0700254 if (!mInCallServices.isEmpty()) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800255 Log.i(this, "Unbinding from InCallService");
Tyler Gunn61b92102014-08-19 07:42:20 -0700256 for (InCallServiceConnection connection : mServiceConnections.values()) {
257 TelecommApp.getInstance().unbindService(connection);
258 }
259 mInCallServices.clear();
Santos Cordone3d76ab2014-01-28 17:25:20 -0800260 }
261 }
262
263 /**
Santos Cordon049b7b62014-01-30 05:34:26 -0800264 * Binds to the in-call app if not already connected by binding directly to the saved
265 * component name of the {@link IInCallService} implementation.
266 */
267 private void bind() {
268 ThreadUtil.checkOnMainThread();
Tyler Gunn61b92102014-08-19 07:42:20 -0700269 if (mInCallServices.isEmpty()) {
270 mServiceConnections.clear();
Santos Cordonfdfcafa2014-06-26 14:49:05 -0700271 Context context = TelecommApp.getInstance();
Tyler Gunn61b92102014-08-19 07:42:20 -0700272 PackageManager packageManager = TelecommApp.getInstance().getPackageManager();
273 Intent intent = new Intent(InCallService.SERVICE_INTERFACE);
Santos Cordon049b7b62014-01-30 05:34:26 -0800274
Tyler Gunn61b92102014-08-19 07:42:20 -0700275 for (ResolveInfo entry : packageManager.queryIntentServices(intent, 0)) {
276 ServiceInfo serviceInfo = entry.serviceInfo;
277 if (serviceInfo != null) {
278 boolean hasServiceBindPermission = serviceInfo.permission != null &&
279 serviceInfo.permission.equals(
280 Manifest.permission.BIND_INCALL_SERVICE);
281 boolean hasControlInCallPermission = packageManager.checkPermission(
282 Manifest.permission.CONTROL_INCALL_EXPERIENCE,
283 serviceInfo.packageName) == PackageManager.PERMISSION_GRANTED;
Santos Cordon049b7b62014-01-30 05:34:26 -0800284
Tyler Gunn61b92102014-08-19 07:42:20 -0700285 if (!hasServiceBindPermission) {
286 Log.w(this, "InCallService does not have BIND_INCALL_SERVICE permission: " +
287 serviceInfo.packageName);
288 continue;
289 }
Santos Cordon049b7b62014-01-30 05:34:26 -0800290
Tyler Gunn61b92102014-08-19 07:42:20 -0700291 if (!hasControlInCallPermission) {
292 Log.w(this,
293 "InCall UI does not have CONTROL_INCALL_EXPERIENCE permission: " +
294 serviceInfo.packageName);
295 continue;
296 }
297
298 Log.i(this, "Attempting to bind to InCall " + serviceInfo.packageName);
299 InCallServiceConnection inCallServiceConnection = new InCallServiceConnection();
300 ComponentName componentName = new ComponentName(serviceInfo.packageName,
301 serviceInfo.name);
302 intent.setComponent(componentName);
303
304 if (context.bindServiceAsUser(intent, inCallServiceConnection,
305 Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
306 mServiceConnections.put(componentName, inCallServiceConnection);
307 }
308 }
Santos Cordon049b7b62014-01-30 05:34:26 -0800309 }
310 }
311 }
312
313 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800314 * Persists the {@link IInCallService} instance and starts the communication between
Sailesh Nepale59bb192014-04-01 18:33:59 -0700315 * this class and in-call app by sending the first update to in-call app. This method is
Santos Cordone3d76ab2014-01-28 17:25:20 -0800316 * called after a successful binding connection is established.
317 *
Tyler Gunn61b92102014-08-19 07:42:20 -0700318 * @param componentName The service {@link ComponentName}.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800319 * @param service The {@link IInCallService} implementation.
320 */
Tyler Gunn61b92102014-08-19 07:42:20 -0700321 private void onConnected(ComponentName componentName, IBinder service) {
Santos Cordone3d76ab2014-01-28 17:25:20 -0800322 ThreadUtil.checkOnMainThread();
Tyler Gunn61b92102014-08-19 07:42:20 -0700323
324 IInCallService inCallService = IInCallService.Stub.asInterface(service);
Santos Cordone3d76ab2014-01-28 17:25:20 -0800325
326 try {
Tyler Gunn61b92102014-08-19 07:42:20 -0700327 inCallService.setInCallAdapter(new InCallAdapter(CallsManager.getInstance(),
Sailesh Nepale59bb192014-04-01 18:33:59 -0700328 mCallIdMapper));
Tyler Gunn61b92102014-08-19 07:42:20 -0700329 mInCallServices.put(componentName, inCallService);
Santos Cordone3d76ab2014-01-28 17:25:20 -0800330 } catch (RemoteException e) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800331 Log.e(this, e, "Failed to set the in-call adapter.");
Sailesh Nepal810735e2014-03-18 18:15:46 -0700332 return;
Santos Cordone3d76ab2014-01-28 17:25:20 -0800333 }
334
Tyler Gunn61b92102014-08-19 07:42:20 -0700335 // Upon successful connection, send the state of the world to the service.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700336 ImmutableCollection<Call> calls = CallsManager.getInstance().getCalls();
337 if (!calls.isEmpty()) {
338 for (Call call : calls) {
Tyler Gunn61b92102014-08-19 07:42:20 -0700339 try {
340 // Track the call if we don't already know about it.
341 addCall(call);
342
Tyler Gunn12bccad2014-08-21 13:52:03 -0700343 inCallService.addCall(toParcelableCall(call,
344 componentName.equals(mInCallComponentName) /* includeVideoProvider */));
Tyler Gunn61b92102014-08-19 07:42:20 -0700345 } catch (RemoteException ignored) {
346 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700347 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700348 onAudioStateChanged(null, CallsManager.getInstance().getAudioState());
Sailesh Nepal810735e2014-03-18 18:15:46 -0700349 } else {
350 unbind();
Santos Cordon049b7b62014-01-30 05:34:26 -0800351 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800352 }
353
354 /**
Tyler Gunn61b92102014-08-19 07:42:20 -0700355 * Cleans up an instance of in-call app after the service has been unbound.
356 *
357 * @param disconnectedComponent The {@link ComponentName} of the service which disconnected.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800358 */
Tyler Gunn61b92102014-08-19 07:42:20 -0700359 private void onDisconnected(ComponentName disconnectedComponent) {
Santos Cordone3d76ab2014-01-28 17:25:20 -0800360 ThreadUtil.checkOnMainThread();
Tyler Gunn61b92102014-08-19 07:42:20 -0700361 if (mInCallServices.containsKey(disconnectedComponent)) {
362 mInCallServices.remove(disconnectedComponent);
363 }
364
365 // If the default in-call UI has disconnected, disconnect all calls and un-bind all other
366 // InCallService implementations.
367 if (disconnectedComponent.equals(mInCallComponentName)) {
368 Log.i(this, "In-call UI %s disconnected.", disconnectedComponent);
369 CallsManager.getInstance().disconnectAllCalls();
370
371 // Iterate through the in-call services, removing them as they are un-bound.
372 Iterator<Map.Entry<ComponentName, IInCallService>> it =
373 mInCallServices.entrySet().iterator();
374 while (it.hasNext()) {
375 Map.Entry<ComponentName, IInCallService> entry = it.next();
376 ComponentName componentName = entry.getKey();
377
378 InCallServiceConnection connection = mServiceConnections.remove(componentName);
379 it.remove();
380 if (connection == null) {
381 continue;
382 }
383
384 Log.i(this, "Unbinding other InCallService %s", componentName);
385 TelecommApp.getInstance().unbindService(connection);
386 }
387 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800388 }
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700389
Tyler Gunn12bccad2014-08-21 13:52:03 -0700390 /**
391 * Informs all {@link InCallService} instances of the updated call information. Changes to the
392 * video provider are only communicated to the default in-call UI.
393 *
394 * @param call The {@link Call}.
395 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700396 private void updateCall(Call call) {
Tyler Gunn61b92102014-08-19 07:42:20 -0700397 if (!mInCallServices.isEmpty()) {
Tyler Gunn12bccad2014-08-21 13:52:03 -0700398 for (Map.Entry<ComponentName, IInCallService> entry : mInCallServices.entrySet()) {
399 ComponentName componentName = entry.getKey();
400 IInCallService inCallService = entry.getValue();
401 ParcelableCall parcelableCall = toParcelableCall(call,
402 componentName.equals(mInCallComponentName) /* includeVideoProvider */);
403
404 Log.v(this, "updateCall %s ==> %s", call, parcelableCall);
Tyler Gunn61b92102014-08-19 07:42:20 -0700405 try {
406 inCallService.updateCall(parcelableCall);
407 } catch (RemoteException ignored) {
408 }
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700409 }
410 }
411 }
412
Tyler Gunn12bccad2014-08-21 13:52:03 -0700413 /**
414 * Parcels all information for a {@link Call} into a new {@link ParcelableCall} instance.
415 *
416 * @param call The {@link Call} to parcel.
417 * @param includeVideoProvider When {@code true}, the {@link IVideoProvider} is included in the
418 * parcelled call. When {@code false}, the {@link IVideoProvider} is not included.
419 * @return The {@link ParcelableCall} containing all call information from the {@link Call}.
420 */
421 private ParcelableCall toParcelableCall(Call call, boolean includeVideoProvider) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700422 String callId = mCallIdMapper.getCallId(call);
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700423
Sailesh Nepale20bc972014-07-09 21:22:36 -0700424 int capabilities = call.getCallCapabilities();
Santos Cordon4b034a62014-07-18 13:42:05 -0700425 if (CallsManager.getInstance().isAddCallCapable(call)) {
Ihab Awad6fb37c82014-08-07 19:48:57 -0700426 capabilities |= PhoneCapabilities.ADD_CALL;
Santos Cordon10838c22014-06-11 17:36:04 -0700427 }
Santos Cordon4b034a62014-07-18 13:42:05 -0700428 if (!call.isEmergencyCall()) {
Ihab Awad6fb37c82014-08-07 19:48:57 -0700429 capabilities |= PhoneCapabilities.MUTE;
Santos Cordona1610702014-06-04 20:22:56 -0700430 }
Sailesh Nepale20bc972014-07-09 21:22:36 -0700431
Ihab Awad6fb37c82014-08-07 19:48:57 -0700432 int state = call.getState();
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700433 if (state == CallState.ABORTED) {
434 state = CallState.DISCONNECTED;
435 }
Santos Cordona1610702014-06-04 20:22:56 -0700436
437 String parentCallId = null;
438 Call parentCall = call.getParentCall();
439 if (parentCall != null) {
440 parentCallId = mCallIdMapper.getCallId(parentCall);
441 }
442
443 long connectTimeMillis = call.getConnectTimeMillis();
444 List<Call> childCalls = call.getChildCalls();
445 List<String> childCallIds = new ArrayList<>();
446 if (!childCalls.isEmpty()) {
447 connectTimeMillis = Long.MAX_VALUE;
448 for (Call child : childCalls) {
449 connectTimeMillis = Math.min(child.getConnectTimeMillis(), connectTimeMillis);
450 childCallIds.add(mCallIdMapper.getCallId(child));
451 }
452 }
453
Ihab Awadff7493a2014-06-10 13:47:44 -0700454 if (call.isRespondViaSmsCapable()) {
Ihab Awad6fb37c82014-08-07 19:48:57 -0700455 capabilities |= PhoneCapabilities.RESPOND_VIA_TEXT;
Ihab Awadff7493a2014-06-10 13:47:44 -0700456 }
457
Ihab Awad6fb37c82014-08-07 19:48:57 -0700458 Uri handle = call.getHandlePresentation() == PropertyPresentation.ALLOWED ?
Sailesh Nepale8ecb982014-07-11 17:19:42 -0700459 call.getHandle() : null;
460 String callerDisplayName = call.getCallerDisplayNamePresentation() ==
Ihab Awad6fb37c82014-08-07 19:48:57 -0700461 PropertyPresentation.ALLOWED ? call.getCallerDisplayName() : null;
Sailesh Nepale8ecb982014-07-11 17:19:42 -0700462
Santos Cordon12d61822014-07-29 16:02:20 -0700463 List<Call> conferenceableCalls = call.getConferenceableCalls();
464 List<String> conferenceableCallIds = new ArrayList<String>(conferenceableCalls.size());
465 for (Call otherCall : conferenceableCalls) {
466 String otherId = mCallIdMapper.getCallId(otherCall);
467 if (otherId != null) {
468 conferenceableCallIds.add(otherId);
469 }
470 }
471
Santos Cordon2583b672014-07-19 13:07:33 -0700472 return new ParcelableCall(
473 callId,
474 state,
475 call.getDisconnectCause(),
476 call.getDisconnectMessage(),
477 call.getCannedSmsResponses(),
478 capabilities,
479 connectTimeMillis,
480 handle,
481 call.getHandlePresentation(),
482 callerDisplayName,
483 call.getCallerDisplayNamePresentation(),
484 call.getGatewayInfo(),
Ihab Awadb78b2762014-07-25 15:16:23 -0700485 call.getTargetPhoneAccount(),
Tyler Gunn12bccad2014-08-21 13:52:03 -0700486 includeVideoProvider ? call.getVideoProvider() : null,
Santos Cordon2583b672014-07-19 13:07:33 -0700487 parentCallId,
488 childCallIds,
489 call.getStatusHints(),
Santos Cordon12d61822014-07-29 16:02:20 -0700490 call.getVideoState(),
Nancy Chena9d91da2014-08-12 14:31:06 -0700491 conferenceableCallIds,
492 call.getExtras());
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700493 }
Tyler Gunn61b92102014-08-19 07:42:20 -0700494
495 /**
496 * Adds the call to the list of calls tracked by the {@link InCallController}.
497 * @param call The call to add.
498 */
499 private void addCall(Call call) {
500 if (mCallIdMapper.getCallId(call) == null) {
501 mCallIdMapper.addCall(call);
502 call.addListener(mCallListener);
503 }
504 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800505}