Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.telecomm; |
| 18 | |
Sailesh Nepal | 9d58de5 | 2014-07-18 14:53:19 -0700 | [diff] [blame] | 19 | import android.app.PendingIntent; |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 20 | import android.content.ComponentName; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.content.ServiceConnection; |
Santos Cordon | fdfcafa | 2014-06-26 14:49:05 -0700 | [diff] [blame] | 24 | |
| 25 | import android.content.res.Resources; |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 26 | import android.net.Uri; |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 27 | import android.os.IBinder; |
| 28 | import android.os.RemoteException; |
Amith Yamasani | 60e7584 | 2014-05-23 10:09:14 -0700 | [diff] [blame] | 29 | import android.os.UserHandle; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 30 | import android.telecomm.CallAudioState; |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 31 | import android.telecomm.CallCapabilities; |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 32 | import android.telecomm.CallPropertyPresentation; |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 33 | import android.telecomm.CallState; |
Santos Cordon | 2583b67 | 2014-07-19 13:07:33 -0700 | [diff] [blame] | 34 | import android.telecomm.ParcelableCall; |
Sailesh Nepal | a439e1b | 2014-03-11 18:19:58 -0700 | [diff] [blame] | 35 | |
| 36 | import com.android.internal.telecomm.IInCallService; |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 37 | import com.google.common.collect.ImmutableCollection; |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 38 | |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 39 | import java.util.ArrayList; |
| 40 | import java.util.List; |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 41 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 42 | /** |
| 43 | * Binds to {@link IInCallService} and provides the service to {@link CallsManager} through which it |
| 44 | * can send updates to the in-call app. This class is created and owned by CallsManager and retains |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 45 | * a binding to the {@link IInCallService} (implemented by the in-call app). |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 46 | */ |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 47 | public final class InCallController extends CallsManagerListenerBase { |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 48 | /** |
| 49 | * Used to bind to the in-call app and triggers the start of communication between |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 50 | * this class and in-call app. |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 51 | */ |
| 52 | private class InCallServiceConnection implements ServiceConnection { |
| 53 | /** {@inheritDoc} */ |
| 54 | @Override public void onServiceConnected(ComponentName name, IBinder service) { |
| 55 | onConnected(service); |
| 56 | } |
| 57 | |
| 58 | /** {@inheritDoc} */ |
| 59 | @Override public void onServiceDisconnected(ComponentName name) { |
| 60 | onDisconnected(); |
| 61 | } |
| 62 | } |
| 63 | |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 64 | private final Call.Listener mCallListener = new Call.ListenerBase() { |
| 65 | @Override |
| 66 | public void onCallCapabilitiesChanged(Call call) { |
| 67 | updateCall(call); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public void onCannedSmsResponsesLoaded(Call call) { |
| 72 | updateCall(call); |
| 73 | } |
| 74 | |
| 75 | @Override |
Andrew Lee | 3bcf935 | 2014-07-23 12:36:05 -0700 | [diff] [blame] | 76 | public void onVideoCallProviderChanged(Call call) { |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 77 | updateCall(call); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public void onStatusHintsChanged(Call call) { |
| 82 | updateCall(call); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public void onHandleChanged(Call call) { |
| 87 | updateCall(call); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public void onCallerDisplayNameChanged(Call call) { |
| 92 | updateCall(call); |
| 93 | } |
Andrew Lee | 4a79660 | 2014-07-11 17:23:03 -0700 | [diff] [blame] | 94 | |
| 95 | @Override |
| 96 | public void onVideoStateChanged(Call call) { |
| 97 | updateCall(call); |
| 98 | } |
Sailesh Nepal | 9d58de5 | 2014-07-18 14:53:19 -0700 | [diff] [blame] | 99 | |
| 100 | @Override |
| 101 | public void onStartActivityFromInCall(Call call, PendingIntent intent) { |
| 102 | if (mInCallService != null) { |
| 103 | Log.i(this, "Calling startActivity, intent: %s", intent); |
| 104 | try { |
| 105 | mInCallService.startActivity(mCallIdMapper.getCallId(call), intent); |
| 106 | } catch (RemoteException ignored) { |
| 107 | } |
| 108 | } |
| 109 | } |
Ihab Awad | 69eb0f5 | 2014-07-18 11:20:37 -0700 | [diff] [blame] | 110 | |
| 111 | @Override |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 112 | public void onTargetPhoneAccountChanged(Call call) { |
Ihab Awad | 69eb0f5 | 2014-07-18 11:20:37 -0700 | [diff] [blame] | 113 | updateCall(call); |
| 114 | } |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 117 | /** Maintains a binding connection to the in-call app. */ |
| 118 | private final InCallServiceConnection mConnection = new InCallServiceConnection(); |
| 119 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 120 | /** The in-call app implementation, see {@link IInCallService}. */ |
| 121 | private IInCallService mInCallService; |
| 122 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 123 | private final CallIdMapper mCallIdMapper = new CallIdMapper("InCall"); |
| 124 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 125 | IInCallService getService() { |
| 126 | return mInCallService; |
| 127 | } |
| 128 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 129 | @Override |
| 130 | public void onCallAdded(Call call) { |
| 131 | if (mInCallService == null) { |
| 132 | bind(); |
| 133 | } else { |
| 134 | Log.i(this, "Adding call: %s", call); |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 135 | if (mCallIdMapper.getCallId(call) == null) { |
| 136 | mCallIdMapper.addCall(call); |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 137 | call.addListener(mCallListener); |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 138 | try { |
Santos Cordon | 2583b67 | 2014-07-19 13:07:33 -0700 | [diff] [blame] | 139 | mInCallService.addCall(toParcelableCall(call)); |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 140 | } catch (RemoteException ignored) { |
| 141 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 142 | } |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 146 | @Override |
| 147 | public void onCallRemoved(Call call) { |
| 148 | if (CallsManager.getInstance().getCalls().isEmpty()) { |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame^] | 149 | // TODO: Wait for all messages to be delivered to the service before unbinding. |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 150 | unbind(); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 151 | } |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 152 | call.removeListener(mCallListener); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 153 | mCallIdMapper.removeCall(call); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 154 | } |
| 155 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 156 | @Override |
| 157 | public void onCallStateChanged(Call call, CallState oldState, CallState newState) { |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 158 | updateCall(call); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 161 | @Override |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 162 | public void onConnectionServiceChanged( |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 163 | Call call, |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 164 | ConnectionServiceWrapper oldService, |
| 165 | ConnectionServiceWrapper newService) { |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 166 | updateCall(call); |
| 167 | } |
| 168 | |
| 169 | @Override |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 170 | public void onAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState) { |
| 171 | if (mInCallService != null) { |
| 172 | Log.i(this, "Calling onAudioStateChanged, audioState: %s -> %s", oldAudioState, |
| 173 | newAudioState); |
| 174 | try { |
| 175 | mInCallService.onAudioStateChanged(newAudioState); |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 176 | } catch (RemoteException ignored) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 181 | void onPostDialWait(Call call, String remaining) { |
| 182 | if (mInCallService != null) { |
| 183 | Log.i(this, "Calling onPostDialWait, remaining = %s", remaining); |
| 184 | try { |
| 185 | mInCallService.setPostDialWait(mCallIdMapper.getCallId(call), remaining); |
| 186 | } catch (RemoteException ignored) { |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 191 | @Override |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 192 | public void onIsConferencedChanged(Call call) { |
| 193 | Log.v(this, "onIsConferencedChanged %s", call); |
| 194 | updateCall(call); |
| 195 | } |
| 196 | |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 197 | void bringToForeground(boolean showDialpad) { |
| 198 | if (mInCallService != null) { |
| 199 | try { |
| 200 | mInCallService.bringToForeground(showDialpad); |
| 201 | } catch (RemoteException ignored) { |
| 202 | } |
| 203 | } else { |
| 204 | Log.w(this, "Asking to bring unbound in-call UI to foreground."); |
| 205 | } |
| 206 | } |
| 207 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 208 | /** |
| 209 | * Unbinds an existing bound connection to the in-call app. |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 210 | */ |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 211 | private void unbind() { |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 212 | ThreadUtil.checkOnMainThread(); |
| 213 | if (mInCallService != null) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 214 | Log.i(this, "Unbinding from InCallService"); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 215 | TelecommApp.getInstance().unbindService(mConnection); |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 216 | mInCallService = null; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | /** |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 221 | * Binds to the in-call app if not already connected by binding directly to the saved |
| 222 | * component name of the {@link IInCallService} implementation. |
| 223 | */ |
| 224 | private void bind() { |
| 225 | ThreadUtil.checkOnMainThread(); |
| 226 | if (mInCallService == null) { |
Santos Cordon | fdfcafa | 2014-06-26 14:49:05 -0700 | [diff] [blame] | 227 | Context context = TelecommApp.getInstance(); |
| 228 | Resources resources = context.getResources(); |
| 229 | ComponentName component = new ComponentName( |
| 230 | resources.getString(R.string.ui_default_package), |
| 231 | resources.getString(R.string.incall_default_class)); |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 232 | Log.i(this, "Attempting to bind to InCallService: %s", component); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 233 | |
| 234 | Intent serviceIntent = new Intent(IInCallService.class.getName()); |
| 235 | serviceIntent.setComponent(component); |
| 236 | |
Amith Yamasani | 60e7584 | 2014-05-23 10:09:14 -0700 | [diff] [blame] | 237 | if (!context.bindServiceAsUser(serviceIntent, mConnection, Context.BIND_AUTO_CREATE, |
| 238 | UserHandle.CURRENT)) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 239 | Log.w(this, "Could not connect to the in-call app (%s)", component); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 240 | |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame^] | 241 | // TODO: Implement retry or fall-back-to-default logic. |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | /** |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 247 | * Persists the {@link IInCallService} instance and starts the communication between |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 248 | * this class and in-call app by sending the first update to in-call app. This method is |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 249 | * called after a successful binding connection is established. |
| 250 | * |
| 251 | * @param service The {@link IInCallService} implementation. |
| 252 | */ |
| 253 | private void onConnected(IBinder service) { |
| 254 | ThreadUtil.checkOnMainThread(); |
| 255 | mInCallService = IInCallService.Stub.asInterface(service); |
| 256 | |
| 257 | try { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 258 | mInCallService.setInCallAdapter(new InCallAdapter(CallsManager.getInstance(), |
| 259 | mCallIdMapper)); |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 260 | } catch (RemoteException e) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 261 | Log.e(this, e, "Failed to set the in-call adapter."); |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 262 | mInCallService = null; |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 263 | return; |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 264 | } |
| 265 | |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 266 | // Upon successful connection, send the state of the world to the in-call app. |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 267 | ImmutableCollection<Call> calls = CallsManager.getInstance().getCalls(); |
| 268 | if (!calls.isEmpty()) { |
| 269 | for (Call call : calls) { |
| 270 | onCallAdded(call); |
| 271 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 272 | onAudioStateChanged(null, CallsManager.getInstance().getAudioState()); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 273 | } else { |
| 274 | unbind(); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 275 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Cleans up the instance of in-call app after the service has been unbound. |
| 280 | */ |
| 281 | private void onDisconnected() { |
| 282 | ThreadUtil.checkOnMainThread(); |
| 283 | mInCallService = null; |
| 284 | } |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 285 | |
| 286 | private void updateCall(Call call) { |
| 287 | if (mInCallService != null) { |
| 288 | try { |
Santos Cordon | 2583b67 | 2014-07-19 13:07:33 -0700 | [diff] [blame] | 289 | ParcelableCall parcelableCall = toParcelableCall(call); |
| 290 | Log.v(this, "updateCall %s ==> %s", call, parcelableCall); |
| 291 | mInCallService.updateCall(parcelableCall); |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 292 | } catch (RemoteException ignored) { |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
Santos Cordon | 2583b67 | 2014-07-19 13:07:33 -0700 | [diff] [blame] | 297 | private ParcelableCall toParcelableCall(Call call) { |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 298 | String callId = mCallIdMapper.getCallId(call); |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 299 | |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 300 | int capabilities = call.getCallCapabilities(); |
Santos Cordon | 4b034a6 | 2014-07-18 13:42:05 -0700 | [diff] [blame] | 301 | if (CallsManager.getInstance().isAddCallCapable(call)) { |
| 302 | capabilities |= CallCapabilities.ADD_CALL; |
Santos Cordon | 10838c2 | 2014-06-11 17:36:04 -0700 | [diff] [blame] | 303 | } |
Santos Cordon | 4b034a6 | 2014-07-18 13:42:05 -0700 | [diff] [blame] | 304 | if (!call.isEmergencyCall()) { |
| 305 | capabilities |= CallCapabilities.MUTE; |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 306 | } |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 307 | |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 308 | CallState state = call.getState(); |
| 309 | if (state == CallState.ABORTED) { |
| 310 | state = CallState.DISCONNECTED; |
| 311 | } |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 312 | |
| 313 | String parentCallId = null; |
| 314 | Call parentCall = call.getParentCall(); |
| 315 | if (parentCall != null) { |
| 316 | parentCallId = mCallIdMapper.getCallId(parentCall); |
| 317 | } |
| 318 | |
| 319 | long connectTimeMillis = call.getConnectTimeMillis(); |
| 320 | List<Call> childCalls = call.getChildCalls(); |
| 321 | List<String> childCallIds = new ArrayList<>(); |
| 322 | if (!childCalls.isEmpty()) { |
| 323 | connectTimeMillis = Long.MAX_VALUE; |
| 324 | for (Call child : childCalls) { |
| 325 | connectTimeMillis = Math.min(child.getConnectTimeMillis(), connectTimeMillis); |
| 326 | childCallIds.add(mCallIdMapper.getCallId(child)); |
| 327 | } |
| 328 | } |
| 329 | |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 330 | if (call.isRespondViaSmsCapable()) { |
| 331 | capabilities |= CallCapabilities.RESPOND_VIA_TEXT; |
| 332 | } |
| 333 | |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 334 | Uri handle = call.getHandlePresentation() == CallPropertyPresentation.ALLOWED ? |
| 335 | call.getHandle() : null; |
| 336 | String callerDisplayName = call.getCallerDisplayNamePresentation() == |
| 337 | CallPropertyPresentation.ALLOWED ? call.getCallerDisplayName() : null; |
| 338 | |
Santos Cordon | 2583b67 | 2014-07-19 13:07:33 -0700 | [diff] [blame] | 339 | return new ParcelableCall( |
| 340 | callId, |
| 341 | state, |
| 342 | call.getDisconnectCause(), |
| 343 | call.getDisconnectMessage(), |
| 344 | call.getCannedSmsResponses(), |
| 345 | capabilities, |
| 346 | connectTimeMillis, |
| 347 | handle, |
| 348 | call.getHandlePresentation(), |
| 349 | callerDisplayName, |
| 350 | call.getCallerDisplayNamePresentation(), |
| 351 | call.getGatewayInfo(), |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 352 | call.getTargetPhoneAccount(), |
Andrew Lee | 3bcf935 | 2014-07-23 12:36:05 -0700 | [diff] [blame] | 353 | call.getVideoCallProvider(), |
Santos Cordon | 2583b67 | 2014-07-19 13:07:33 -0700 | [diff] [blame] | 354 | parentCallId, |
| 355 | childCallIds, |
| 356 | call.getStatusHints(), |
| 357 | call.getVideoState()); |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 358 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 359 | } |