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