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