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