blob: d5e4f1b2cd13de04c47dd5bf7cb1bd3662fe4fe2 [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 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
17package android.telecomm;
18
Santos Cordon5c6fa952014-07-20 17:47:12 -070019import android.annotation.SdkConstant;
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -070020import android.app.PendingIntent;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070021import android.app.Service;
Santos Cordon52d8a152014-06-17 19:08:45 -070022import android.content.ComponentName;
Santos Cordon5c6fa952014-07-20 17:47:12 -070023import android.content.Intent;
Ihab Awad542e0ea2014-05-16 10:22:16 -070024import android.net.Uri;
Santos Cordon52d8a152014-06-17 19:08:45 -070025import android.os.Handler;
26import android.os.IBinder;
27import android.os.Looper;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070028import android.os.Message;
Evan Charltonbf11f982014-07-20 22:06:28 -070029import android.telephony.DisconnectCause;
Andrew Lee14185762014-07-25 09:41:56 -070030
Sailesh Nepal2a46b902014-07-04 17:21:07 -070031import com.android.internal.os.SomeArgs;
32import com.android.internal.telecomm.IConnectionService;
33import com.android.internal.telecomm.IConnectionServiceAdapter;
Santos Cordon52d8a152014-06-17 19:08:45 -070034import com.android.internal.telecomm.RemoteServiceCallback;
35
Ihab Awad5d0410f2014-07-30 10:07:40 -070036import java.util.ArrayList;
Santos Cordonb6939982014-06-04 20:20:58 -070037import java.util.Collection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070038import java.util.Collections;
Ihab Awad542e0ea2014-05-16 10:22:16 -070039import java.util.HashMap;
Santos Cordon52d8a152014-06-17 19:08:45 -070040import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070041import java.util.Map;
42
43/**
Sailesh Nepal2a46b902014-07-04 17:21:07 -070044 * A {@link android.app.Service} that provides telephone connections to processes running on an
45 * Android device.
Ihab Awad542e0ea2014-05-16 10:22:16 -070046 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070047public abstract class ConnectionService extends Service {
Ihab Awadb19a0bc2014-08-07 19:46:01 -070048
Santos Cordon5c6fa952014-07-20 17:47:12 -070049 /**
50 * The {@link Intent} that must be declared as handled by the service.
51 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070052 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Santos Cordon5c6fa952014-07-20 17:47:12 -070053 public static final String SERVICE_INTERFACE = "android.telecomm.ConnectionService";
54
Ihab Awad542e0ea2014-05-16 10:22:16 -070055 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -070056 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -070057
Ihab Awad8aecfed2014-08-08 17:06:11 -070058 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -070059 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070060 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -070061 private static final int MSG_ANSWER = 4;
62 private static final int MSG_REJECT = 5;
63 private static final int MSG_DISCONNECT = 6;
64 private static final int MSG_HOLD = 7;
65 private static final int MSG_UNHOLD = 8;
66 private static final int MSG_ON_AUDIO_STATE_CHANGED = 9;
67 private static final int MSG_PLAY_DTMF_TONE = 10;
68 private static final int MSG_STOP_DTMF_TONE = 11;
69 private static final int MSG_CONFERENCE = 12;
70 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070071 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
72 private static final int MSG_ON_PHONE_ACCOUNT_CLICKED = 15;
73 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070074
Ihab Awad542e0ea2014-05-16 10:22:16 -070075 private final Map<String, Connection> mConnectionById = new HashMap<>();
76 private final Map<Connection, String> mIdByConnection = new HashMap<>();
Santos Cordon52d8a152014-06-17 19:08:45 -070077 private final RemoteConnectionManager mRemoteConnectionManager = new RemoteConnectionManager();
Santos Cordon52d8a152014-06-17 19:08:45 -070078
Ihab Awad9c3f1882014-06-30 21:17:13 -070079 private boolean mAreAccountsInitialized = false;
Ihab Awad5d0410f2014-07-30 10:07:40 -070080 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -070081 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -070082
Sailesh Nepal2a46b902014-07-04 17:21:07 -070083 private final IBinder mBinder = new IConnectionService.Stub() {
84 @Override
85 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter) {
Ihab Awad8aecfed2014-08-08 17:06:11 -070086 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, adapter).sendToTarget();
87 }
88
89 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter) {
90 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, adapter).sendToTarget();
Sailesh Nepal2a46b902014-07-04 17:21:07 -070091 }
92
93 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -070094 public void createConnection(
95 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -070096 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -070097 ConnectionRequest request,
98 boolean isIncoming) {
99 SomeArgs args = SomeArgs.obtain();
100 args.arg1 = connectionManagerPhoneAccount;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700101 args.arg2 = id;
102 args.arg3 = request;
Ihab Awadf8b69882014-07-25 15:14:01 -0700103 args.argi1 = isIncoming ? 1 : 0;
104 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700105 }
106
107 @Override
108 public void abort(String callId) {
109 mHandler.obtainMessage(MSG_ABORT, callId).sendToTarget();
110 }
111
112 @Override
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700113 public void answer(String callId, int videoState) {
114 SomeArgs args = SomeArgs.obtain();
115 args.arg1 = callId;
Evan Charltonbf11f982014-07-20 22:06:28 -0700116 args.argi1 = videoState;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700117 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700118 }
119
120 @Override
121 public void reject(String callId) {
122 mHandler.obtainMessage(MSG_REJECT, callId).sendToTarget();
123 }
124
125 @Override
126 public void disconnect(String callId) {
127 mHandler.obtainMessage(MSG_DISCONNECT, callId).sendToTarget();
128 }
129
130 @Override
131 public void hold(String callId) {
132 mHandler.obtainMessage(MSG_HOLD, callId).sendToTarget();
133 }
134
135 @Override
136 public void unhold(String callId) {
137 mHandler.obtainMessage(MSG_UNHOLD, callId).sendToTarget();
138 }
139
140 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700141 public void onAudioStateChanged(String callId, AudioState audioState) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700142 SomeArgs args = SomeArgs.obtain();
143 args.arg1 = callId;
144 args.arg2 = audioState;
145 mHandler.obtainMessage(MSG_ON_AUDIO_STATE_CHANGED, args).sendToTarget();
146 }
147
148 @Override
149 public void playDtmfTone(String callId, char digit) {
150 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, digit, 0, callId).sendToTarget();
151 }
152
153 @Override
154 public void stopDtmfTone(String callId) {
155 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, callId).sendToTarget();
156 }
157
158 @Override
159 public void conference(String conferenceCallId, String callId) {
160 SomeArgs args = SomeArgs.obtain();
161 args.arg1 = conferenceCallId;
162 args.arg2 = callId;
163 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
164 }
165
166 @Override
167 public void splitFromConference(String callId) {
168 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, callId).sendToTarget();
169 }
170
171 @Override
172 public void onPostDialContinue(String callId, boolean proceed) {
173 SomeArgs args = SomeArgs.obtain();
174 args.arg1 = callId;
175 args.argi1 = proceed ? 1 : 0;
176 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
177 }
178
179 @Override
180 public void onPhoneAccountClicked(String callId) {
181 mHandler.obtainMessage(MSG_ON_PHONE_ACCOUNT_CLICKED, callId).sendToTarget();
182 }
183 };
184
185 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
186 @Override
187 public void handleMessage(Message msg) {
188 switch (msg.what) {
Ihab Awad8aecfed2014-08-08 17:06:11 -0700189 case MSG_ADD_CONNECTION_SERVICE_ADAPTER:
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700190 mAdapter.addAdapter((IConnectionServiceAdapter) msg.obj);
191 onAdapterAttached();
192 break;
Ihab Awad8aecfed2014-08-08 17:06:11 -0700193 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER:
194 mAdapter.removeAdapter((IConnectionServiceAdapter) msg.obj);
195 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700196 case MSG_CREATE_CONNECTION: {
197 SomeArgs args = (SomeArgs) msg.obj;
198 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700199 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700200 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700201 final String id = (String) args.arg2;
202 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700203 final boolean isIncoming = args.argi1 == 1;
204 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700205 Log.d(this, "Enqueueing pre-init request %s", id);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700206 mPreInitializationConnectionRequests.add(new Runnable() {
207 @Override
208 public void run() {
209 createConnection(
210 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700211 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700212 request,
213 isIncoming);
214 }
215 });
216 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700217 createConnection(
218 connectionManagerPhoneAccount,
219 id,
220 request,
221 isIncoming);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700222 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700223 } finally {
224 args.recycle();
225 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700226 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700227 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700228 case MSG_ABORT:
229 abort((String) msg.obj);
230 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700231 case MSG_ANSWER: {
232 SomeArgs args = (SomeArgs) msg.obj;
233 try {
234 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700235 int videoState = args.argi1;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700236 answer(callId, videoState);
237 } finally {
238 args.recycle();
239 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700240 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700241 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700242 case MSG_REJECT:
243 reject((String) msg.obj);
244 break;
245 case MSG_DISCONNECT:
246 disconnect((String) msg.obj);
247 break;
248 case MSG_HOLD:
249 hold((String) msg.obj);
250 break;
251 case MSG_UNHOLD:
252 unhold((String) msg.obj);
253 break;
254 case MSG_ON_AUDIO_STATE_CHANGED: {
255 SomeArgs args = (SomeArgs) msg.obj;
256 try {
257 String callId = (String) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700258 AudioState audioState = (AudioState) args.arg2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700259 onAudioStateChanged(callId, audioState);
260 } finally {
261 args.recycle();
262 }
263 break;
264 }
265 case MSG_PLAY_DTMF_TONE:
266 playDtmfTone((String) msg.obj, (char) msg.arg1);
267 break;
268 case MSG_STOP_DTMF_TONE:
269 stopDtmfTone((String) msg.obj);
270 break;
271 case MSG_CONFERENCE: {
272 SomeArgs args = (SomeArgs) msg.obj;
273 try {
274 String conferenceCallId = (String) args.arg1;
275 String callId = (String) args.arg2;
276 conference(conferenceCallId, callId);
277 } finally {
278 args.recycle();
279 }
280 break;
281 }
282 case MSG_SPLIT_FROM_CONFERENCE:
283 splitFromConference((String) msg.obj);
284 break;
285 case MSG_ON_POST_DIAL_CONTINUE: {
286 SomeArgs args = (SomeArgs) msg.obj;
287 try {
288 String callId = (String) args.arg1;
289 boolean proceed = (args.argi1 == 1);
290 onPostDialContinue(callId, proceed);
291 } finally {
292 args.recycle();
293 }
294 break;
295 }
296 case MSG_ON_PHONE_ACCOUNT_CLICKED:
Evan Charlton8c8a0622014-07-20 12:31:00 -0700297 onPhoneAccountHandleClicked((String) msg.obj);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700298 break;
299 default:
300 break;
301 }
302 }
303 };
304
Ihab Awad542e0ea2014-05-16 10:22:16 -0700305 private final Connection.Listener mConnectionListener = new Connection.Listener() {
306 @Override
307 public void onStateChanged(Connection c, int state) {
308 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -0700309 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -0700310 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700311 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700312 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700313 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700314 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700315 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700316 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700317 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700318 // Handled in onDisconnected()
319 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700320 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700321 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700322 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700323 case Connection.STATE_NEW:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700324 // Nothing to tell Telecomm
325 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700326 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700327 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700328 break;
329 }
330 }
331
332 @Override
333 public void onDisconnected(Connection c, int cause, String message) {
334 String id = mIdByConnection.get(c);
Ihab Awad60ac30b2014-05-20 22:32:12 -0700335 Log.d(this, "Adapter set disconnected %d %s", cause, message);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700336 mAdapter.setDisconnected(id, cause, message);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700337 }
338
339 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -0700340 public void onVideoStateChanged(Connection c, int videoState) {
341 String id = mIdByConnection.get(c);
342 Log.d(this, "Adapter set video state %d", videoState);
343 mAdapter.setVideoState(id, videoState);
344 }
345
346 @Override
Sailesh Nepal61203862014-07-11 14:50:13 -0700347 public void onHandleChanged(Connection c, Uri handle, int presentation) {
348 String id = mIdByConnection.get(c);
349 mAdapter.setHandle(id, handle, presentation);
350 }
351
352 @Override
353 public void onCallerDisplayNameChanged(
354 Connection c, String callerDisplayName, int presentation) {
355 String id = mIdByConnection.get(c);
356 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700357 }
358
359 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700360 public void onDestroyed(Connection c) {
361 removeConnection(c);
362 }
Ihab Awadf8358972014-05-28 16:46:42 -0700363
364 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700365 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -0700366 String id = mIdByConnection.get(c);
367 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700368 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700369 }
370
371 @Override
Ihab Awadf8358972014-05-28 16:46:42 -0700372 public void onRequestingRingback(Connection c, boolean ringback) {
373 String id = mIdByConnection.get(c);
374 Log.d(this, "Adapter onRingback %b", ringback);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700375 mAdapter.setRequestingRingback(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -0700376 }
Santos Cordonb6939982014-06-04 20:20:58 -0700377
378 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700379 public void onCallCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -0700380 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700381 Log.d(this, "capabilities: parcelableconnection: %s",
382 PhoneCapabilities.toString(capabilities));
383 mAdapter.setCallCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -0700384 }
385
Santos Cordonb6939982014-06-04 20:20:58 -0700386 @Override
387 public void onParentConnectionChanged(Connection c, Connection parent) {
388 String id = mIdByConnection.get(c);
389 String parentId = parent == null ? null : mIdByConnection.get(parent);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700390 mAdapter.setIsConferenced(id, parentId);
Santos Cordonb6939982014-06-04 20:20:58 -0700391 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700392
393 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700394 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700395 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700396 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700397 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700398
399 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700400 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700401 String id = mIdByConnection.get(c);
402 mAdapter.setAudioModeIsVoip(id, isVoip);
403 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700404
405 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700406 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700407 String id = mIdByConnection.get(c);
408 mAdapter.setStatusHints(id, statusHints);
409 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700410
411 @Override
412 public void onStartActivityFromInCall(Connection c, PendingIntent intent) {
413 String id = mIdByConnection.get(c);
414 mAdapter.startActivityFromInCall(id, intent);
415 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700416
417 @Override
418 public void onConferenceableConnectionsChanged(
419 Connection connection, List<Connection> conferenceableConnections) {
420 String id = mIdByConnection.get(connection);
421 List<String> conferenceableCallIds = new ArrayList<>(conferenceableConnections.size());
422 for (Connection c : conferenceableConnections) {
423 if (mIdByConnection.containsKey(c)) {
424 conferenceableCallIds.add(mIdByConnection.get(c));
425 }
426 }
427 Collections.sort(conferenceableCallIds);
428 mAdapter.setConferenceableConnections(id, conferenceableCallIds);
429 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700430 };
431
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700432 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -0700433 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700434 public final IBinder onBind(Intent intent) {
435 return mBinder;
436 }
437
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700438 /**
439 * This can be used by telecomm to either create a new outgoing call or attach to an existing
440 * incoming call. In either case, telecomm will cycle through a set of services and call
441 * createConnection util a connection service cancels the process or completes it successfully.
442 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700443 private void createConnection(
444 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700445 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -0700446 final ConnectionRequest request,
447 boolean isIncoming) {
Evan Charltonbf11f982014-07-20 22:06:28 -0700448 Log.d(this, "call %s", request);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700449
Evan Charltonbf11f982014-07-20 22:06:28 -0700450 final Connection createdConnection;
451 if (isIncoming) {
Ihab Awadf8b69882014-07-25 15:14:01 -0700452 createdConnection = onCreateIncomingConnection(callManagerAccount, request);
Evan Charltonbf11f982014-07-20 22:06:28 -0700453 } else {
Ihab Awadf8b69882014-07-25 15:14:01 -0700454 createdConnection = onCreateOutgoingConnection(callManagerAccount, request);
Evan Charltonbf11f982014-07-20 22:06:28 -0700455 }
Sailesh Nepal506e3862014-06-25 13:35:14 -0700456
Evan Charltonbf11f982014-07-20 22:06:28 -0700457 if (createdConnection != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700458 Log.d(this, "adapter handleCreateConnectionSuccessful %s", callId);
459 if (createdConnection.getState() == Connection.STATE_INITIALIZING) {
Evan Charltonbf11f982014-07-20 22:06:28 -0700460 // Wait for the connection to become initialized.
461 createdConnection.addConnectionListener(new Connection.Listener() {
462 @Override
463 public void onStateChanged(Connection c, int state) {
464 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700465 case Connection.STATE_FAILED:
Evan Charltonbf11f982014-07-20 22:06:28 -0700466 Log.d(this, "Connection (%s) failed (%d: %s)", request,
467 c.getFailureCode(), c.getFailureMessage());
Ihab Awad8aecfed2014-08-08 17:06:11 -0700468 Log.d(this, "adapter handleCreateConnectionFailed %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700469 callId);
470 mAdapter.handleCreateConnectionFailed(
471 callId,
472 request,
473 c.getFailureCode(),
Evan Charltonbf11f982014-07-20 22:06:28 -0700474 c.getFailureMessage());
475 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700476 case Connection.STATE_CANCELED:
Ihab Awad8aecfed2014-08-08 17:06:11 -0700477 Log.d(this, "adapter handleCreateConnectionCanceled %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700478 callId);
479 mAdapter.handleCreateConnectionCancelled(callId, request);
Evan Charltonbf11f982014-07-20 22:06:28 -0700480 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700481 case Connection.STATE_INITIALIZING:
482 Log.d(this, "State changed to STATE_INITIALIZING; ignoring");
Evan Charltonbf11f982014-07-20 22:06:28 -0700483 return; // Don't want to stop listening on this state transition.
484 default:
485 Log.d(this, "Connection created in state %s",
486 Connection.stateToString(state));
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700487 connectionCreated(callId, request, createdConnection);
Evan Charltonbf11f982014-07-20 22:06:28 -0700488 break;
489 }
490 c.removeConnectionListener(this);
491 }
492 });
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700493 } else if (createdConnection.getState() == Connection.STATE_CANCELED) {
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700494 // Tell telecomm not to attempt any more services.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700495 mAdapter.handleCreateConnectionCancelled(callId, request);
496 } else if (createdConnection.getState() == Connection.STATE_FAILED) {
497 mAdapter.handleCreateConnectionFailed(
498 callId,
499 request,
500 createdConnection.getFailureCode(),
Sailesh Nepal4e7ec712014-07-28 10:25:27 -0700501 createdConnection.getFailureMessage());
Evan Charltonbf11f982014-07-20 22:06:28 -0700502 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700503 connectionCreated(callId, request, createdConnection);
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700504 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700505 } else {
Evan Charltonbf11f982014-07-20 22:06:28 -0700506 // Tell telecomm to try a different service.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700507 Log.d(this, "adapter handleCreateConnectionFailed %s", callId);
508 mAdapter.handleCreateConnectionFailed(
509 callId,
510 request,
511 DisconnectCause.ERROR_UNSPECIFIED,
512 null);
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700513 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700514 }
515
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700516 private void connectionCreated(
517 String callId,
518 ConnectionRequest request,
519 Connection connection) {
520 addConnection(callId, connection);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700521 Uri handle = connection.getHandle();
522 String number = handle == null ? "null" : handle.getSchemeSpecificPart();
523 Log.v(this, "connectionCreated, parcelableconnection: %s, %d, %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700524 Connection.toLogSafePhoneNumber(number),
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700525 connection.getState(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700526 PhoneCapabilities.toString(connection.getCallCapabilities()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700527
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700528 Log.d(this, "adapter handleCreateConnectionSuccessful %s", callId);
Evan Charltonbf11f982014-07-20 22:06:28 -0700529 mAdapter.handleCreateConnectionSuccessful(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700530 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -0700531 request,
532 new ParcelableConnection(
533 request.getAccountHandle(),
534 connection.getState(),
535 connection.getCallCapabilities(),
536 connection.getHandle(),
537 connection.getHandlePresentation(),
538 connection.getCallerDisplayName(),
539 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700540 connection.getVideoProvider() == null ?
541 null : connection.getVideoProvider().getInterface(),
Evan Charltonbf11f982014-07-20 22:06:28 -0700542 connection.getVideoState()));
543 }
544
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700545 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700546 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700547 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700548 }
549
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700550 private void answer(String callId, int videoState) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700551 Log.d(this, "answer %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700552 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700553 }
554
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700555 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700556 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700557 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700558 }
559
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700560 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700561 Log.d(this, "disconnect %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700562 findConnectionForAction(callId, "disconnect").onDisconnect();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700563 }
564
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700565 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700566 Log.d(this, "hold %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700567 findConnectionForAction(callId, "hold").onHold();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700568 }
569
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700570 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700571 Log.d(this, "unhold %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700572 findConnectionForAction(callId, "unhold").onUnhold();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700573 }
574
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700575 private void onAudioStateChanged(String callId, AudioState audioState) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700576 Log.d(this, "onAudioStateChanged %s %s", callId, audioState);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700577 findConnectionForAction(callId, "onAudioStateChanged").setAudioState(audioState);
578 }
579
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700580 private void playDtmfTone(String callId, char digit) {
581 Log.d(this, "playDtmfTone %s %c", callId, digit);
582 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
583 }
584
585 private void stopDtmfTone(String callId) {
586 Log.d(this, "stopDtmfTone %s", callId);
587 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
588 }
589
590 private void conference(final String conferenceCallId, String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -0700591 Log.d(this, "conference %s, %s", conferenceCallId, callId);
Santos Cordon980acb92014-05-31 10:31:19 -0700592
Santos Cordonb6939982014-06-04 20:20:58 -0700593 Connection connection = findConnectionForAction(callId, "conference");
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700594 if (connection == Connection.getNullConnection()) {
Santos Cordonb6939982014-06-04 20:20:58 -0700595 Log.w(this, "Connection missing in conference request %s.", callId);
596 return;
Santos Cordon980acb92014-05-31 10:31:19 -0700597 }
598
Santos Cordonb6939982014-06-04 20:20:58 -0700599 onCreateConferenceConnection(conferenceCallId, connection,
600 new Response<String, Connection>() {
601 /** ${inheritDoc} */
602 @Override
603 public void onResult(String ignored, Connection... result) {
604 Log.d(this, "onCreateConference.Response %s", (Object[]) result);
605 if (result != null && result.length == 1) {
606 Connection conferenceConnection = result[0];
607 if (!mIdByConnection.containsKey(conferenceConnection)) {
608 Log.v(this, "sending new conference call %s", conferenceCallId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700609 mAdapter.addConferenceCall(conferenceCallId);
Santos Cordonb6939982014-06-04 20:20:58 -0700610 addConnection(conferenceCallId, conferenceConnection);
611 }
612 }
613 }
614
615 /** ${inheritDoc} */
616 @Override
617 public void onError(String request, int code, String reason) {
618 // no-op
619 }
620 });
Santos Cordon980acb92014-05-31 10:31:19 -0700621 }
622
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700623 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -0700624 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -0700625
626 Connection connection = findConnectionForAction(callId, "splitFromConference");
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700627 if (connection == Connection.getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -0700628 Log.w(this, "Connection missing in conference request %s.", callId);
629 return;
630 }
631
Santos Cordon8abea422014-08-06 04:46:17 -0700632 // TODO: Find existing conference call and invoke split(connection).
Santos Cordon980acb92014-05-31 10:31:19 -0700633 }
634
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700635 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700636 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700637 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700638 }
639
Evan Charlton8c8a0622014-07-20 12:31:00 -0700640 private void onPhoneAccountHandleClicked(String callId) {
Sailesh Nepal2bed9562014-07-02 21:26:12 -0700641 Log.d(this, "onPhoneAccountClicked %s", callId);
642 findConnectionForAction(callId, "onPhoneAccountClicked").onPhoneAccountClicked();
643 }
644
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700645 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -0700646 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700647 // No need to query again if we already did it.
648 return;
649 }
650
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700651 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -0700652 @Override
653 public void onResult(
654 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700655 final List<IBinder> services) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700656 mHandler.post(new Runnable() {
657 @Override public void run() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700658 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700659 mRemoteConnectionManager.addConnectionService(
660 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700661 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -0700662 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700663 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700664 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -0700665 }
666 });
667 }
668
669 @Override
670 public void onError() {
671 mHandler.post(new Runnable() {
672 @Override public void run() {
Ihab Awad9c3f1882014-06-30 21:17:13 -0700673 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -0700674 }
675 });
676 }
677 });
678 }
679
Ihab Awadf8b69882014-07-25 15:14:01 -0700680 /**
681 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
682 * incoming request. This is used to attach to existing incoming calls.
683 *
684 * @param connectionManagerPhoneAccount See description at
685 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
686 * @param request Details about the incoming call.
687 * @return The {@code Connection} object to satisfy this call, or {@code null} to
688 * not handle the call.
689 */
690 public final RemoteConnection createRemoteIncomingConnection(
691 PhoneAccountHandle connectionManagerPhoneAccount,
692 ConnectionRequest request) {
693 return mRemoteConnectionManager.createRemoteConnection(
694 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -0700695 }
696
697 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700698 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
699 * outgoing request. This is used to initiate new outgoing calls.
700 *
701 * @param connectionManagerPhoneAccount See description at
702 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
703 * @param request Details about the incoming call.
704 * @return The {@code Connection} object to satisfy this call, or {@code null} to
705 * not handle the call.
706 */
707 public final RemoteConnection createRemoteOutgoingConnection(
708 PhoneAccountHandle connectionManagerPhoneAccount,
709 ConnectionRequest request) {
710 return mRemoteConnectionManager.createRemoteConnection(
711 connectionManagerPhoneAccount, request, false);
712 }
713
714 /**
715 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
716 * has taken responsibility.
717 *
718 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -0700719 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700720 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -0700721 return mConnectionById.values();
722 }
723
724 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700725 * Create a {@code Connection} given an incoming request. This is used to attach to existing
726 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -0700727 *
Ihab Awadf8b69882014-07-25 15:14:01 -0700728 * @param connectionManagerPhoneAccount See description at
729 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
730 * @param request Details about the incoming call.
731 * @return The {@code Connection} object to satisfy this call, or {@code null} to
732 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700733 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700734 public Connection onCreateIncomingConnection(
735 PhoneAccountHandle connectionManagerPhoneAccount,
736 ConnectionRequest request) {
737 return null;
738 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700739
740 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700741 * Create a {@code Connection} given an outgoing request. This is used to initiate new
742 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700743 *
Ihab Awadf8b69882014-07-25 15:14:01 -0700744 * @param connectionManagerPhoneAccount The connection manager account to use for managing
745 * this call.
746 * <p>
747 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
748 * has registered one or more {@code PhoneAccount}s having
749 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
750 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
751 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
752 * making the connection.
753 * <p>
754 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
755 * being asked to make a direct connection. The
756 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
757 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
758 * making the connection.
759 * @param request Details about the outgoing call.
760 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700761 * of {@link Connection#createFailedConnection(int, String)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700762 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700763 public Connection onCreateOutgoingConnection(
764 PhoneAccountHandle connectionManagerPhoneAccount,
765 ConnectionRequest request) {
766 return null;
767 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700768
769 /**
Santos Cordonb6939982014-06-04 20:20:58 -0700770 * Returns a new or existing conference connection when the the user elects to convert the
771 * specified connection into a conference call. The specified connection can be any connection
772 * which had previously specified itself as conference-capable including both simple connections
773 * and connections previously returned from this method.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700774 * <p>
775 * TODO: To be refactored out with conference call re-engineering<br/>
776 * TODO: Also remove class {@link Response} once this method is removed
Santos Cordonb6939982014-06-04 20:20:58 -0700777 *
778 * @param connection The connection from which the user opted to start a conference call.
779 * @param token The token to be passed into the response callback.
780 * @param callback The callback for providing the potentially-new conference connection.
781 */
Santos Cordonf2951102014-07-20 19:06:29 -0700782 public void onCreateConferenceConnection(
Santos Cordonb6939982014-06-04 20:20:58 -0700783 String token,
784 Connection connection,
785 Response<String, Connection> callback) {}
786
787 /**
Santos Cordonb6939982014-06-04 20:20:58 -0700788 * Notifies that a connection has been added to this connection service and sent to Telecomm.
789 *
790 * @param connection The connection which was added.
791 */
Santos Cordonf2951102014-07-20 19:06:29 -0700792 public void onConnectionAdded(Connection connection) {}
Santos Cordonb6939982014-06-04 20:20:58 -0700793
794 /**
795 * Notified that a connection has been removed from this connection service.
796 *
797 * @param connection The connection which was removed.
798 */
Santos Cordonf2951102014-07-20 19:06:29 -0700799 public void onConnectionRemoved(Connection connection) {}
Santos Cordonb6939982014-06-04 20:20:58 -0700800
Ihab Awad5d0410f2014-07-30 10:07:40 -0700801 private void onAccountsInitialized() {
802 mAreAccountsInitialized = true;
803 for (Runnable r : mPreInitializationConnectionRequests) {
804 r.run();
805 }
806 mPreInitializationConnectionRequests.clear();
807 }
808
Ihab Awad542e0ea2014-05-16 10:22:16 -0700809 private void addConnection(String callId, Connection connection) {
810 mConnectionById.put(callId, connection);
811 mIdByConnection.put(connection, callId);
812 connection.addConnectionListener(mConnectionListener);
Santos Cordonb6939982014-06-04 20:20:58 -0700813 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700814 }
815
816 private void removeConnection(Connection connection) {
Ihab Awad8aecfed2014-08-08 17:06:11 -0700817 String id = mIdByConnection.get(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700818 connection.removeConnectionListener(mConnectionListener);
819 mConnectionById.remove(mIdByConnection.get(connection));
820 mIdByConnection.remove(connection);
Santos Cordonb6939982014-06-04 20:20:58 -0700821 onConnectionRemoved(connection);
Ihab Awad8aecfed2014-08-08 17:06:11 -0700822 mAdapter.removeCall(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700823 }
824
825 private Connection findConnectionForAction(String callId, String action) {
826 if (mConnectionById.containsKey(callId)) {
827 return mConnectionById.get(callId);
828 }
Ihab Awad60ac30b2014-05-20 22:32:12 -0700829 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700830 return Connection.getNullConnection();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700831 }
832
Santos Cordon980acb92014-05-31 10:31:19 -0700833}