blob: 4f022c09ee72ffa241f5f25e1282cdda6eada11e [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 Gunn61b92102014-08-19 07:42:20 -0700146 /** The {@link ComponentName} of the default InCall UI */
147 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
167 ParcelableCall parcelableCall = toParcelableCall(call);
168 for (IInCallService inCallService : mInCallServices.values()) {
Ihab Awadff7493a2014-06-10 13:47:44 -0700169 try {
Tyler Gunn61b92102014-08-19 07:42:20 -0700170 inCallService.addCall(parcelableCall);
Ihab Awadff7493a2014-06-10 13:47:44 -0700171 } catch (RemoteException ignored) {
172 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800173 }
Santos Cordon049b7b62014-01-30 05:34:26 -0800174 }
175 }
176
Sailesh Nepal810735e2014-03-18 18:15:46 -0700177 @Override
178 public void onCallRemoved(Call call) {
179 if (CallsManager.getInstance().getCalls().isEmpty()) {
Santos Cordondf399862014-08-06 04:39:15 -0700180 // TODO: Wait for all messages to be delivered to the service before unbinding.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700181 unbind();
Santos Cordon049b7b62014-01-30 05:34:26 -0800182 }
Sailesh Nepale8ecb982014-07-11 17:19:42 -0700183 call.removeListener(mCallListener);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700184 mCallIdMapper.removeCall(call);
Santos Cordon049b7b62014-01-30 05:34:26 -0800185 }
186
Sailesh Nepal810735e2014-03-18 18:15:46 -0700187 @Override
Ihab Awad6fb37c82014-08-07 19:48:57 -0700188 public void onCallStateChanged(Call call, int oldState, int newState) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700189 updateCall(call);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700190 }
191
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700192 @Override
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700193 public void onConnectionServiceChanged(
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700194 Call call,
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700195 ConnectionServiceWrapper oldService,
196 ConnectionServiceWrapper newService) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700197 updateCall(call);
198 }
199
200 @Override
Ihab Awad6fb37c82014-08-07 19:48:57 -0700201 public void onAudioStateChanged(AudioState oldAudioState, AudioState newAudioState) {
Tyler Gunn61b92102014-08-19 07:42:20 -0700202 if (!mInCallServices.isEmpty()) {
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700203 Log.i(this, "Calling onAudioStateChanged, audioState: %s -> %s", oldAudioState,
204 newAudioState);
Tyler Gunn61b92102014-08-19 07:42:20 -0700205 for (IInCallService inCallService : mInCallServices.values()) {
206 try {
207 inCallService.onAudioStateChanged(newAudioState);
208 } catch (RemoteException ignored) {
209 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700210 }
211 }
212 }
213
Evan Charlton352105c2014-06-03 14:10:54 -0700214 void onPostDialWait(Call call, String remaining) {
Tyler Gunn61b92102014-08-19 07:42:20 -0700215 if (!mInCallServices.isEmpty()) {
Evan Charlton352105c2014-06-03 14:10:54 -0700216 Log.i(this, "Calling onPostDialWait, remaining = %s", remaining);
Tyler Gunn61b92102014-08-19 07:42:20 -0700217 for (IInCallService inCallService : mInCallServices.values()) {
218 try {
219 inCallService.setPostDialWait(mCallIdMapper.getCallId(call), remaining);
220 } catch (RemoteException ignored) {
221 }
Evan Charlton352105c2014-06-03 14:10:54 -0700222 }
223 }
224 }
225
Santos Cordona1610702014-06-04 20:22:56 -0700226 @Override
Santos Cordona1610702014-06-04 20:22:56 -0700227 public void onIsConferencedChanged(Call call) {
Santos Cordon0fbe6322014-08-14 04:04:25 -0700228 Log.d(this, "onIsConferencedChanged %s", call);
Santos Cordona1610702014-06-04 20:22:56 -0700229 updateCall(call);
230 }
231
Santos Cordonf3671a62014-05-29 21:51:53 -0700232 void bringToForeground(boolean showDialpad) {
Tyler Gunn61b92102014-08-19 07:42:20 -0700233 if (!mInCallServices.isEmpty()) {
234 for (IInCallService inCallService : mInCallServices.values()) {
235 try {
236 inCallService.bringToForeground(showDialpad);
237 } catch (RemoteException ignored) {
238 }
Santos Cordonf3671a62014-05-29 21:51:53 -0700239 }
240 } else {
241 Log.w(this, "Asking to bring unbound in-call UI to foreground.");
242 }
243 }
244
Santos Cordone3d76ab2014-01-28 17:25:20 -0800245 /**
246 * Unbinds an existing bound connection to the in-call app.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800247 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700248 private void unbind() {
Santos Cordone3d76ab2014-01-28 17:25:20 -0800249 ThreadUtil.checkOnMainThread();
Tyler Gunn61b92102014-08-19 07:42:20 -0700250 if (!mInCallServices.isEmpty()) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800251 Log.i(this, "Unbinding from InCallService");
Tyler Gunn61b92102014-08-19 07:42:20 -0700252 for (InCallServiceConnection connection : mServiceConnections.values()) {
253 TelecommApp.getInstance().unbindService(connection);
254 }
255 mInCallServices.clear();
Santos Cordone3d76ab2014-01-28 17:25:20 -0800256 }
257 }
258
259 /**
Santos Cordon049b7b62014-01-30 05:34:26 -0800260 * Binds to the in-call app if not already connected by binding directly to the saved
261 * component name of the {@link IInCallService} implementation.
262 */
263 private void bind() {
264 ThreadUtil.checkOnMainThread();
Tyler Gunn61b92102014-08-19 07:42:20 -0700265 if (mInCallServices.isEmpty()) {
266 mServiceConnections.clear();
Santos Cordonfdfcafa2014-06-26 14:49:05 -0700267 Context context = TelecommApp.getInstance();
Tyler Gunn61b92102014-08-19 07:42:20 -0700268 PackageManager packageManager = TelecommApp.getInstance().getPackageManager();
269 Intent intent = new Intent(InCallService.SERVICE_INTERFACE);
Santos Cordon049b7b62014-01-30 05:34:26 -0800270
Tyler Gunn61b92102014-08-19 07:42:20 -0700271 for (ResolveInfo entry : packageManager.queryIntentServices(intent, 0)) {
272 ServiceInfo serviceInfo = entry.serviceInfo;
273 if (serviceInfo != null) {
274 boolean hasServiceBindPermission = serviceInfo.permission != null &&
275 serviceInfo.permission.equals(
276 Manifest.permission.BIND_INCALL_SERVICE);
277 boolean hasControlInCallPermission = packageManager.checkPermission(
278 Manifest.permission.CONTROL_INCALL_EXPERIENCE,
279 serviceInfo.packageName) == PackageManager.PERMISSION_GRANTED;
Santos Cordon049b7b62014-01-30 05:34:26 -0800280
Tyler Gunn61b92102014-08-19 07:42:20 -0700281 if (!hasServiceBindPermission) {
282 Log.w(this, "InCallService does not have BIND_INCALL_SERVICE permission: " +
283 serviceInfo.packageName);
284 continue;
285 }
Santos Cordon049b7b62014-01-30 05:34:26 -0800286
Tyler Gunn61b92102014-08-19 07:42:20 -0700287 if (!hasControlInCallPermission) {
288 Log.w(this,
289 "InCall UI does not have CONTROL_INCALL_EXPERIENCE permission: " +
290 serviceInfo.packageName);
291 continue;
292 }
293
294 Log.i(this, "Attempting to bind to InCall " + serviceInfo.packageName);
295 InCallServiceConnection inCallServiceConnection = new InCallServiceConnection();
296 ComponentName componentName = new ComponentName(serviceInfo.packageName,
297 serviceInfo.name);
298 intent.setComponent(componentName);
299
300 if (context.bindServiceAsUser(intent, inCallServiceConnection,
301 Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
302 mServiceConnections.put(componentName, inCallServiceConnection);
303 }
304 }
Santos Cordon049b7b62014-01-30 05:34:26 -0800305 }
306 }
307 }
308
309 /**
Santos Cordone3d76ab2014-01-28 17:25:20 -0800310 * Persists the {@link IInCallService} instance and starts the communication between
Sailesh Nepale59bb192014-04-01 18:33:59 -0700311 * 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 -0800312 * called after a successful binding connection is established.
313 *
Tyler Gunn61b92102014-08-19 07:42:20 -0700314 * @param componentName The service {@link ComponentName}.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800315 * @param service The {@link IInCallService} implementation.
316 */
Tyler Gunn61b92102014-08-19 07:42:20 -0700317 private void onConnected(ComponentName componentName, IBinder service) {
Santos Cordone3d76ab2014-01-28 17:25:20 -0800318 ThreadUtil.checkOnMainThread();
Tyler Gunn61b92102014-08-19 07:42:20 -0700319
320 IInCallService inCallService = IInCallService.Stub.asInterface(service);
Santos Cordone3d76ab2014-01-28 17:25:20 -0800321
322 try {
Tyler Gunn61b92102014-08-19 07:42:20 -0700323 inCallService.setInCallAdapter(new InCallAdapter(CallsManager.getInstance(),
Sailesh Nepale59bb192014-04-01 18:33:59 -0700324 mCallIdMapper));
Tyler Gunn61b92102014-08-19 07:42:20 -0700325 mInCallServices.put(componentName, inCallService);
Santos Cordone3d76ab2014-01-28 17:25:20 -0800326 } catch (RemoteException e) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800327 Log.e(this, e, "Failed to set the in-call adapter.");
Sailesh Nepal810735e2014-03-18 18:15:46 -0700328 return;
Santos Cordone3d76ab2014-01-28 17:25:20 -0800329 }
330
Tyler Gunn61b92102014-08-19 07:42:20 -0700331 // Upon successful connection, send the state of the world to the service.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700332 ImmutableCollection<Call> calls = CallsManager.getInstance().getCalls();
333 if (!calls.isEmpty()) {
334 for (Call call : calls) {
Tyler Gunn61b92102014-08-19 07:42:20 -0700335 try {
336 // Track the call if we don't already know about it.
337 addCall(call);
338
339 inCallService.addCall(toParcelableCall(call));
340 } catch (RemoteException ignored) {
341 }
Sailesh Nepal810735e2014-03-18 18:15:46 -0700342 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700343 onAudioStateChanged(null, CallsManager.getInstance().getAudioState());
Sailesh Nepal810735e2014-03-18 18:15:46 -0700344 } else {
345 unbind();
Santos Cordon049b7b62014-01-30 05:34:26 -0800346 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800347 }
348
349 /**
Tyler Gunn61b92102014-08-19 07:42:20 -0700350 * Cleans up an instance of in-call app after the service has been unbound.
351 *
352 * @param disconnectedComponent The {@link ComponentName} of the service which disconnected.
Santos Cordone3d76ab2014-01-28 17:25:20 -0800353 */
Tyler Gunn61b92102014-08-19 07:42:20 -0700354 private void onDisconnected(ComponentName disconnectedComponent) {
Santos Cordone3d76ab2014-01-28 17:25:20 -0800355 ThreadUtil.checkOnMainThread();
Tyler Gunn61b92102014-08-19 07:42:20 -0700356 if (mInCallServices.containsKey(disconnectedComponent)) {
357 mInCallServices.remove(disconnectedComponent);
358 }
359
360 // If the default in-call UI has disconnected, disconnect all calls and un-bind all other
361 // InCallService implementations.
362 if (disconnectedComponent.equals(mInCallComponentName)) {
363 Log.i(this, "In-call UI %s disconnected.", disconnectedComponent);
364 CallsManager.getInstance().disconnectAllCalls();
365
366 // Iterate through the in-call services, removing them as they are un-bound.
367 Iterator<Map.Entry<ComponentName, IInCallService>> it =
368 mInCallServices.entrySet().iterator();
369 while (it.hasNext()) {
370 Map.Entry<ComponentName, IInCallService> entry = it.next();
371 ComponentName componentName = entry.getKey();
372
373 InCallServiceConnection connection = mServiceConnections.remove(componentName);
374 it.remove();
375 if (connection == null) {
376 continue;
377 }
378
379 Log.i(this, "Unbinding other InCallService %s", componentName);
380 TelecommApp.getInstance().unbindService(connection);
381 }
382 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800383 }
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700384
385 private void updateCall(Call call) {
Tyler Gunn61b92102014-08-19 07:42:20 -0700386 if (!mInCallServices.isEmpty()) {
387 ParcelableCall parcelableCall = toParcelableCall(call);
388 Log.v(this, "updateCall %s ==> %s", call, parcelableCall);
389 for (IInCallService inCallService : mInCallServices.values()) {
390 try {
391 inCallService.updateCall(parcelableCall);
392 } catch (RemoteException ignored) {
393 }
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700394 }
395 }
396 }
397
Santos Cordon2583b672014-07-19 13:07:33 -0700398 private ParcelableCall toParcelableCall(Call call) {
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700399 String callId = mCallIdMapper.getCallId(call);
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700400
Sailesh Nepale20bc972014-07-09 21:22:36 -0700401 int capabilities = call.getCallCapabilities();
Santos Cordon4b034a62014-07-18 13:42:05 -0700402 if (CallsManager.getInstance().isAddCallCapable(call)) {
Ihab Awad6fb37c82014-08-07 19:48:57 -0700403 capabilities |= PhoneCapabilities.ADD_CALL;
Santos Cordon10838c22014-06-11 17:36:04 -0700404 }
Santos Cordon4b034a62014-07-18 13:42:05 -0700405 if (!call.isEmergencyCall()) {
Ihab Awad6fb37c82014-08-07 19:48:57 -0700406 capabilities |= PhoneCapabilities.MUTE;
Santos Cordona1610702014-06-04 20:22:56 -0700407 }
Sailesh Nepale20bc972014-07-09 21:22:36 -0700408
Ihab Awad6fb37c82014-08-07 19:48:57 -0700409 int state = call.getState();
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700410 if (state == CallState.ABORTED) {
411 state = CallState.DISCONNECTED;
412 }
Santos Cordona1610702014-06-04 20:22:56 -0700413
414 String parentCallId = null;
415 Call parentCall = call.getParentCall();
416 if (parentCall != null) {
417 parentCallId = mCallIdMapper.getCallId(parentCall);
418 }
419
420 long connectTimeMillis = call.getConnectTimeMillis();
421 List<Call> childCalls = call.getChildCalls();
422 List<String> childCallIds = new ArrayList<>();
423 if (!childCalls.isEmpty()) {
424 connectTimeMillis = Long.MAX_VALUE;
425 for (Call child : childCalls) {
426 connectTimeMillis = Math.min(child.getConnectTimeMillis(), connectTimeMillis);
427 childCallIds.add(mCallIdMapper.getCallId(child));
428 }
429 }
430
Ihab Awadff7493a2014-06-10 13:47:44 -0700431 if (call.isRespondViaSmsCapable()) {
Ihab Awad6fb37c82014-08-07 19:48:57 -0700432 capabilities |= PhoneCapabilities.RESPOND_VIA_TEXT;
Ihab Awadff7493a2014-06-10 13:47:44 -0700433 }
434
Ihab Awad6fb37c82014-08-07 19:48:57 -0700435 Uri handle = call.getHandlePresentation() == PropertyPresentation.ALLOWED ?
Sailesh Nepale8ecb982014-07-11 17:19:42 -0700436 call.getHandle() : null;
437 String callerDisplayName = call.getCallerDisplayNamePresentation() ==
Ihab Awad6fb37c82014-08-07 19:48:57 -0700438 PropertyPresentation.ALLOWED ? call.getCallerDisplayName() : null;
Sailesh Nepale8ecb982014-07-11 17:19:42 -0700439
Santos Cordon12d61822014-07-29 16:02:20 -0700440 List<Call> conferenceableCalls = call.getConferenceableCalls();
441 List<String> conferenceableCallIds = new ArrayList<String>(conferenceableCalls.size());
442 for (Call otherCall : conferenceableCalls) {
443 String otherId = mCallIdMapper.getCallId(otherCall);
444 if (otherId != null) {
445 conferenceableCallIds.add(otherId);
446 }
447 }
448
Santos Cordon2583b672014-07-19 13:07:33 -0700449 return new ParcelableCall(
450 callId,
451 state,
452 call.getDisconnectCause(),
453 call.getDisconnectMessage(),
454 call.getCannedSmsResponses(),
455 capabilities,
456 connectTimeMillis,
457 handle,
458 call.getHandlePresentation(),
459 callerDisplayName,
460 call.getCallerDisplayNamePresentation(),
461 call.getGatewayInfo(),
Ihab Awadb78b2762014-07-25 15:16:23 -0700462 call.getTargetPhoneAccount(),
Ihab Awad6fb37c82014-08-07 19:48:57 -0700463 call.getVideoProvider(),
Santos Cordon2583b672014-07-19 13:07:33 -0700464 parentCallId,
465 childCallIds,
466 call.getStatusHints(),
Santos Cordon12d61822014-07-29 16:02:20 -0700467 call.getVideoState(),
Nancy Chena9d91da2014-08-12 14:31:06 -0700468 conferenceableCallIds,
469 call.getExtras());
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700470 }
Tyler Gunn61b92102014-08-19 07:42:20 -0700471
472 /**
473 * Adds the call to the list of calls tracked by the {@link InCallController}.
474 * @param call The call to add.
475 */
476 private void addCall(Call call) {
477 if (mCallIdMapper.getCallId(call) == null) {
478 mCallIdMapper.addCall(call);
479 call.addListener(mCallListener);
480 }
481 }
Santos Cordone3d76ab2014-01-28 17:25:20 -0800482}