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