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