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