Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 | |
| 19 | import android.content.ComponentName; |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 20 | import android.net.Uri; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 21 | import android.os.Bundle; |
| 22 | import android.os.Handler; |
| 23 | import android.os.IBinder; |
| 24 | import android.os.Message; |
| 25 | import android.os.RemoteException; |
| 26 | import android.telecomm.CallAudioState; |
| 27 | import android.telecomm.ConnectionService; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 28 | import android.telecomm.ConnectionRequest; |
| 29 | import android.telecomm.GatewayInfo; |
Sailesh Nepal | 35faf8c | 2014-07-08 22:02:34 -0700 | [diff] [blame] | 30 | import android.telecomm.StatusHints; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 31 | import android.telecomm.TelecommConstants; |
| 32 | import android.telephony.DisconnectCause; |
| 33 | |
| 34 | import com.android.internal.os.SomeArgs; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 35 | import com.android.internal.telecomm.IConnectionService; |
| 36 | import com.android.internal.telecomm.IConnectionServiceAdapter; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 37 | import com.android.internal.telecomm.ICallVideoProvider; |
| 38 | import com.android.internal.telecomm.RemoteServiceCallback; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 39 | import com.google.common.base.Preconditions; |
| 40 | import com.google.common.collect.ImmutableList; |
| 41 | |
| 42 | import org.apache.http.conn.ClientConnectionRequest; |
| 43 | |
| 44 | import java.util.ArrayList; |
| 45 | import java.util.Collection; |
| 46 | import java.util.HashMap; |
| 47 | import java.util.HashSet; |
| 48 | import java.util.List; |
| 49 | import java.util.Map; |
| 50 | import java.util.Set; |
| 51 | |
| 52 | /** |
| 53 | * Wrapper for {@link IConnectionService}s, handles binding to {@link IConnectionService} and keeps |
| 54 | * track of when the object can safely be unbound. Other classes should not use |
| 55 | * {@link IConnectionService} directly and instead should use this class to invoke methods of |
| 56 | * {@link IConnectionService}. |
| 57 | */ |
| 58 | final class ConnectionServiceWrapper extends ServiceBinder<IConnectionService> { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 59 | private static final int MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL = 1; |
| 60 | private static final int MSG_HANDLE_CREATE_CONNECTION_FAILED = 2; |
| 61 | private static final int MSG_HANDLE_CREATE_CONNECTION_CANCELLED = 3; |
| 62 | private static final int MSG_SET_ACTIVE = 4; |
| 63 | private static final int MSG_SET_RINGING = 5; |
| 64 | private static final int MSG_SET_DIALING = 6; |
| 65 | private static final int MSG_SET_DISCONNECTED = 7; |
| 66 | private static final int MSG_SET_ON_HOLD = 8; |
| 67 | private static final int MSG_SET_REQUESTING_RINGBACK = 9; |
| 68 | private static final int MSG_SET_CALL_CAPABILITIES = 10; |
| 69 | private static final int MSG_SET_IS_CONFERENCED = 11; |
| 70 | private static final int MSG_ADD_CONFERENCE_CALL = 12; |
| 71 | private static final int MSG_REMOVE_CALL = 13; |
| 72 | private static final int MSG_ON_POST_DIAL_WAIT = 14; |
| 73 | private static final int MSG_QUERY_REMOTE_CALL_SERVICES = 15; |
| 74 | private static final int MSG_SET_CALL_VIDEO_PROVIDER = 16; |
| 75 | private static final int MSG_SET_AUDIO_MODE_IS_VOIP = 17; |
| 76 | private static final int MSG_SET_STATUS_HINTS = 18; |
| 77 | private static final int MSG_SET_HANDLE = 19; |
| 78 | private static final int MSG_SET_CALLER_DISPLAY_NAME = 20; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 79 | |
| 80 | private final Handler mHandler = new Handler() { |
| 81 | @Override |
| 82 | public void handleMessage(Message msg) { |
| 83 | Call call; |
| 84 | switch (msg.what) { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 85 | case MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL: { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 86 | ConnectionRequest request = (ConnectionRequest) msg.obj; |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 87 | if (mPendingResponses.containsKey(request.getCallId())) { |
| 88 | mPendingResponses.remove( |
| 89 | request.getCallId()).handleCreateConnectionSuccessful(request); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 90 | } else { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 91 | //Log.w(this, "handleCreateConnectionSuccessful, unknown call: %s", callId); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 92 | } |
| 93 | break; |
| 94 | } |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 95 | case MSG_HANDLE_CREATE_CONNECTION_FAILED: { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 96 | SomeArgs args = (SomeArgs) msg.obj; |
| 97 | try { |
Sailesh Nepal | a49c643 | 2014-07-07 22:47:11 -0700 | [diff] [blame] | 98 | ConnectionRequest request = (ConnectionRequest) args.arg1; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 99 | int statusCode = args.argi1; |
| 100 | String statusMsg = (String) args.arg2; |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 101 | if (mPendingResponses.containsKey(request.getCallId())) { |
| 102 | mPendingResponses.remove(request.getCallId()) |
| 103 | .handleCreateConnectionFailed(statusCode, statusMsg); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 104 | mCallIdMapper.removeCall(request.getCallId()); |
| 105 | } else { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 106 | //Log.w(this, "handleCreateConnectionFailed, unknown call: %s", callId); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 107 | } |
| 108 | } finally { |
| 109 | args.recycle(); |
| 110 | } |
| 111 | break; |
| 112 | } |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 113 | case MSG_HANDLE_CREATE_CONNECTION_CANCELLED: { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 114 | ConnectionRequest request = (ConnectionRequest) msg.obj; |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 115 | if (mPendingResponses.containsKey(request.getCallId())) { |
| 116 | mPendingResponses.remove( |
| 117 | request.getCallId()).handleCreateConnectionCancelled(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 118 | } else { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 119 | //Log.w(this, "handleCreateConnectionCancelled, unknown call: %s", callId); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 120 | } |
| 121 | break; |
| 122 | } |
| 123 | case MSG_SET_ACTIVE: |
| 124 | call = mCallIdMapper.getCall(msg.obj); |
| 125 | if (call != null) { |
| 126 | mCallsManager.markCallAsActive(call); |
| 127 | } else { |
| 128 | //Log.w(this, "setActive, unknown call id: %s", msg.obj); |
| 129 | } |
| 130 | break; |
| 131 | case MSG_SET_RINGING: |
| 132 | call = mCallIdMapper.getCall(msg.obj); |
| 133 | if (call != null) { |
| 134 | mCallsManager.markCallAsRinging(call); |
| 135 | } else { |
| 136 | //Log.w(this, "setRinging, unknown call id: %s", msg.obj); |
| 137 | } |
| 138 | break; |
| 139 | case MSG_SET_DIALING: |
| 140 | call = mCallIdMapper.getCall(msg.obj); |
| 141 | if (call != null) { |
| 142 | mCallsManager.markCallAsDialing(call); |
| 143 | } else { |
| 144 | //Log.w(this, "setDialing, unknown call id: %s", msg.obj); |
| 145 | } |
| 146 | break; |
| 147 | case MSG_SET_DISCONNECTED: { |
| 148 | SomeArgs args = (SomeArgs) msg.obj; |
| 149 | try { |
| 150 | call = mCallIdMapper.getCall(args.arg1); |
| 151 | String disconnectMessage = (String) args.arg2; |
| 152 | int disconnectCause = args.argi1; |
| 153 | if (call != null) { |
| 154 | mCallsManager.markCallAsDisconnected(call, disconnectCause, |
| 155 | disconnectMessage); |
| 156 | } else { |
| 157 | //Log.w(this, "setDisconnected, unknown call id: %s", args.arg1); |
| 158 | } |
| 159 | } finally { |
| 160 | args.recycle(); |
| 161 | } |
| 162 | break; |
| 163 | } |
| 164 | case MSG_SET_ON_HOLD: |
| 165 | call = mCallIdMapper.getCall(msg.obj); |
| 166 | if (call != null) { |
| 167 | mCallsManager.markCallAsOnHold(call); |
| 168 | } else { |
| 169 | //Log.w(this, "setOnHold, unknown call id: %s", msg.obj); |
| 170 | } |
| 171 | break; |
| 172 | case MSG_SET_REQUESTING_RINGBACK: { |
| 173 | SomeArgs args = (SomeArgs) msg.obj; |
| 174 | try { |
| 175 | call = mCallIdMapper.getCall(args.arg1); |
| 176 | boolean ringback = (boolean) args.arg2; |
| 177 | if (call != null) { |
| 178 | call.setRequestingRingback(ringback); |
| 179 | } else { |
| 180 | //Log.w(this, "setRingback, unknown call id: %s", args.arg1); |
| 181 | } |
| 182 | } finally { |
| 183 | args.recycle(); |
| 184 | } |
| 185 | break; |
| 186 | } |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 187 | case MSG_SET_CALL_CAPABILITIES: { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 188 | call = mCallIdMapper.getCall(msg.obj); |
| 189 | if (call != null) { |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 190 | call.setCallCapabilities(msg.arg1); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 191 | } else { |
| 192 | //Log.w(ConnectionServiceWrapper.this, |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 193 | // "setCallCapabilities, unknown call id: %s", msg.obj); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 194 | } |
| 195 | break; |
| 196 | } |
| 197 | case MSG_SET_IS_CONFERENCED: { |
| 198 | SomeArgs args = (SomeArgs) msg.obj; |
| 199 | try { |
| 200 | Call childCall = mCallIdMapper.getCall(args.arg1); |
| 201 | if (childCall != null) { |
| 202 | String conferenceCallId = (String) args.arg2; |
| 203 | if (conferenceCallId == null) { |
| 204 | childCall.setParentCall(null); |
| 205 | } else { |
| 206 | Call conferenceCall = mCallIdMapper.getCall(conferenceCallId); |
| 207 | if (conferenceCall != null && |
| 208 | !mPendingConferenceCalls.contains(conferenceCall)) { |
| 209 | childCall.setParentCall(conferenceCall); |
| 210 | } else { |
| 211 | //Log.w(this, "setIsConferenced, unknown conference id %s", |
| 212 | // conferenceCallId); |
| 213 | } |
| 214 | } |
| 215 | } else { |
| 216 | //Log.w(this, "setIsConferenced, unknown call id: %s", args.arg1); |
| 217 | } |
| 218 | } finally { |
| 219 | args.recycle(); |
| 220 | } |
| 221 | break; |
| 222 | } |
| 223 | case MSG_ADD_CONFERENCE_CALL: { |
| 224 | Call conferenceCall = mCallIdMapper.getCall(msg.obj); |
| 225 | if (mPendingConferenceCalls.remove(conferenceCall)) { |
| 226 | Log.v(this, "confirming conf call %s", conferenceCall); |
| 227 | conferenceCall.confirmConference(); |
| 228 | } else { |
| 229 | //Log.w(this, "addConference, unknown call id: %s", callId); |
| 230 | } |
| 231 | break; |
| 232 | } |
| 233 | case MSG_REMOVE_CALL: |
| 234 | break; |
| 235 | case MSG_ON_POST_DIAL_WAIT: { |
| 236 | SomeArgs args = (SomeArgs) msg.obj; |
| 237 | try { |
| 238 | call = mCallIdMapper.getCall(args.arg1); |
| 239 | if (call != null) { |
| 240 | String remaining = (String) args.arg2; |
| 241 | call.onPostDialWait(remaining); |
| 242 | } else { |
| 243 | //Log.w(this, "onPostDialWait, unknown call id: %s", args.arg1); |
| 244 | } |
| 245 | } finally { |
| 246 | args.recycle(); |
| 247 | } |
| 248 | break; |
| 249 | } |
| 250 | case MSG_QUERY_REMOTE_CALL_SERVICES: { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 251 | queryRemoteConnectionServices((RemoteServiceCallback) msg.obj); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 252 | break; |
| 253 | } |
| 254 | case MSG_SET_CALL_VIDEO_PROVIDER: { |
| 255 | SomeArgs args = (SomeArgs) msg.obj; |
| 256 | try { |
| 257 | call = mCallIdMapper.getCall(args.arg1); |
| 258 | ICallVideoProvider callVideoProvider = (ICallVideoProvider) args.arg2; |
| 259 | if (call != null) { |
| 260 | call.setCallVideoProvider(callVideoProvider); |
| 261 | } |
| 262 | } finally { |
| 263 | args.recycle(); |
| 264 | } |
| 265 | break; |
| 266 | } |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 267 | case MSG_SET_AUDIO_MODE_IS_VOIP: { |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 268 | call = mCallIdMapper.getCall(msg.obj); |
| 269 | if (call != null) { |
| 270 | call.setAudioModeIsVoip(msg.arg1 == 1); |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 271 | } |
| 272 | break; |
| 273 | } |
Sailesh Nepal | 35faf8c | 2014-07-08 22:02:34 -0700 | [diff] [blame] | 274 | case MSG_SET_STATUS_HINTS: { |
| 275 | SomeArgs args = (SomeArgs) msg.obj; |
| 276 | try { |
| 277 | call = mCallIdMapper.getCall(args.arg1); |
| 278 | StatusHints statusHints = (StatusHints) args.arg2; |
| 279 | if (call != null) { |
| 280 | call.setStatusHints(statusHints); |
| 281 | } |
| 282 | } finally { |
| 283 | args.recycle(); |
| 284 | } |
| 285 | break; |
| 286 | } |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 287 | case MSG_SET_HANDLE: { |
| 288 | SomeArgs args = (SomeArgs) msg.obj; |
| 289 | try { |
| 290 | call = mCallIdMapper.getCall(args.arg1); |
| 291 | if (call != null) { |
| 292 | call.setHandle((Uri) args.arg2, args.argi1); |
| 293 | } |
| 294 | } finally { |
| 295 | args.recycle(); |
| 296 | } |
| 297 | break; |
| 298 | } |
| 299 | case MSG_SET_CALLER_DISPLAY_NAME: { |
| 300 | SomeArgs args = (SomeArgs) msg.obj; |
| 301 | try { |
| 302 | call = mCallIdMapper.getCall(args.arg1); |
| 303 | if (call != null) { |
| 304 | call.setCallerDisplayName((String) args.arg2, args.argi1); |
| 305 | } |
| 306 | } finally { |
| 307 | args.recycle(); |
| 308 | } |
| 309 | break; |
| 310 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | }; |
| 314 | |
| 315 | private final class Adapter extends IConnectionServiceAdapter.Stub { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 316 | @Override |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 317 | public void handleCreateConnectionSuccessful(ConnectionRequest request) { |
| 318 | logIncoming("handleCreateConnectionSuccessful %s", request); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 319 | mCallIdMapper.checkValidCallId(request.getCallId()); |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 320 | mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL, request).sendToTarget(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 323 | @Override |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 324 | public void handleCreateConnectionFailed( |
| 325 | ConnectionRequest request, int errorCode, String errorMsg) { |
| 326 | logIncoming("handleCreateConnectionFailed %s %d %s", request, errorCode, errorMsg); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 327 | mCallIdMapper.checkValidCallId(request.getCallId()); |
| 328 | SomeArgs args = SomeArgs.obtain(); |
| 329 | args.arg1 = request; |
| 330 | args.argi1 = errorCode; |
| 331 | args.arg2 = errorMsg; |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 332 | mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_FAILED, args).sendToTarget(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 335 | @Override |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 336 | public void handleCreateConnectionCancelled(ConnectionRequest request) { |
| 337 | logIncoming("handleCreateConnectionCancelled %s", request); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 338 | mCallIdMapper.checkValidCallId(request.getCallId()); |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 339 | mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_CANCELLED, request).sendToTarget(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 342 | @Override |
| 343 | public void setActive(String callId) { |
| 344 | logIncoming("setActive %s", callId); |
| 345 | mCallIdMapper.checkValidCallId(callId); |
| 346 | mHandler.obtainMessage(MSG_SET_ACTIVE, callId).sendToTarget(); |
| 347 | } |
| 348 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 349 | @Override |
| 350 | public void setRinging(String callId) { |
| 351 | logIncoming("setRinging %s", callId); |
| 352 | mCallIdMapper.checkValidCallId(callId); |
| 353 | mHandler.obtainMessage(MSG_SET_RINGING, callId).sendToTarget(); |
| 354 | } |
| 355 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 356 | @Override |
| 357 | public void setCallVideoProvider(String callId, ICallVideoProvider callVideoProvider) { |
| 358 | logIncoming("setCallVideoProvider %s", callId); |
| 359 | mCallIdMapper.checkValidCallId(callId); |
| 360 | SomeArgs args = SomeArgs.obtain(); |
| 361 | args.arg1 = callId; |
| 362 | args.arg2 = callVideoProvider; |
| 363 | mHandler.obtainMessage(MSG_SET_CALL_VIDEO_PROVIDER, args).sendToTarget(); |
| 364 | } |
| 365 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 366 | @Override |
| 367 | public void setDialing(String callId) { |
| 368 | logIncoming("setDialing %s", callId); |
| 369 | mCallIdMapper.checkValidCallId(callId); |
| 370 | mHandler.obtainMessage(MSG_SET_DIALING, callId).sendToTarget(); |
| 371 | } |
| 372 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 373 | @Override |
| 374 | public void setDisconnected( |
| 375 | String callId, int disconnectCause, String disconnectMessage) { |
| 376 | logIncoming("setDisconnected %s %d %s", callId, disconnectCause, disconnectMessage); |
| 377 | mCallIdMapper.checkValidCallId(callId); |
| 378 | SomeArgs args = SomeArgs.obtain(); |
| 379 | args.arg1 = callId; |
| 380 | args.arg2 = disconnectMessage; |
| 381 | args.argi1 = disconnectCause; |
| 382 | mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget(); |
| 383 | } |
| 384 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 385 | @Override |
| 386 | public void setOnHold(String callId) { |
| 387 | logIncoming("setOnHold %s", callId); |
| 388 | mCallIdMapper.checkValidCallId(callId); |
| 389 | mHandler.obtainMessage(MSG_SET_ON_HOLD, callId).sendToTarget(); |
| 390 | } |
| 391 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 392 | @Override |
| 393 | public void setRequestingRingback(String callId, boolean ringback) { |
| 394 | logIncoming("setRequestingRingback %s %b", callId, ringback); |
| 395 | mCallIdMapper.checkValidCallId(callId); |
| 396 | SomeArgs args = SomeArgs.obtain(); |
| 397 | args.arg1 = callId; |
| 398 | args.arg2 = ringback; |
| 399 | mHandler.obtainMessage(MSG_SET_REQUESTING_RINGBACK, args).sendToTarget(); |
| 400 | } |
| 401 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 402 | @Override |
| 403 | public void removeCall(String callId) { |
| 404 | logIncoming("removeCall %s", callId); |
| 405 | } |
| 406 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 407 | @Override |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 408 | public void setCallCapabilities(String callId, int callCapabilities) { |
| 409 | logIncoming("setCallCapabilities %s %d", callId, callCapabilities); |
| 410 | mHandler.obtainMessage(MSG_SET_CALL_CAPABILITIES, callCapabilities, 0, callId) |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 411 | .sendToTarget(); |
| 412 | } |
| 413 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 414 | @Override |
| 415 | public void setIsConferenced(String callId, String conferenceCallId) { |
| 416 | logIncoming("setIsConferenced %s %s", callId, conferenceCallId); |
| 417 | SomeArgs args = SomeArgs.obtain(); |
| 418 | args.arg1 = callId; |
| 419 | args.arg2 = conferenceCallId; |
| 420 | mHandler.obtainMessage(MSG_SET_IS_CONFERENCED, args).sendToTarget(); |
| 421 | } |
| 422 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 423 | @Override |
| 424 | public void addConferenceCall(String callId) { |
| 425 | logIncoming("addConferenceCall %s", callId); |
| 426 | mCallIdMapper.checkValidCallId(callId); |
| 427 | mHandler.obtainMessage(MSG_ADD_CONFERENCE_CALL, callId).sendToTarget(); |
| 428 | } |
| 429 | |
| 430 | @Override |
| 431 | public void onPostDialWait(String callId, String remaining) throws RemoteException { |
| 432 | logIncoming("onPostDialWait %s %s", callId, remaining); |
| 433 | mCallIdMapper.checkValidCallId(callId); |
| 434 | SomeArgs args = SomeArgs.obtain(); |
| 435 | args.arg1 = callId; |
| 436 | args.arg2 = remaining; |
| 437 | mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget(); |
| 438 | } |
| 439 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 440 | @Override |
| 441 | public void queryRemoteConnectionServices(RemoteServiceCallback callback) { |
| 442 | logIncoming("queryRemoteCSs"); |
| 443 | mHandler.obtainMessage(MSG_QUERY_REMOTE_CALL_SERVICES, callback).sendToTarget(); |
| 444 | } |
| 445 | |
| 446 | @Override |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 447 | public void setAudioModeIsVoip(String callId, boolean isVoip) { |
Sailesh Nepal | 7fa33ca | 2014-07-10 15:28:21 -0700 | [diff] [blame] | 448 | logIncoming("setAudioModeIsVoip %s %b", callId, isVoip); |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 449 | mCallIdMapper.checkValidCallId(callId); |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 450 | mHandler.obtainMessage(MSG_SET_AUDIO_MODE_IS_VOIP, isVoip ? 1 : 0, 0, |
| 451 | callId).sendToTarget(); |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 452 | } |
Sailesh Nepal | 35faf8c | 2014-07-08 22:02:34 -0700 | [diff] [blame] | 453 | |
| 454 | @Override |
| 455 | public void setStatusHints(String callId, StatusHints statusHints) { |
| 456 | logIncoming("setStatusHints %s %s", callId, statusHints); |
| 457 | mCallIdMapper.checkValidCallId(callId); |
| 458 | SomeArgs args = SomeArgs.obtain(); |
| 459 | args.arg1 = callId; |
| 460 | args.arg2 = statusHints; |
| 461 | mHandler.obtainMessage(MSG_SET_STATUS_HINTS, args).sendToTarget(); |
| 462 | } |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 463 | |
| 464 | @Override |
| 465 | public void setHandle(String callId, Uri handle, int presentation) { |
| 466 | logIncoming("setHandle %s %s %d", callId, handle, presentation); |
| 467 | mCallIdMapper.checkValidCallId(callId); |
| 468 | SomeArgs args = SomeArgs.obtain(); |
| 469 | args.arg1 = callId; |
| 470 | args.arg2 = handle; |
| 471 | args.argi1 = presentation; |
| 472 | mHandler.obtainMessage(MSG_SET_HANDLE, args).sendToTarget(); |
| 473 | } |
| 474 | |
| 475 | @Override |
| 476 | public void setCallerDisplayName( |
| 477 | String callId, String callerDisplayName, int presentation) { |
| 478 | logIncoming("setCallerDisplayName %s %s %d", callId, callerDisplayName, presentation); |
| 479 | mCallIdMapper.checkValidCallId(callId); |
| 480 | SomeArgs args = SomeArgs.obtain(); |
| 481 | args.arg1 = callId; |
| 482 | args.arg2 = callerDisplayName; |
| 483 | args.argi1 = presentation; |
| 484 | mHandler.obtainMessage(MSG_SET_CALLER_DISPLAY_NAME, args).sendToTarget(); |
| 485 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | private final Adapter mAdapter = new Adapter(); |
| 489 | private final CallsManager mCallsManager = CallsManager.getInstance(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 490 | private final Set<Call> mPendingConferenceCalls = new HashSet<>(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 491 | private final CallIdMapper mCallIdMapper = new CallIdMapper("ConnectionService"); |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 492 | private final Map<String, CreateConnectionResponse> mPendingResponses = new HashMap<>(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 493 | |
| 494 | private Binder mBinder = new Binder(); |
| 495 | private IConnectionService mServiceInterface; |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 496 | private final ConnectionServiceRepository mConnectionServiceRepository; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 497 | |
| 498 | /** |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 499 | * Creates a connection service. |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 500 | * |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 501 | * @param componentName The component name of the service with which to bind. |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 502 | * @param connectionServiceRepository Connection service repository. |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 503 | */ |
| 504 | ConnectionServiceWrapper( |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 505 | ComponentName componentName, ConnectionServiceRepository connectionServiceRepository) { |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 506 | super(TelecommConstants.ACTION_CONNECTION_SERVICE, componentName); |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 507 | mConnectionServiceRepository = connectionServiceRepository; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | /** See {@link IConnectionService#addConnectionServiceAdapter}. */ |
| 511 | private void addConnectionServiceAdapter(IConnectionServiceAdapter adapter) { |
| 512 | if (isServiceValid("addConnectionServiceAdapter")) { |
| 513 | try { |
Sailesh Nepal | 3fe8b72 | 2014-07-08 10:07:26 -0700 | [diff] [blame] | 514 | logOutgoing("addConnectionServiceAdapter %s", adapter); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 515 | mServiceInterface.addConnectionServiceAdapter(adapter); |
| 516 | } catch (RemoteException e) { |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | /** |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 522 | * Creates a new connection for a new outgoing call or to attach to an existing incoming call. |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 523 | */ |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 524 | void createConnection(final Call call, final CreateConnectionResponse response) { |
| 525 | Log.d(this, "createConnection(%s) via %s.", call, getComponentName()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 526 | BindCallback callback = new BindCallback() { |
| 527 | @Override |
| 528 | public void onSuccess() { |
| 529 | String callId = mCallIdMapper.getCallId(call); |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 530 | mPendingResponses.put(callId, response); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 531 | |
| 532 | GatewayInfo gatewayInfo = call.getGatewayInfo(); |
| 533 | Bundle extras = call.getExtras(); |
| 534 | if (gatewayInfo != null && gatewayInfo.getGatewayProviderPackageName() != null && |
| 535 | gatewayInfo.getOriginalHandle() != null) { |
| 536 | extras = (Bundle) extras.clone(); |
| 537 | extras.putString( |
| 538 | NewOutgoingCallIntentBroadcaster.EXTRA_GATEWAY_PROVIDER_PACKAGE, |
| 539 | gatewayInfo.getGatewayProviderPackageName()); |
| 540 | extras.putParcelable( |
| 541 | NewOutgoingCallIntentBroadcaster.EXTRA_GATEWAY_ORIGINAL_URI, |
| 542 | gatewayInfo.getOriginalHandle()); |
| 543 | } |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 544 | ConnectionRequest request = new ConnectionRequest( |
| 545 | call.getPhoneAccount(), |
| 546 | callId, |
| 547 | call.getHandle(), |
| 548 | call.getHandlePresentation(), |
| 549 | extras, |
Tyler Gunn | c4abd91 | 2014-07-08 14:22:10 -0700 | [diff] [blame] | 550 | call.getVideoState()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 551 | |
| 552 | try { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 553 | mServiceInterface.createConnection(request, call.isIncoming()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 554 | } catch (RemoteException e) { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 555 | Log.e(this, e, "Failure to createConnection -- %s", getComponentName()); |
| 556 | mPendingResponses.remove(callId).handleCreateConnectionFailed( |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 557 | DisconnectCause.ERROR_UNSPECIFIED, e.toString()); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | @Override |
| 562 | public void onFailure() { |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 563 | Log.e(this, new Exception(), "Failure to call %s", getComponentName()); |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 564 | response.handleCreateConnectionFailed(DisconnectCause.ERROR_UNSPECIFIED, null); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 565 | } |
| 566 | }; |
| 567 | |
| 568 | mBinder.bind(callback); |
| 569 | } |
| 570 | |
| 571 | /** @see ConnectionService#abort(String) */ |
| 572 | void abort(Call call) { |
| 573 | // Clear out any pending outgoing call data |
| 574 | String callId = mCallIdMapper.getCallId(call); |
| 575 | |
| 576 | // If still bound, tell the connection service to abort. |
| 577 | if (isServiceValid("abort")) { |
| 578 | try { |
| 579 | logOutgoing("abort %s", callId); |
| 580 | mServiceInterface.abort(callId); |
| 581 | } catch (RemoteException e) { |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | removeCall(call); |
| 586 | } |
| 587 | |
| 588 | /** @see ConnectionService#hold(String) */ |
| 589 | void hold(Call call) { |
| 590 | if (isServiceValid("hold")) { |
| 591 | try { |
| 592 | logOutgoing("hold %s", mCallIdMapper.getCallId(call)); |
| 593 | mServiceInterface.hold(mCallIdMapper.getCallId(call)); |
| 594 | } catch (RemoteException e) { |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | /** @see ConnectionService#unhold(String) */ |
| 600 | void unhold(Call call) { |
| 601 | if (isServiceValid("unhold")) { |
| 602 | try { |
| 603 | logOutgoing("unhold %s", mCallIdMapper.getCallId(call)); |
| 604 | mServiceInterface.unhold(mCallIdMapper.getCallId(call)); |
| 605 | } catch (RemoteException e) { |
| 606 | } |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | /** @see ConnectionService#onAudioStateChanged(String,CallAudioState) */ |
| 611 | void onAudioStateChanged(Call activeCall, CallAudioState audioState) { |
| 612 | if (isServiceValid("onAudioStateChanged")) { |
| 613 | try { |
| 614 | logOutgoing("onAudioStateChanged %s %s", |
| 615 | mCallIdMapper.getCallId(activeCall), audioState); |
| 616 | mServiceInterface.onAudioStateChanged(mCallIdMapper.getCallId(activeCall), |
| 617 | audioState); |
| 618 | } catch (RemoteException e) { |
| 619 | } |
| 620 | } |
| 621 | } |
| 622 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 623 | /** @see ConnectionService#disconnect(String) */ |
| 624 | void disconnect(Call call) { |
| 625 | if (isServiceValid("disconnect")) { |
| 626 | try { |
| 627 | logOutgoing("disconnect %s", mCallIdMapper.getCallId(call)); |
| 628 | mServiceInterface.disconnect(mCallIdMapper.getCallId(call)); |
| 629 | } catch (RemoteException e) { |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | /** @see ConnectionService#answer(String) */ |
| 635 | void answer(Call call) { |
| 636 | if (isServiceValid("answer")) { |
| 637 | try { |
| 638 | logOutgoing("answer %s", mCallIdMapper.getCallId(call)); |
| 639 | mServiceInterface.answer(mCallIdMapper.getCallId(call)); |
| 640 | } catch (RemoteException e) { |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | /** @see ConnectionService#reject(String) */ |
| 646 | void reject(Call call) { |
| 647 | if (isServiceValid("reject")) { |
| 648 | try { |
| 649 | logOutgoing("reject %s", mCallIdMapper.getCallId(call)); |
| 650 | mServiceInterface.reject(mCallIdMapper.getCallId(call)); |
| 651 | } catch (RemoteException e) { |
| 652 | } |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | /** @see ConnectionService#playDtmfTone(String,char) */ |
| 657 | void playDtmfTone(Call call, char digit) { |
| 658 | if (isServiceValid("playDtmfTone")) { |
| 659 | try { |
| 660 | logOutgoing("playDtmfTone %s %c", mCallIdMapper.getCallId(call), digit); |
| 661 | mServiceInterface.playDtmfTone(mCallIdMapper.getCallId(call), digit); |
| 662 | } catch (RemoteException e) { |
| 663 | } |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | /** @see ConnectionService#stopDtmfTone(String) */ |
| 668 | void stopDtmfTone(Call call) { |
| 669 | if (isServiceValid("stopDtmfTone")) { |
| 670 | try { |
| 671 | logOutgoing("stopDtmfTone %s", mCallIdMapper.getCallId(call)); |
| 672 | mServiceInterface.stopDtmfTone(mCallIdMapper.getCallId(call)); |
| 673 | } catch (RemoteException e) { |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | void addCall(Call call) { |
| 679 | if (mCallIdMapper.getCallId(call) == null) { |
| 680 | mCallIdMapper.addCall(call); |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * Associates newCall with this connection service by replacing callToReplace. |
| 686 | */ |
| 687 | void replaceCall(Call newCall, Call callToReplace) { |
| 688 | Preconditions.checkState(callToReplace.getConnectionService() == this); |
| 689 | mCallIdMapper.replaceCall(newCall, callToReplace); |
| 690 | } |
| 691 | |
| 692 | void removeCall(Call call) { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 693 | CreateConnectionResponse response = mPendingResponses.remove(mCallIdMapper.getCallId(call)); |
| 694 | if (response != null) { |
| 695 | response.handleCreateConnectionFailed(DisconnectCause.ERROR_UNSPECIFIED, null); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | mCallIdMapper.removeCall(call); |
| 699 | } |
| 700 | |
| 701 | void onPostDialContinue(Call call, boolean proceed) { |
| 702 | if (isServiceValid("onPostDialContinue")) { |
| 703 | try { |
| 704 | logOutgoing("onPostDialContinue %s %b", mCallIdMapper.getCallId(call), proceed); |
| 705 | mServiceInterface.onPostDialContinue(mCallIdMapper.getCallId(call), proceed); |
| 706 | } catch (RemoteException ignored) { |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | void onPhoneAccountClicked(Call call) { |
| 712 | if (isServiceValid("onPhoneAccountClicked")) { |
| 713 | try { |
| 714 | logOutgoing("onPhoneAccountClicked %s", mCallIdMapper.getCallId(call)); |
| 715 | mServiceInterface.onPhoneAccountClicked(mCallIdMapper.getCallId(call)); |
| 716 | } catch (RemoteException ignored) { |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | void conference(final Call conferenceCall, Call call) { |
| 722 | if (isServiceValid("conference")) { |
| 723 | try { |
| 724 | conferenceCall.setConnectionService(this); |
| 725 | mPendingConferenceCalls.add(conferenceCall); |
| 726 | mHandler.postDelayed(new Runnable() { |
| 727 | @Override public void run() { |
| 728 | if (mPendingConferenceCalls.remove(conferenceCall)) { |
| 729 | conferenceCall.expireConference(); |
| 730 | Log.i(this, "Conference call expired: %s", conferenceCall); |
| 731 | } |
| 732 | } |
| 733 | }, Timeouts.getConferenceCallExpireMillis()); |
| 734 | |
| 735 | logOutgoing("conference %s %s", |
| 736 | mCallIdMapper.getCallId(conferenceCall), |
| 737 | mCallIdMapper.getCallId(call)); |
| 738 | mServiceInterface.conference( |
| 739 | mCallIdMapper.getCallId(conferenceCall), |
| 740 | mCallIdMapper.getCallId(call)); |
| 741 | } catch (RemoteException ignored) { |
| 742 | } |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | void splitFromConference(Call call) { |
| 747 | if (isServiceValid("splitFromConference")) { |
| 748 | try { |
| 749 | logOutgoing("splitFromConference %s", mCallIdMapper.getCallId(call)); |
| 750 | mServiceInterface.splitFromConference(mCallIdMapper.getCallId(call)); |
| 751 | } catch (RemoteException ignored) { |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 756 | void swapWithBackgroundCall(Call call) { |
| 757 | if (isServiceValid("swapWithBackgroundCall")) { |
| 758 | try { |
| 759 | logOutgoing("swapWithBackgroundCall %s", mCallIdMapper.getCallId(call)); |
| 760 | mServiceInterface.swapWithBackgroundCall(mCallIdMapper.getCallId(call)); |
| 761 | } catch (RemoteException ignored) { |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 766 | /** {@inheritDoc} */ |
| 767 | @Override |
| 768 | protected void setServiceInterface(IBinder binder) { |
| 769 | if (binder == null) { |
| 770 | // We have lost our service connection. Notify the world that this service is done. |
| 771 | // We must notify the adapter before CallsManager. The adapter will force any pending |
| 772 | // outgoing calls to try the next service. This needs to happen before CallsManager |
| 773 | // tries to clean up any calls still associated with this service. |
| 774 | handleConnectionServiceDeath(); |
| 775 | CallsManager.getInstance().handleConnectionServiceDeath(this); |
| 776 | mServiceInterface = null; |
| 777 | } else { |
| 778 | mServiceInterface = IConnectionService.Stub.asInterface(binder); |
| 779 | addConnectionServiceAdapter(mAdapter); |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | /** |
| 784 | * Called when the associated connection service dies. |
| 785 | */ |
| 786 | private void handleConnectionServiceDeath() { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 787 | if (!mPendingResponses.isEmpty()) { |
| 788 | CreateConnectionResponse[] responses = mPendingResponses.values().toArray( |
| 789 | new CreateConnectionResponse[mPendingResponses.values().size()]); |
| 790 | mPendingResponses.clear(); |
| 791 | for (int i = 0; i < responses.length; i++) { |
| 792 | responses[i].handleCreateConnectionFailed(DisconnectCause.ERROR_UNSPECIFIED, null); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 793 | } |
| 794 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 795 | mCallIdMapper.clear(); |
| 796 | } |
| 797 | |
| 798 | private void logIncoming(String msg, Object... params) { |
| 799 | Log.d(this, "ConnectionService -> Telecomm: " + msg, params); |
| 800 | } |
| 801 | |
| 802 | private void logOutgoing(String msg, Object... params) { |
| 803 | Log.d(this, "Telecomm -> ConnectionService: " + msg, params); |
| 804 | } |
| 805 | |
| 806 | private void queryRemoteConnectionServices(final RemoteServiceCallback callback) { |
| 807 | final List<IBinder> connectionServices = new ArrayList<>(); |
| 808 | final List<ComponentName> components = new ArrayList<>(); |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 809 | final List<ConnectionServiceWrapper> servciesAttempted = new ArrayList<>(); |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 810 | final Collection<ConnectionServiceWrapper> services = |
| 811 | mConnectionServiceRepository.lookupServices(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 812 | |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 813 | Log.v(this, "queryRemoteConnectionServices, services: " + services.size()); |
| 814 | |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 815 | for (ConnectionServiceWrapper cs : services) { |
| 816 | if (cs != this) { |
| 817 | final ConnectionServiceWrapper currentConnectionService = cs; |
| 818 | cs.mBinder.bind(new BindCallback() { |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 819 | @Override |
| 820 | public void onSuccess() { |
| 821 | Log.d(this, "Adding ***** %s", currentConnectionService.getComponentName()); |
| 822 | connectionServices.add( |
| 823 | currentConnectionService.mServiceInterface.asBinder()); |
| 824 | components.add(currentConnectionService.getComponentName()); |
| 825 | maybeComplete(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 826 | } |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 827 | |
| 828 | @Override |
| 829 | public void onFailure() { |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 830 | maybeComplete(); |
| 831 | } |
| 832 | |
| 833 | private void maybeComplete() { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 834 | servciesAttempted.add(currentConnectionService); |
| 835 | if (servciesAttempted.size() == services.size() - 1) { |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 836 | try { |
| 837 | callback.onResult(components, connectionServices); |
| 838 | } catch (RemoteException ignored) { |
| 839 | } |
| 840 | } |
| 841 | } |
| 842 | }); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 843 | } |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 844 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 845 | } |
| 846 | } |