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 | } |
Santos Cordon | 12d6182 | 2014-07-29 16:02:20 -0700 | [diff] [blame] | 115 | |
| 116 | @Override |
| 117 | public void onConferenceableCallsChanged(Call call) { |
| 118 | updateCall(call); |
| 119 | } |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 122 | /** Maintains a binding connection to the in-call app. */ |
| 123 | private final InCallServiceConnection mConnection = new InCallServiceConnection(); |
| 124 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 125 | /** The in-call app implementation, see {@link IInCallService}. */ |
| 126 | private IInCallService mInCallService; |
| 127 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 128 | private final CallIdMapper mCallIdMapper = new CallIdMapper("InCall"); |
| 129 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 130 | IInCallService getService() { |
| 131 | return mInCallService; |
| 132 | } |
| 133 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 134 | @Override |
| 135 | public void onCallAdded(Call call) { |
| 136 | if (mInCallService == null) { |
| 137 | bind(); |
| 138 | } else { |
| 139 | Log.i(this, "Adding call: %s", call); |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 140 | if (mCallIdMapper.getCallId(call) == null) { |
| 141 | mCallIdMapper.addCall(call); |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 142 | call.addListener(mCallListener); |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 143 | try { |
Santos Cordon | 2583b67 | 2014-07-19 13:07:33 -0700 | [diff] [blame] | 144 | mInCallService.addCall(toParcelableCall(call)); |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 145 | } catch (RemoteException ignored) { |
| 146 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 147 | } |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 151 | @Override |
| 152 | public void onCallRemoved(Call call) { |
| 153 | if (CallsManager.getInstance().getCalls().isEmpty()) { |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 154 | // 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] | 155 | unbind(); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 156 | } |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 157 | call.removeListener(mCallListener); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 158 | mCallIdMapper.removeCall(call); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 159 | } |
| 160 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 161 | @Override |
| 162 | public void onCallStateChanged(Call call, CallState oldState, CallState newState) { |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 163 | updateCall(call); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 166 | @Override |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 167 | public void onConnectionServiceChanged( |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 168 | Call call, |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 169 | ConnectionServiceWrapper oldService, |
| 170 | ConnectionServiceWrapper newService) { |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 171 | updateCall(call); |
| 172 | } |
| 173 | |
| 174 | @Override |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 175 | public void onAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState) { |
| 176 | if (mInCallService != null) { |
| 177 | Log.i(this, "Calling onAudioStateChanged, audioState: %s -> %s", oldAudioState, |
| 178 | newAudioState); |
| 179 | try { |
| 180 | mInCallService.onAudioStateChanged(newAudioState); |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 181 | } catch (RemoteException ignored) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 186 | void onPostDialWait(Call call, String remaining) { |
| 187 | if (mInCallService != null) { |
| 188 | Log.i(this, "Calling onPostDialWait, remaining = %s", remaining); |
| 189 | try { |
| 190 | mInCallService.setPostDialWait(mCallIdMapper.getCallId(call), remaining); |
| 191 | } catch (RemoteException ignored) { |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 196 | @Override |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 197 | public void onIsConferencedChanged(Call call) { |
| 198 | Log.v(this, "onIsConferencedChanged %s", call); |
| 199 | updateCall(call); |
| 200 | } |
| 201 | |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 202 | void bringToForeground(boolean showDialpad) { |
| 203 | if (mInCallService != null) { |
| 204 | try { |
| 205 | mInCallService.bringToForeground(showDialpad); |
| 206 | } catch (RemoteException ignored) { |
| 207 | } |
| 208 | } else { |
| 209 | Log.w(this, "Asking to bring unbound in-call UI to foreground."); |
| 210 | } |
| 211 | } |
| 212 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 213 | /** |
| 214 | * Unbinds an existing bound connection to the in-call app. |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 215 | */ |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 216 | private void unbind() { |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 217 | ThreadUtil.checkOnMainThread(); |
| 218 | if (mInCallService != null) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 219 | Log.i(this, "Unbinding from InCallService"); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 220 | TelecommApp.getInstance().unbindService(mConnection); |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 221 | mInCallService = null; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | /** |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 226 | * Binds to the in-call app if not already connected by binding directly to the saved |
| 227 | * component name of the {@link IInCallService} implementation. |
| 228 | */ |
| 229 | private void bind() { |
| 230 | ThreadUtil.checkOnMainThread(); |
| 231 | if (mInCallService == null) { |
Santos Cordon | fdfcafa | 2014-06-26 14:49:05 -0700 | [diff] [blame] | 232 | Context context = TelecommApp.getInstance(); |
| 233 | Resources resources = context.getResources(); |
| 234 | ComponentName component = new ComponentName( |
| 235 | resources.getString(R.string.ui_default_package), |
| 236 | resources.getString(R.string.incall_default_class)); |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 237 | Log.i(this, "Attempting to bind to InCallService: %s", component); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 238 | |
| 239 | Intent serviceIntent = new Intent(IInCallService.class.getName()); |
| 240 | serviceIntent.setComponent(component); |
| 241 | |
Amith Yamasani | 60e7584 | 2014-05-23 10:09:14 -0700 | [diff] [blame] | 242 | if (!context.bindServiceAsUser(serviceIntent, mConnection, Context.BIND_AUTO_CREATE, |
| 243 | UserHandle.CURRENT)) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 244 | 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] | 245 | |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 246 | // TODO: Implement retry or fall-back-to-default logic. |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | /** |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 252 | * Persists the {@link IInCallService} instance and starts the communication between |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 253 | * 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] | 254 | * called after a successful binding connection is established. |
| 255 | * |
| 256 | * @param service The {@link IInCallService} implementation. |
| 257 | */ |
| 258 | private void onConnected(IBinder service) { |
| 259 | ThreadUtil.checkOnMainThread(); |
| 260 | mInCallService = IInCallService.Stub.asInterface(service); |
| 261 | |
| 262 | try { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 263 | mInCallService.setInCallAdapter(new InCallAdapter(CallsManager.getInstance(), |
| 264 | mCallIdMapper)); |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 265 | } catch (RemoteException e) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 266 | Log.e(this, e, "Failed to set the in-call adapter."); |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 267 | mInCallService = null; |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 268 | return; |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 271 | // 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] | 272 | ImmutableCollection<Call> calls = CallsManager.getInstance().getCalls(); |
| 273 | if (!calls.isEmpty()) { |
| 274 | for (Call call : calls) { |
| 275 | onCallAdded(call); |
| 276 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 277 | onAudioStateChanged(null, CallsManager.getInstance().getAudioState()); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 278 | } else { |
| 279 | unbind(); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 280 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Cleans up the instance of in-call app after the service has been unbound. |
| 285 | */ |
| 286 | private void onDisconnected() { |
| 287 | ThreadUtil.checkOnMainThread(); |
| 288 | mInCallService = null; |
| 289 | } |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 290 | |
| 291 | private void updateCall(Call call) { |
| 292 | if (mInCallService != null) { |
| 293 | try { |
Santos Cordon | 2583b67 | 2014-07-19 13:07:33 -0700 | [diff] [blame] | 294 | ParcelableCall parcelableCall = toParcelableCall(call); |
| 295 | Log.v(this, "updateCall %s ==> %s", call, parcelableCall); |
| 296 | mInCallService.updateCall(parcelableCall); |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 297 | } catch (RemoteException ignored) { |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
Santos Cordon | 2583b67 | 2014-07-19 13:07:33 -0700 | [diff] [blame] | 302 | private ParcelableCall toParcelableCall(Call call) { |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 303 | String callId = mCallIdMapper.getCallId(call); |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 304 | |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 305 | int capabilities = call.getCallCapabilities(); |
Santos Cordon | 4b034a6 | 2014-07-18 13:42:05 -0700 | [diff] [blame] | 306 | if (CallsManager.getInstance().isAddCallCapable(call)) { |
| 307 | capabilities |= CallCapabilities.ADD_CALL; |
Santos Cordon | 10838c2 | 2014-06-11 17:36:04 -0700 | [diff] [blame] | 308 | } |
Santos Cordon | 4b034a6 | 2014-07-18 13:42:05 -0700 | [diff] [blame] | 309 | if (!call.isEmergencyCall()) { |
| 310 | capabilities |= CallCapabilities.MUTE; |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 311 | } |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 312 | |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 313 | CallState state = call.getState(); |
| 314 | if (state == CallState.ABORTED) { |
| 315 | state = CallState.DISCONNECTED; |
| 316 | } |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 317 | |
| 318 | String parentCallId = null; |
| 319 | Call parentCall = call.getParentCall(); |
| 320 | if (parentCall != null) { |
| 321 | parentCallId = mCallIdMapper.getCallId(parentCall); |
| 322 | } |
| 323 | |
| 324 | long connectTimeMillis = call.getConnectTimeMillis(); |
| 325 | List<Call> childCalls = call.getChildCalls(); |
| 326 | List<String> childCallIds = new ArrayList<>(); |
| 327 | if (!childCalls.isEmpty()) { |
| 328 | connectTimeMillis = Long.MAX_VALUE; |
| 329 | for (Call child : childCalls) { |
| 330 | connectTimeMillis = Math.min(child.getConnectTimeMillis(), connectTimeMillis); |
| 331 | childCallIds.add(mCallIdMapper.getCallId(child)); |
| 332 | } |
| 333 | } |
| 334 | |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 335 | if (call.isRespondViaSmsCapable()) { |
| 336 | capabilities |= CallCapabilities.RESPOND_VIA_TEXT; |
| 337 | } |
| 338 | |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 339 | Uri handle = call.getHandlePresentation() == CallPropertyPresentation.ALLOWED ? |
| 340 | call.getHandle() : null; |
| 341 | String callerDisplayName = call.getCallerDisplayNamePresentation() == |
| 342 | CallPropertyPresentation.ALLOWED ? call.getCallerDisplayName() : null; |
| 343 | |
Santos Cordon | 12d6182 | 2014-07-29 16:02:20 -0700 | [diff] [blame] | 344 | List<Call> conferenceableCalls = call.getConferenceableCalls(); |
| 345 | List<String> conferenceableCallIds = new ArrayList<String>(conferenceableCalls.size()); |
| 346 | for (Call otherCall : conferenceableCalls) { |
| 347 | String otherId = mCallIdMapper.getCallId(otherCall); |
| 348 | if (otherId != null) { |
| 349 | conferenceableCallIds.add(otherId); |
| 350 | } |
| 351 | } |
| 352 | |
Santos Cordon | 2583b67 | 2014-07-19 13:07:33 -0700 | [diff] [blame] | 353 | return new ParcelableCall( |
| 354 | callId, |
| 355 | state, |
| 356 | call.getDisconnectCause(), |
| 357 | call.getDisconnectMessage(), |
| 358 | call.getCannedSmsResponses(), |
| 359 | capabilities, |
| 360 | connectTimeMillis, |
| 361 | handle, |
| 362 | call.getHandlePresentation(), |
| 363 | callerDisplayName, |
| 364 | call.getCallerDisplayNamePresentation(), |
| 365 | call.getGatewayInfo(), |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 366 | call.getTargetPhoneAccount(), |
Andrew Lee | 3bcf935 | 2014-07-23 12:36:05 -0700 | [diff] [blame] | 367 | call.getVideoCallProvider(), |
Santos Cordon | 2583b67 | 2014-07-19 13:07:33 -0700 | [diff] [blame] | 368 | parentCallId, |
| 369 | childCallIds, |
| 370 | call.getStatusHints(), |
Santos Cordon | 12d6182 | 2014-07-29 16:02:20 -0700 | [diff] [blame] | 371 | call.getVideoState(), |
| 372 | conferenceableCallIds); |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 373 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 374 | } |