Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [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 | |
Evan Charlton | a05805b | 2014-03-05 08:21:46 -0800 | [diff] [blame] | 19 | import android.os.Bundle; |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 20 | import android.os.Handler; |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 21 | import android.os.IBinder; |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 22 | import android.os.Message; |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 23 | import android.os.RemoteException; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 24 | import android.telecomm.CallAudioState; |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 25 | import android.telecomm.CallInfo; |
Evan Charlton | a05805b | 2014-03-05 08:21:46 -0800 | [diff] [blame] | 26 | import android.telecomm.CallService; |
Ben Gilad | c5b2269 | 2014-02-18 20:03:22 -0800 | [diff] [blame] | 27 | import android.telecomm.CallServiceDescriptor; |
Ihab Awad | a3cb9e3 | 2014-06-03 18:45:05 -0700 | [diff] [blame] | 28 | import android.telecomm.ConnectionRequest; |
Sailesh Nepal | 83cfe7c | 2014-03-11 19:54:22 -0700 | [diff] [blame] | 29 | import android.telecomm.TelecommConstants; |
Ihab Awad | a3cb9e3 | 2014-06-03 18:45:05 -0700 | [diff] [blame] | 30 | import android.telephony.DisconnectCause; |
Sailesh Nepal | a439e1b | 2014-03-11 18:19:58 -0700 | [diff] [blame] | 31 | |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 32 | import com.android.internal.os.SomeArgs; |
Sailesh Nepal | a439e1b | 2014-03-11 18:19:58 -0700 | [diff] [blame] | 33 | import com.android.internal.telecomm.ICallService; |
| 34 | import com.android.internal.telecomm.ICallServiceAdapter; |
| 35 | import com.android.internal.telecomm.ICallServiceProvider; |
Sailesh Nepal | 0e5410a | 2014-04-04 01:20:58 -0700 | [diff] [blame] | 36 | import com.google.common.base.Preconditions; |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 37 | import com.google.common.collect.ImmutableList; |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 38 | |
Ihab Awad | a3cb9e3 | 2014-06-03 18:45:05 -0700 | [diff] [blame] | 39 | import org.apache.http.conn.ClientConnectionRequest; |
| 40 | |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 41 | import java.util.HashMap; |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 42 | import java.util.HashSet; |
Santos Cordon | 8f3282c | 2014-06-01 13:56:02 -0700 | [diff] [blame] | 43 | import java.util.List; |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 44 | import java.util.Map; |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 45 | import java.util.Set; |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Wrapper for {@link ICallService}s, handles binding to {@link ICallService} and keeps track of |
| 49 | * when the object can safely be unbound. Other classes should not use {@link ICallService} directly |
| 50 | * and instead should use this class to invoke methods of {@link ICallService}. |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 51 | */ |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 52 | final class CallServiceWrapper extends ServiceBinder<ICallService> { |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 53 | private static final String TAG = CallServiceWrapper.class.getSimpleName(); |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 54 | |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 55 | private final class Adapter extends ICallServiceAdapter.Stub { |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 56 | private static final int MSG_NOTIFY_INCOMING_CALL = 1; |
| 57 | private static final int MSG_HANDLE_SUCCESSFUL_OUTGOING_CALL = 2; |
| 58 | private static final int MSG_HANDLE_FAILED_OUTGOING_CALL = 3; |
| 59 | private static final int MSG_SET_ACTIVE = 4; |
| 60 | private static final int MSG_SET_RINGING = 5; |
| 61 | private static final int MSG_SET_DIALING = 6; |
| 62 | private static final int MSG_SET_DISCONNECTED = 7; |
| 63 | private static final int MSG_SET_ON_HOLD = 8; |
Ihab Awad | 50a5713 | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 64 | private static final int MSG_SET_REQUESTING_RINGBACK = 9; |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 65 | private static final int MSG_ON_POST_DIAL_WAIT = 10; |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 66 | private static final int MSG_CAN_CONFERENCE = 11; |
| 67 | private static final int MSG_SET_IS_CONFERENCED = 12; |
| 68 | private static final int MSG_ADD_CONFERENCE_CALL = 13; |
| 69 | private static final int MSG_HANDOFF_CALL = 14; |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 70 | |
| 71 | private final Handler mHandler = new Handler() { |
| 72 | @Override |
| 73 | public void handleMessage(Message msg) { |
| 74 | Call call; |
| 75 | switch (msg.what) { |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 76 | case MSG_NOTIFY_INCOMING_CALL: |
| 77 | CallInfo clientCallInfo = (CallInfo) msg.obj; |
| 78 | call = mCallIdMapper.getCall(clientCallInfo.getId()); |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 79 | if (call != null && mPendingIncomingCalls.remove(call) && |
| 80 | call.isIncoming()) { |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 81 | CallInfo callInfo = new CallInfo(null, clientCallInfo.getState(), |
| 82 | clientCallInfo.getHandle()); |
| 83 | mIncomingCallsManager.handleSuccessfulIncomingCall(call, callInfo); |
| 84 | } else { |
| 85 | Log.w(this, "notifyIncomingCall, unknown incoming call: %s, id: %s", |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 86 | call, clientCallInfo.getId()); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 87 | } |
| 88 | break; |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 89 | case MSG_HANDLE_SUCCESSFUL_OUTGOING_CALL: { |
| 90 | String callId = (String) msg.obj; |
| 91 | if (mPendingOutgoingCalls.containsKey(callId)) { |
Ihab Awad | a3cb9e3 | 2014-06-03 18:45:05 -0700 | [diff] [blame] | 92 | mPendingOutgoingCalls.remove(callId).onResult(true, 0, null); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 93 | } else { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 94 | Log.w(this, "handleSuccessfulOutgoingCall, unknown call: %s", callId); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 95 | } |
| 96 | break; |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 97 | } |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 98 | case MSG_HANDLE_FAILED_OUTGOING_CALL: { |
| 99 | SomeArgs args = (SomeArgs) msg.obj; |
| 100 | try { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 101 | String callId = (String) args.arg1; |
Ihab Awad | a3cb9e3 | 2014-06-03 18:45:05 -0700 | [diff] [blame] | 102 | int statusCode = args.argi1; |
| 103 | String statusMsg = (String) args.arg2; |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 104 | // TODO(santoscordon): Do something with 'reason' or get rid of it. |
| 105 | |
| 106 | if (mPendingOutgoingCalls.containsKey(callId)) { |
Ihab Awad | a3cb9e3 | 2014-06-03 18:45:05 -0700 | [diff] [blame] | 107 | mPendingOutgoingCalls.remove(callId).onResult( |
| 108 | false, statusCode, statusMsg); |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 109 | mCallIdMapper.removeCall(callId); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 110 | } else { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 111 | Log.w(this, "handleFailedOutgoingCall, unknown call: %s", callId); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 112 | } |
| 113 | } finally { |
| 114 | args.recycle(); |
| 115 | } |
| 116 | break; |
| 117 | } |
| 118 | case MSG_SET_ACTIVE: |
| 119 | call = mCallIdMapper.getCall(msg.obj); |
| 120 | if (call != null) { |
| 121 | mCallsManager.markCallAsActive(call); |
| 122 | } else { |
| 123 | Log.w(this, "setActive, unknown call id: %s", msg.obj); |
| 124 | } |
| 125 | break; |
| 126 | case MSG_SET_RINGING: |
| 127 | call = mCallIdMapper.getCall(msg.obj); |
| 128 | if (call != null) { |
| 129 | mCallsManager.markCallAsRinging(call); |
| 130 | } else { |
| 131 | Log.w(this, "setRinging, unknown call id: %s", msg.obj); |
| 132 | } |
| 133 | break; |
| 134 | case MSG_SET_DIALING: |
| 135 | call = mCallIdMapper.getCall(msg.obj); |
| 136 | if (call != null) { |
| 137 | mCallsManager.markCallAsDialing(call); |
| 138 | } else { |
| 139 | Log.w(this, "setDialing, unknown call id: %s", msg.obj); |
| 140 | } |
| 141 | break; |
| 142 | case MSG_SET_DISCONNECTED: { |
| 143 | SomeArgs args = (SomeArgs) msg.obj; |
| 144 | try { |
| 145 | call = mCallIdMapper.getCall(args.arg1); |
| 146 | String disconnectMessage = (String) args.arg2; |
| 147 | int disconnectCause = args.argi1; |
| 148 | if (call != null) { |
| 149 | mCallsManager.markCallAsDisconnected(call, disconnectCause, |
| 150 | disconnectMessage); |
| 151 | } else { |
| 152 | Log.w(this, "setDisconnected, unknown call id: %s", args.arg1); |
| 153 | } |
| 154 | } finally { |
| 155 | args.recycle(); |
| 156 | } |
| 157 | break; |
| 158 | } |
| 159 | case MSG_SET_ON_HOLD: |
| 160 | call = mCallIdMapper.getCall(msg.obj); |
| 161 | if (call != null) { |
| 162 | mCallsManager.markCallAsOnHold(call); |
| 163 | } else { |
| 164 | Log.w(this, "setOnHold, unknown call id: %s", msg.obj); |
| 165 | } |
| 166 | break; |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 167 | case MSG_SET_REQUESTING_RINGBACK: { |
Ihab Awad | 50a5713 | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 168 | SomeArgs args = (SomeArgs) msg.obj; |
| 169 | try { |
| 170 | call = mCallIdMapper.getCall(args.arg1); |
| 171 | boolean ringback = (boolean) args.arg2; |
| 172 | if (call != null) { |
| 173 | call.setRequestingRingback(ringback); |
| 174 | } else { |
| 175 | Log.w(this, "setRingback, unknown call id: %s", args.arg1); |
| 176 | } |
| 177 | } finally { |
| 178 | args.recycle(); |
| 179 | } |
| 180 | break; |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 181 | } |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 182 | case MSG_ON_POST_DIAL_WAIT: { |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 183 | SomeArgs args = (SomeArgs) msg.obj; |
| 184 | try { |
| 185 | call = mCallIdMapper.getCall(args.arg1); |
| 186 | if (call != null) { |
| 187 | String remaining = (String) args.arg2; |
| 188 | call.onPostDialWait(remaining); |
| 189 | } else { |
| 190 | Log.w(this, "onPostDialWait, unknown call id: %s", args.arg1); |
| 191 | } |
| 192 | } finally { |
| 193 | args.recycle(); |
| 194 | } |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 195 | break; |
| 196 | } |
Sailesh Nepal | 6098d2c | 2014-06-06 10:56:53 -0700 | [diff] [blame] | 197 | case MSG_HANDOFF_CALL: |
| 198 | call = mCallIdMapper.getCall(msg.obj); |
| 199 | if (call != null) { |
| 200 | mCallsManager.startHandoffForCall(call); |
| 201 | } else { |
| 202 | Log.w(this, "handoffCall, unknown call id: %s", msg.obj); |
| 203 | } |
| 204 | break; |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 205 | case MSG_CAN_CONFERENCE: { |
| 206 | call = mCallIdMapper.getCall(msg.obj); |
| 207 | if (call != null) { |
| 208 | call.setIsConferenceCapable(msg.arg1 == 1); |
| 209 | } else { |
| 210 | Log.w(CallServiceWrapper.this, "canConference, unknown call id: %s", |
| 211 | msg.obj); |
| 212 | } |
| 213 | break; |
| 214 | } |
| 215 | case MSG_SET_IS_CONFERENCED: { |
| 216 | SomeArgs args = (SomeArgs) msg.obj; |
| 217 | try { |
| 218 | Call childCall = mCallIdMapper.getCall(args.arg1); |
| 219 | if (childCall != null) { |
| 220 | String conferenceCallId = (String) args.arg2; |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 221 | if (conferenceCallId == null) { |
| 222 | childCall.setParentCall(null); |
| 223 | } else { |
| 224 | Call conferenceCall = mCallIdMapper.getCall(conferenceCallId); |
| 225 | if (conferenceCall != null && |
| 226 | !mPendingConferenceCalls.contains(conferenceCall)) { |
| 227 | childCall.setParentCall(conferenceCall); |
| 228 | } else { |
| 229 | Log.w(this, "setIsConferenced, unknown conference id %s", |
| 230 | conferenceCallId); |
| 231 | } |
| 232 | } |
| 233 | } else { |
| 234 | Log.w(this, "setIsConferenced, unknown call id: %s", args.arg1); |
| 235 | } |
| 236 | } finally { |
| 237 | args.recycle(); |
| 238 | } |
| 239 | break; |
| 240 | } |
| 241 | case MSG_ADD_CONFERENCE_CALL: { |
| 242 | SomeArgs args = (SomeArgs) msg.obj; |
| 243 | try { |
| 244 | String callId = (String) args.arg1; |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 245 | Call conferenceCall = mCallIdMapper.getCall(callId); |
| 246 | if (mPendingConferenceCalls.remove(conferenceCall)) { |
| 247 | Log.v(this, "confirming conf call %s", conferenceCall); |
| 248 | conferenceCall.confirmConference(); |
| 249 | } else { |
| 250 | Log.w(this, "addConference, unknown call id: %s", callId); |
| 251 | } |
| 252 | } finally { |
| 253 | args.recycle(); |
| 254 | } |
| 255 | break; |
| 256 | } |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | }; |
| 260 | |
| 261 | /** {@inheritDoc} */ |
| 262 | @Override |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 263 | public void notifyIncomingCall(CallInfo callInfo) { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 264 | logIncoming("notifyIncomingCall %s", callInfo); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 265 | mCallIdMapper.checkValidCallId(callInfo.getId()); |
| 266 | mHandler.obtainMessage(MSG_NOTIFY_INCOMING_CALL, callInfo).sendToTarget(); |
| 267 | } |
| 268 | |
| 269 | /** {@inheritDoc} */ |
| 270 | @Override |
| 271 | public void handleSuccessfulOutgoingCall(String callId) { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 272 | logIncoming("handleSuccessfulOutgoingCall %s", callId); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 273 | mCallIdMapper.checkValidCallId(callId); |
| 274 | mHandler.obtainMessage(MSG_HANDLE_SUCCESSFUL_OUTGOING_CALL, callId).sendToTarget(); |
| 275 | } |
| 276 | |
| 277 | /** {@inheritDoc} */ |
| 278 | @Override |
Ihab Awad | a3cb9e3 | 2014-06-03 18:45:05 -0700 | [diff] [blame] | 279 | public void handleFailedOutgoingCall( |
| 280 | ConnectionRequest request, |
| 281 | int errorCode, |
| 282 | String errorMsg) { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 283 | logIncoming("handleFailedOutgoingCall %s %d %s", request, errorCode, errorMsg); |
Ihab Awad | a3cb9e3 | 2014-06-03 18:45:05 -0700 | [diff] [blame] | 284 | mCallIdMapper.checkValidCallId(request.getCallId()); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 285 | SomeArgs args = SomeArgs.obtain(); |
Ihab Awad | a3cb9e3 | 2014-06-03 18:45:05 -0700 | [diff] [blame] | 286 | args.arg1 = request.getCallId(); |
| 287 | args.argi1 = errorCode; |
| 288 | args.arg2 = errorMsg; |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 289 | mHandler.obtainMessage(MSG_HANDLE_FAILED_OUTGOING_CALL, args).sendToTarget(); |
| 290 | } |
| 291 | |
| 292 | /** {@inheritDoc} */ |
| 293 | @Override |
| 294 | public void setActive(String callId) { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 295 | logIncoming("setActive %s", callId); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 296 | mCallIdMapper.checkValidCallId(callId); |
| 297 | mHandler.obtainMessage(MSG_SET_ACTIVE, callId).sendToTarget(); |
| 298 | } |
| 299 | |
| 300 | /** {@inheritDoc} */ |
| 301 | @Override |
| 302 | public void setRinging(String callId) { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 303 | logIncoming("setRinging %s", callId); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 304 | mCallIdMapper.checkValidCallId(callId); |
| 305 | mHandler.obtainMessage(MSG_SET_RINGING, callId).sendToTarget(); |
| 306 | } |
| 307 | |
| 308 | /** {@inheritDoc} */ |
| 309 | @Override |
| 310 | public void setDialing(String callId) { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 311 | logIncoming("setDialing %s", callId); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 312 | mCallIdMapper.checkValidCallId(callId); |
| 313 | mHandler.obtainMessage(MSG_SET_DIALING, callId).sendToTarget(); |
| 314 | } |
| 315 | |
| 316 | /** {@inheritDoc} */ |
| 317 | @Override |
| 318 | public void setDisconnected( |
| 319 | String callId, int disconnectCause, String disconnectMessage) { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 320 | logIncoming("setDisconnected %s %d %s", callId, disconnectCause, disconnectMessage); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 321 | mCallIdMapper.checkValidCallId(callId); |
| 322 | SomeArgs args = SomeArgs.obtain(); |
| 323 | args.arg1 = callId; |
| 324 | args.arg2 = disconnectMessage; |
| 325 | args.argi1 = disconnectCause; |
| 326 | mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget(); |
| 327 | } |
| 328 | |
| 329 | /** {@inheritDoc} */ |
| 330 | @Override |
| 331 | public void setOnHold(String callId) { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 332 | logIncoming("setOnHold %s", callId); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 333 | mCallIdMapper.checkValidCallId(callId); |
| 334 | mHandler.obtainMessage(MSG_SET_ON_HOLD, callId).sendToTarget(); |
| 335 | } |
Ihab Awad | 50a5713 | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 336 | |
| 337 | /** {@inheritDoc} */ |
| 338 | @Override |
| 339 | public void setRequestingRingback(String callId, boolean ringback) { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 340 | logIncoming("setRequestingRingback %s %b", callId, ringback); |
Ihab Awad | 50a5713 | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 341 | mCallIdMapper.checkValidCallId(callId); |
| 342 | SomeArgs args = SomeArgs.obtain(); |
| 343 | args.arg1 = callId; |
| 344 | args.arg2 = ringback; |
| 345 | mHandler.obtainMessage(MSG_SET_REQUESTING_RINGBACK, args).sendToTarget(); |
| 346 | } |
Santos Cordon | 8f3282c | 2014-06-01 13:56:02 -0700 | [diff] [blame] | 347 | |
| 348 | /** ${inheritDoc} */ |
| 349 | @Override |
| 350 | public void removeCall(String callId) { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 351 | logIncoming("removeCall %s", callId); |
Santos Cordon | 8f3282c | 2014-06-01 13:56:02 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | /** ${inheritDoc} */ |
| 355 | @Override |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 356 | public void setCanConference(String callId, boolean canConference) { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 357 | logIncoming("setCanConference %s %b", callId, canConference); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 358 | mHandler.obtainMessage(MSG_CAN_CONFERENCE, canConference ? 1 : 0, 0, callId) |
| 359 | .sendToTarget(); |
Santos Cordon | 8f3282c | 2014-06-01 13:56:02 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | /** ${inheritDoc} */ |
| 363 | @Override |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 364 | public void setIsConferenced(String callId, String conferenceCallId) { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 365 | logIncoming("setIsConferenced %s %s", callId, conferenceCallId); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 366 | SomeArgs args = SomeArgs.obtain(); |
| 367 | args.arg1 = callId; |
| 368 | args.arg2 = conferenceCallId; |
| 369 | mHandler.obtainMessage(MSG_SET_IS_CONFERENCED, args).sendToTarget(); |
| 370 | } |
| 371 | |
| 372 | /** ${InheritDoc} */ |
| 373 | @Override |
| 374 | public void addConferenceCall(String callId, CallInfo callInfo) { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 375 | logIncoming("addConferenceCall %s %s", callId, callInfo); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 376 | mCallIdMapper.checkValidCallId(callId); |
| 377 | SomeArgs args = SomeArgs.obtain(); |
| 378 | args.arg1 = callId; |
| 379 | args.arg2 = callInfo; |
| 380 | mHandler.obtainMessage(MSG_ADD_CONFERENCE_CALL, args).sendToTarget(); |
Santos Cordon | 8f3282c | 2014-06-01 13:56:02 -0700 | [diff] [blame] | 381 | } |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 382 | |
| 383 | @Override |
| 384 | public void onPostDialWait(String callId, String remaining) throws RemoteException { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 385 | logIncoming("onPostDialWait %s %s", callId, remaining); |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 386 | mCallIdMapper.checkValidCallId(callId); |
| 387 | SomeArgs args = SomeArgs.obtain(); |
| 388 | args.arg1 = callId; |
| 389 | args.arg2 = remaining; |
| 390 | mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget(); |
| 391 | } |
Sailesh Nepal | 6098d2c | 2014-06-06 10:56:53 -0700 | [diff] [blame] | 392 | |
| 393 | /** {@inheritDoc} */ |
| 394 | @Override |
| 395 | public void handoffCall(String callId) { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 396 | logIncoming("handoffCall %s", callId); |
Sailesh Nepal | 6098d2c | 2014-06-06 10:56:53 -0700 | [diff] [blame] | 397 | mCallIdMapper.checkValidCallId(callId); |
| 398 | mHandler.obtainMessage(MSG_HANDOFF_CALL, callId).sendToTarget(); |
| 399 | } |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | private final Adapter mAdapter = new Adapter(); |
| 403 | private final CallsManager mCallsManager = CallsManager.getInstance(); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 404 | private final Set<Call> mPendingIncomingCalls = new HashSet<>(); |
| 405 | private final Set<Call> mPendingConferenceCalls = new HashSet<>(); |
Ben Gilad | c5b2269 | 2014-02-18 20:03:22 -0800 | [diff] [blame] | 406 | private final CallServiceDescriptor mDescriptor; |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 407 | private final CallIdMapper mCallIdMapper = new CallIdMapper("CallService"); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 408 | private final IncomingCallsManager mIncomingCallsManager; |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 409 | private final Map<String, AsyncResultCallback<Boolean>> mPendingOutgoingCalls = new HashMap<>(); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 410 | private final Handler mHandler = new Handler(); |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 411 | |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 412 | private Binder mBinder = new Binder(); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 413 | private ICallService mServiceInterface; |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 414 | |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 415 | /** |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 416 | * Creates a call-service for the specified descriptor. |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 417 | * |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 418 | * @param descriptor The call-service descriptor from |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 419 | * {@link ICallServiceProvider#lookupCallServices}. |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 420 | * @param incomingCallsManager Manages the incoming call initialization flow. |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 421 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 422 | CallServiceWrapper( |
| 423 | CallServiceDescriptor descriptor, |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 424 | IncomingCallsManager incomingCallsManager) { |
Sailesh Nepal | a439e1b | 2014-03-11 18:19:58 -0700 | [diff] [blame] | 425 | super(TelecommConstants.ACTION_CALL_SERVICE, descriptor.getServiceComponent()); |
Ben Gilad | c5b2269 | 2014-02-18 20:03:22 -0800 | [diff] [blame] | 426 | mDescriptor = descriptor; |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 427 | mIncomingCallsManager = incomingCallsManager; |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 430 | CallServiceDescriptor getDescriptor() { |
Ben Gilad | c5b2269 | 2014-02-18 20:03:22 -0800 | [diff] [blame] | 431 | return mDescriptor; |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 434 | /** See {@link ICallService#setCallServiceAdapter}. */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 435 | private void setCallServiceAdapter(ICallServiceAdapter callServiceAdapter) { |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 436 | if (isServiceValid("setCallServiceAdapter")) { |
| 437 | try { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 438 | logOutgoing("setCallServiceAdapter %s", callServiceAdapter); |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 439 | mServiceInterface.setCallServiceAdapter(callServiceAdapter); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 440 | } catch (RemoteException e) { |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 441 | } |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 445 | /** |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 446 | * Attempts to place the specified call, see {@link ICallService#call}. Returns the result |
| 447 | * asynchronously through the specified callback. |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 448 | */ |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 449 | void call(final Call call, final AsyncResultCallback<Boolean> resultCallback) { |
| 450 | Log.d(this, "call(%s) via %s.", call, getComponentName()); |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 451 | BindCallback callback = new BindCallback() { |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 452 | @Override |
| 453 | public void onSuccess() { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 454 | String callId = mCallIdMapper.getCallId(call); |
| 455 | mPendingOutgoingCalls.put(callId, resultCallback); |
| 456 | |
| 457 | try { |
| 458 | CallInfo callInfo = call.toCallInfo(callId); |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 459 | logOutgoing("call %s", callInfo); |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 460 | mServiceInterface.call(callInfo); |
| 461 | } catch (RemoteException e) { |
Ihab Awad | a3cb9e3 | 2014-06-03 18:45:05 -0700 | [diff] [blame] | 462 | mPendingOutgoingCalls.remove(callId).onResult( |
| 463 | false, DisconnectCause.ERROR_UNSPECIFIED, e.toString()); |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 464 | } |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 465 | } |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 466 | |
| 467 | @Override |
| 468 | public void onFailure() { |
Ihab Awad | a3cb9e3 | 2014-06-03 18:45:05 -0700 | [diff] [blame] | 469 | resultCallback.onResult(false, DisconnectCause.ERROR_UNSPECIFIED, null); |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 470 | } |
| 471 | }; |
| 472 | |
| 473 | mBinder.bind(callback); |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 474 | } |
| 475 | |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 476 | /** @see CallService#abort(String) */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 477 | void abort(Call call) { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 478 | // Clear out any pending outgoing call data |
| 479 | String callId = mCallIdMapper.getCallId(call); |
| 480 | |
| 481 | // If still bound, tell the call service to abort. |
Ben Gilad | 28e8ad6 | 2014-03-06 17:01:54 -0800 | [diff] [blame] | 482 | if (isServiceValid("abort")) { |
| 483 | try { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 484 | logOutgoing("abort %s", callId); |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 485 | mServiceInterface.abort(callId); |
Ben Gilad | 28e8ad6 | 2014-03-06 17:01:54 -0800 | [diff] [blame] | 486 | } catch (RemoteException e) { |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 487 | } |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 488 | } |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 489 | |
| 490 | removeCall(call); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 491 | } |
| 492 | |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 493 | /** @see CallService#hold(String) */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 494 | void hold(Call call) { |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 495 | if (isServiceValid("hold")) { |
| 496 | try { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 497 | logOutgoing("hold %s", mCallIdMapper.getCallId(call)); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 498 | mServiceInterface.hold(mCallIdMapper.getCallId(call)); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 499 | } catch (RemoteException e) { |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | } |
| 503 | |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 504 | /** @see CallService#unhold(String) */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 505 | void unhold(Call call) { |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 506 | if (isServiceValid("unhold")) { |
| 507 | try { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 508 | logOutgoing("unhold %s", mCallIdMapper.getCallId(call)); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 509 | mServiceInterface.unhold(mCallIdMapper.getCallId(call)); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 510 | } catch (RemoteException e) { |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | } |
| 514 | |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 515 | /** @see CallService#onAudioStateChanged(String,CallAudioState) */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 516 | void onAudioStateChanged(Call activeCall, CallAudioState audioState) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 517 | if (isServiceValid("onAudioStateChanged")) { |
| 518 | try { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 519 | logOutgoing("onAudioStateChanged %s %s", |
| 520 | mCallIdMapper.getCallId(activeCall), audioState); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 521 | mServiceInterface.onAudioStateChanged(mCallIdMapper.getCallId(activeCall), |
| 522 | audioState); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 523 | } catch (RemoteException e) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | } |
| 527 | |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 528 | /** |
| 529 | * Starts retrieval of details for an incoming call. Details are returned through the |
| 530 | * call-service adapter using the specified call ID. Upon failure, the specified error callback |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 531 | * is invoked. Can be invoked even when the call service is unbound. See |
| 532 | * {@link ICallService#setIncomingCallId}. |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 533 | * |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 534 | * @param call The call used for the incoming call. |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 535 | * @param extras The {@link CallService}-provided extras which need to be sent back. |
| 536 | * @param errorCallback The callback to invoke upon failure. |
| 537 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 538 | void setIncomingCallId(final Call call, final Bundle extras, final Runnable errorCallback) { |
| 539 | Log.d(this, "setIncomingCall(%s) via %s.", call, getComponentName()); |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 540 | BindCallback callback = new BindCallback() { |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 541 | @Override |
| 542 | public void onSuccess() { |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 543 | if (isServiceValid("setIncomingCallId")) { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 544 | mPendingIncomingCalls.add(call); |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 545 | try { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 546 | logOutgoing("setIncomingCallId %s %s", |
| 547 | mCallIdMapper.getCallId(call), extras); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 548 | mServiceInterface.setIncomingCallId(mCallIdMapper.getCallId(call), |
| 549 | extras); |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 550 | } catch (RemoteException e) { |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 551 | } |
| 552 | } |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 553 | } |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 554 | |
| 555 | @Override |
| 556 | public void onFailure() { |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 557 | errorCallback.run(); |
| 558 | } |
| 559 | }; |
| 560 | |
| 561 | mBinder.bind(callback); |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 562 | } |
| 563 | |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 564 | /** @see CallService#disconnect(String) */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 565 | void disconnect(Call call) { |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 566 | if (isServiceValid("disconnect")) { |
| 567 | try { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 568 | logOutgoing("disconnect %s", mCallIdMapper.getCallId(call)); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 569 | mServiceInterface.disconnect(mCallIdMapper.getCallId(call)); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 570 | } catch (RemoteException e) { |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 571 | } |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 572 | } |
| 573 | } |
Santos Cordon | 5c12c6e | 2014-02-13 14:35:31 -0800 | [diff] [blame] | 574 | |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 575 | /** @see CallService#answer(String) */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 576 | void answer(Call call) { |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 577 | if (isServiceValid("answer")) { |
| 578 | try { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 579 | logOutgoing("answer %s", mCallIdMapper.getCallId(call)); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 580 | mServiceInterface.answer(mCallIdMapper.getCallId(call)); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 581 | } catch (RemoteException e) { |
Santos Cordon | 7917d38 | 2014-02-14 02:31:18 -0800 | [diff] [blame] | 582 | } |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 586 | /** @see CallService#reject(String) */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 587 | void reject(Call call) { |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 588 | if (isServiceValid("reject")) { |
| 589 | try { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 590 | logOutgoing("reject %s", mCallIdMapper.getCallId(call)); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 591 | mServiceInterface.reject(mCallIdMapper.getCallId(call)); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 592 | } catch (RemoteException e) { |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | /** @see CallService#playDtmfTone(String,char) */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 598 | void playDtmfTone(Call call, char digit) { |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 599 | if (isServiceValid("playDtmfTone")) { |
| 600 | try { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 601 | logOutgoing("playDtmfTone %s %c", mCallIdMapper.getCallId(call), digit); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 602 | mServiceInterface.playDtmfTone(mCallIdMapper.getCallId(call), digit); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 603 | } catch (RemoteException e) { |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | /** @see CallService#stopDtmfTone(String) */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 609 | void stopDtmfTone(Call call) { |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 610 | if (isServiceValid("stopDtmfTone")) { |
| 611 | try { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 612 | logOutgoing("stopDtmfTone %s", mCallIdMapper.getCallId(call)); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 613 | mServiceInterface.stopDtmfTone(mCallIdMapper.getCallId(call)); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 614 | } catch (RemoteException e) { |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 615 | } |
Santos Cordon | 7917d38 | 2014-02-14 02:31:18 -0800 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 619 | void addCall(Call call) { |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 620 | if (mCallIdMapper.getCallId(call) == null) { |
| 621 | mCallIdMapper.addCall(call); |
| 622 | } |
Santos Cordon | 7917d38 | 2014-02-14 02:31:18 -0800 | [diff] [blame] | 623 | } |
| 624 | |
Sailesh Nepal | 0e5410a | 2014-04-04 01:20:58 -0700 | [diff] [blame] | 625 | /** |
| 626 | * Associates newCall with this call service by replacing callToReplace. |
| 627 | */ |
| 628 | void replaceCall(Call newCall, Call callToReplace) { |
| 629 | Preconditions.checkState(callToReplace.getCallService() == this); |
| 630 | mCallIdMapper.replaceCall(newCall, callToReplace); |
| 631 | } |
| 632 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 633 | void removeCall(Call call) { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 634 | mPendingIncomingCalls.remove(call); |
| 635 | |
| 636 | AsyncResultCallback<Boolean> outgoingResultCallback = |
| 637 | mPendingOutgoingCalls.remove(mCallIdMapper.getCallId(call)); |
| 638 | if (outgoingResultCallback != null) { |
Ihab Awad | a3cb9e3 | 2014-06-03 18:45:05 -0700 | [diff] [blame] | 639 | outgoingResultCallback.onResult(false, DisconnectCause.ERROR_UNSPECIFIED, null); |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 640 | } |
| 641 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 642 | mCallIdMapper.removeCall(call); |
Yorke Lee | adee12d | 2014-03-13 12:08:30 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 645 | void onPostDialContinue(Call call, boolean proceed) { |
| 646 | if (isServiceValid("onPostDialContinue")) { |
| 647 | try { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 648 | logOutgoing("onPostDialContinue %s %b", mCallIdMapper.getCallId(call), proceed); |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 649 | mServiceInterface.onPostDialContinue(mCallIdMapper.getCallId(call), proceed); |
| 650 | } catch (RemoteException ignored) { |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 655 | void conference(final Call conferenceCall, Call call) { |
| 656 | if (isServiceValid("conference")) { |
| 657 | try { |
| 658 | conferenceCall.setCallService(this); |
| 659 | mPendingConferenceCalls.add(conferenceCall); |
| 660 | mHandler.postDelayed(new Runnable() { |
| 661 | @Override public void run() { |
| 662 | if (mPendingConferenceCalls.remove(conferenceCall)) { |
| 663 | conferenceCall.expireConference(); |
| 664 | Log.i(this, "Conference call expired: %s", conferenceCall); |
| 665 | } |
| 666 | } |
| 667 | }, Timeouts.getConferenceCallExpireMillis()); |
| 668 | |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 669 | logOutgoing("conference %s %s", |
| 670 | mCallIdMapper.getCallId(conferenceCall), |
| 671 | mCallIdMapper.getCallId(call)); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 672 | mServiceInterface.conference( |
| 673 | mCallIdMapper.getCallId(conferenceCall), |
| 674 | mCallIdMapper.getCallId(call)); |
| 675 | } catch (RemoteException ignored) { |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | void splitFromConference(Call call) { |
| 681 | if (isServiceValid("splitFromConference")) { |
| 682 | try { |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 683 | logOutgoing("splitFromConference %s", mCallIdMapper.getCallId(call)); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 684 | mServiceInterface.splitFromConference(mCallIdMapper.getCallId(call)); |
| 685 | } catch (RemoteException ignored) { |
| 686 | } |
| 687 | } |
| 688 | } |
| 689 | |
Santos Cordon | 5c12c6e | 2014-02-13 14:35:31 -0800 | [diff] [blame] | 690 | /** {@inheritDoc} */ |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 691 | @Override |
| 692 | protected void setServiceInterface(IBinder binder) { |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 693 | if (binder == null) { |
| 694 | // We have lost our service connection. Notify the world that this call service is done. |
| 695 | // We must notify the adapter before CallsManager. The adapter will force any pending |
| 696 | // outgoing calls to try the next call service. This needs to happen before CallsManager |
| 697 | // tries to clean up any calls still associated with this call service. |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 698 | handleCallServiceDeath(); |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 699 | CallsManager.getInstance().handleCallServiceDeath(this); |
| 700 | mServiceInterface = null; |
| 701 | } else { |
| 702 | mServiceInterface = ICallService.Stub.asInterface(binder); |
| 703 | setCallServiceAdapter(mAdapter); |
| 704 | } |
Santos Cordon | 5c12c6e | 2014-02-13 14:35:31 -0800 | [diff] [blame] | 705 | } |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 706 | |
| 707 | /** |
| 708 | * Called when the associated call service dies. |
| 709 | */ |
| 710 | private void handleCallServiceDeath() { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 711 | if (!mPendingOutgoingCalls.isEmpty()) { |
| 712 | for (AsyncResultCallback<Boolean> callback : mPendingOutgoingCalls.values()) { |
Ihab Awad | a3cb9e3 | 2014-06-03 18:45:05 -0700 | [diff] [blame] | 713 | callback.onResult(false, DisconnectCause.ERROR_UNSPECIFIED, null); |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 714 | } |
| 715 | mPendingOutgoingCalls.clear(); |
| 716 | } |
| 717 | |
| 718 | if (!mPendingIncomingCalls.isEmpty()) { |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 719 | // Iterate through a copy because the code inside the loop will modify the original |
| 720 | // list. |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 721 | for (Call call : ImmutableList.copyOf(mPendingIncomingCalls)) { |
| 722 | Preconditions.checkState(call.isIncoming()); |
| 723 | mIncomingCallsManager.handleFailedIncomingCall(call); |
Santos Cordon | 3d3b405 | 2014-05-05 12:05:36 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 726 | if (!mPendingIncomingCalls.isEmpty()) { |
| 727 | Log.wtf(this, "Pending calls did not get cleared."); |
| 728 | mPendingIncomingCalls.clear(); |
| 729 | } |
| 730 | } |
Santos Cordon | 8f3282c | 2014-06-01 13:56:02 -0700 | [diff] [blame] | 731 | |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 732 | mCallIdMapper.clear(); |
| 733 | } |
Ihab Awad | 55a3428 | 2014-06-18 10:31:09 -0700 | [diff] [blame^] | 734 | |
| 735 | private void logIncoming(String msg, Object... params) { |
| 736 | Log.d(this, "CallService -> Telecomm: " + msg, params); |
| 737 | } |
| 738 | |
| 739 | private void logOutgoing(String msg, Object... params) { |
| 740 | Log.d(this, "Telecomm -> CallService: " + msg, params); |
| 741 | } |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 742 | } |