blob: 10569abc0ccacde0b26bf6181a3be996ddd61922 [file] [log] [blame]
Santos Cordon52d8a152014-06-17 19:08:45 -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 R* limitations under the License.
15 */
16
17package android.telecomm;
18
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -070019import android.app.PendingIntent;
Santos Cordon52d8a152014-06-17 19:08:45 -070020import android.content.ComponentName;
21import android.net.Uri;
Sailesh Nepal48031592014-07-18 14:21:23 -070022import android.os.Handler;
Santos Cordone8dc4be2014-07-21 01:28:28 -070023import android.os.IBinder.DeathRecipient;
Sailesh Nepal48031592014-07-18 14:21:23 -070024import android.os.Message;
Santos Cordon52d8a152014-06-17 19:08:45 -070025import android.os.RemoteException;
26import android.telephony.DisconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -070027import android.text.TextUtils;
28
Sailesh Nepal48031592014-07-18 14:21:23 -070029import com.android.internal.os.SomeArgs;
Santos Cordone8dc4be2014-07-21 01:28:28 -070030import com.android.internal.telecomm.ICallVideoProvider;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070031import com.android.internal.telecomm.IConnectionService;
32import com.android.internal.telecomm.IConnectionServiceAdapter;
Santos Cordon52d8a152014-06-17 19:08:45 -070033import com.android.internal.telecomm.RemoteServiceCallback;
34
Santos Cordon52d8a152014-06-17 19:08:45 -070035import java.util.LinkedList;
36import java.util.List;
37import java.util.UUID;
38
39/**
40 * Remote connection service which other connection services can use to place calls on their behalf.
Sailesh Nepal091768c2014-06-30 15:15:23 -070041 *
42 * @hide
Santos Cordon52d8a152014-06-17 19:08:45 -070043 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070044final class RemoteConnectionService implements DeathRecipient {
Sailesh Nepal48031592014-07-18 14:21:23 -070045 private static final int MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL = 1;
46 private static final int MSG_HANDLE_CREATE_CONNECTION_FAILED = 2;
47 private static final int MSG_HANDLE_CREATE_CONNECTION_CANCELLED = 3;
48 private static final int MSG_SET_ACTIVE = 4;
49 private static final int MSG_SET_RINGING = 5;
50 private static final int MSG_SET_DIALING = 6;
51 private static final int MSG_SET_DISCONNECTED = 7;
52 private static final int MSG_SET_ON_HOLD = 8;
53 private static final int MSG_SET_REQUESTING_RINGBACK = 9;
54 private static final int MSG_SET_CALL_CAPABILITIES = 10;
55 private static final int MSG_SET_IS_CONFERENCED = 11;
56 private static final int MSG_ADD_CONFERENCE_CALL = 12;
57 private static final int MSG_REMOVE_CALL = 13;
58 private static final int MSG_ON_POST_DIAL_WAIT = 14;
59 private static final int MSG_QUERY_REMOTE_CALL_SERVICES = 15;
60 private static final int MSG_SET_VIDEO_STATE = 16;
61 private static final int MSG_SET_CALL_VIDEO_PROVIDER = 17;
62 private static final int MSG_SET_AUDIO_MODE_IS_VOIP = 18;
63 private static final int MSG_SET_STATUS_HINTS = 19;
64 private static final int MSG_SET_HANDLE = 20;
65 private static final int MSG_SET_CALLER_DISPLAY_NAME = 21;
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -070066 private static final int MSG_START_ACTIVITY_FROM_IN_CALL = 22;
Sailesh Nepal48031592014-07-18 14:21:23 -070067
Sailesh Nepal2a46b902014-07-04 17:21:07 -070068 private final IConnectionService mConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -070069 private final ComponentName mComponentName;
70
71 private String mConnectionId;
72 private ConnectionRequest mPendingRequest;
Sailesh Nepalc5b01572014-07-14 16:29:44 -070073 private ConnectionService.CreateConnectionResponse<RemoteConnection> mPendingResponse;
Santos Cordon52d8a152014-06-17 19:08:45 -070074 // Remote connection services only support a single connection.
75 private RemoteConnection mConnection;
76
Sailesh Nepal48031592014-07-18 14:21:23 -070077 private final Handler mHandler = new Handler() {
78 @Override
79 public void handleMessage(Message msg) {
80 switch (msg.what) {
81 case MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL: {
Santos Cordone8dc4be2014-07-21 01:28:28 -070082 SomeArgs args = (SomeArgs) msg.obj;
83 try {
84 ConnectionRequest request = (ConnectionRequest) args.arg1;
85 if (isPendingConnection(request.getCallId())) {
86 ParcelableConnection parcel = (ParcelableConnection) args.arg2;
87 mConnection = new RemoteConnection(
88 mConnectionService, request.getCallId());
89 mConnection.setState(parcel.getState());
90 mConnection.setCallCapabilities(parcel.getCapabilities());
91 mConnection.setHandle(
92 parcel.getHandle(), parcel.getHandlePresentation());
93 mConnection.setCallerDisplayName(
94 parcel.getCallerDisplayName(),
95 parcel.getCallerDisplayNamePresentation());
96 // TODO: Do we need to support video providers for remote connections?
97
98 mPendingResponse.onSuccess(request, mConnection);
99 clearPendingInformation();
100 }
101 } finally {
102 args.recycle();
Sailesh Nepal48031592014-07-18 14:21:23 -0700103 }
104 break;
105 }
106 case MSG_HANDLE_CREATE_CONNECTION_FAILED: {
107 SomeArgs args = (SomeArgs) msg.obj;
108 try {
109 ConnectionRequest request = (ConnectionRequest) args.arg1;
110 if (isPendingConnection(request.getCallId())) {
111 mPendingResponse.onFailure(request, args.argi1, (String) args.arg2);
112 mConnectionId = null;
113 clearPendingInformation();
114 }
115 } finally {
116 args.recycle();
117 }
118 break;
119 }
120 case MSG_HANDLE_CREATE_CONNECTION_CANCELLED: {
121 ConnectionRequest request = (ConnectionRequest) msg.obj;
122 if (isPendingConnection(request.getCallId())) {
123 mPendingResponse.onCancel(request);
124 mConnectionId = null;
125 clearPendingInformation();
126 }
127 break;
128 }
129 case MSG_SET_ACTIVE:
130 if (isCurrentConnection(msg.obj)) {
131 mConnection.setState(Connection.State.ACTIVE);
132 }
133 break;
134 case MSG_SET_RINGING:
135 if (isCurrentConnection(msg.obj)) {
136 mConnection.setState(Connection.State.RINGING);
137 }
138 break;
139 case MSG_SET_DIALING:
140 if (isCurrentConnection(msg.obj)) {
141 mConnection.setState(Connection.State.DIALING);
142 }
143 break;
144 case MSG_SET_DISCONNECTED: {
145 SomeArgs args = (SomeArgs) msg.obj;
146 try {
147 if (isCurrentConnection(args.arg1)) {
148 mConnection.setDisconnected(args.argi1, (String) args.arg2);
149 }
150 } finally {
151 args.recycle();
152 }
153 break;
154 }
155 case MSG_SET_ON_HOLD:
156 if (isCurrentConnection(msg.obj)) {
157 mConnection.setState(Connection.State.HOLDING);
158 }
159 break;
160 case MSG_SET_REQUESTING_RINGBACK:
161 if (isCurrentConnection(msg.obj)) {
162 mConnection.setRequestingRingback(msg.arg1 == 1);
163 }
164 break;
165 case MSG_SET_CALL_CAPABILITIES:
166 if (isCurrentConnection(msg.obj)) {
167 mConnection.setCallCapabilities(msg.arg1);
168 }
169 break;
170 case MSG_SET_IS_CONFERENCED:
171 // not supported for remote connections.
172 break;
173 case MSG_ADD_CONFERENCE_CALL:
174 // not supported for remote connections.
175 break;
176 case MSG_REMOVE_CALL:
177 if (isCurrentConnection(msg.obj)) {
178 destroyConnection();
179 }
180 break;
181 case MSG_ON_POST_DIAL_WAIT: {
182 SomeArgs args = (SomeArgs) msg.obj;
183 try {
184 if (isCurrentConnection(args.arg1)) {
185 mConnection.setPostDialWait((String) args.arg2);
186 }
187 } finally {
188 args.recycle();
189 }
190 break;
191 }
192 case MSG_QUERY_REMOTE_CALL_SERVICES:
193 // Not supported from remote connection service.
194 break;
195 case MSG_SET_VIDEO_STATE:
196 if (isCurrentConnection(msg.obj)) {
197 mConnection.setVideoState(msg.arg1);
198 }
199 break;
200 case MSG_SET_CALL_VIDEO_PROVIDER:
201 // not supported for remote connections.
202 break;
203 case MSG_SET_AUDIO_MODE_IS_VOIP:
204 if (isCurrentConnection(msg.obj)) {
205 mConnection.setAudioModeIsVoip(msg.arg1 == 1);
206 }
207 break;
208 case MSG_SET_STATUS_HINTS: {
209 SomeArgs args = (SomeArgs) msg.obj;
210 try {
211 if (isCurrentConnection(args.arg1)) {
212 mConnection.setStatusHints((StatusHints) args.arg2);
213 }
214 } finally {
215 args.recycle();
216 }
217 break;
218 }
219 case MSG_SET_HANDLE: {
220 SomeArgs args = (SomeArgs) msg.obj;
221 try {
222 if (isCurrentConnection(args.arg1)) {
223 mConnection.setHandle((Uri) args.arg2, args.argi1);
224 }
225 } finally {
226 args.recycle();
227 }
228 break;
229 }
230 case MSG_SET_CALLER_DISPLAY_NAME: {
231 SomeArgs args = (SomeArgs) msg.obj;
232 try {
233 if (isCurrentConnection(msg.arg1)) {
234 mConnection.setCallerDisplayName((String) args.arg2, args.argi1);
235 }
236 } finally {
237 args.recycle();
238 }
239 break;
240 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700241 case MSG_START_ACTIVITY_FROM_IN_CALL: {
242 SomeArgs args = (SomeArgs) msg.obj;
243 try {
244 if (isCurrentConnection(msg.arg1)) {
245 mConnection.startActivityFromInCall((PendingIntent) args.arg2);
246 }
247 } finally {
248 args.recycle();
249 }
250 break;
251 }
Sailesh Nepal48031592014-07-18 14:21:23 -0700252 }
253 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700254
255
Sailesh Nepal48031592014-07-18 14:21:23 -0700256 };
257
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700258 private final IConnectionServiceAdapter mAdapter = new IConnectionServiceAdapter.Stub() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700259 @Override
Santos Cordone8dc4be2014-07-21 01:28:28 -0700260 public void handleCreateConnectionSuccessful(
261 ConnectionRequest request, ParcelableConnection connection) {
262 SomeArgs args = SomeArgs.obtain();
263 args.arg1 = request;
264 args.arg2 = connection;
265 mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL, args).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700266 }
267
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700268 @Override
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700269 public void handleCreateConnectionFailed(
Santos Cordon52d8a152014-06-17 19:08:45 -0700270 ConnectionRequest request, int errorCode, String errorMessage) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700271 SomeArgs args = SomeArgs.obtain();
272 args.arg1 = request;
273 args.argi1 = errorCode;
274 args.arg2 = errorMessage;
275 mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_FAILED, args).sendToTarget();
Sailesh Nepal506e3862014-06-25 13:35:14 -0700276 }
277
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700278 @Override
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700279 public void handleCreateConnectionCancelled(ConnectionRequest request) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700280 mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_CANCELLED, request).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700281 }
282
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700283 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700284 public void setActive(String connectionId) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700285 mHandler.obtainMessage(MSG_SET_ACTIVE, connectionId).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700286 }
287
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700288 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700289 public void setRinging(String connectionId) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700290 mHandler.obtainMessage(MSG_SET_RINGING, connectionId).sendToTarget();
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700291 }
292
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700293 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700294 public void setDialing(String connectionId) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700295 mHandler.obtainMessage(MSG_SET_DIALING, connectionId).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700296 }
297
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700298 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700299 public void setDisconnected(
300 String connectionId, int disconnectCause, String disconnectMessage) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700301 SomeArgs args = SomeArgs.obtain();
302 args.arg1 = connectionId;
303 args.arg2 = disconnectMessage;
304 args.argi1 = disconnectCause;
305 mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700306 }
307
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700308 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700309 public void setOnHold(String connectionId) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700310 mHandler.obtainMessage(MSG_SET_ON_HOLD, connectionId).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700311 }
312
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700313 @Override
Sailesh Nepal48031592014-07-18 14:21:23 -0700314 public void setRequestingRingback(String connectionId, boolean ringback) {
315 mHandler.obtainMessage(MSG_SET_REQUESTING_RINGBACK, ringback ? 1 : 0, 0, connectionId)
316 .sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700317 }
318
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700319 @Override
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700320 public void setCallCapabilities(String connectionId, int callCapabilities) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700321 mHandler.obtainMessage(MSG_SET_CALL_CAPABILITIES, callCapabilities, 0, connectionId)
322 .sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700323 }
324
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700325 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700326 public void setIsConferenced(String connectionId, String conferenceConnectionId) {
327 // not supported for remote connections.
328 }
329
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700330 @Override
331 public void addConferenceCall(String connectionId) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700332 // not supported for remote connections.
333 }
334
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700335 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700336 public void removeCall(String connectionId) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700337 mHandler.obtainMessage(MSG_REMOVE_CALL, connectionId).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700338 }
339
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700340 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700341 public void onPostDialWait(String connectionId, String remainingDigits) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700342 SomeArgs args = SomeArgs.obtain();
343 args.arg1 = connectionId;
344 args.arg2 = remainingDigits;
345 mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700346 }
347
Santos Cordon52d8a152014-06-17 19:08:45 -0700348 @Override
349 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
350 try {
351 // Not supported from remote connection service.
352 callback.onError();
353 } catch (RemoteException e) {
354 }
355 }
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700356
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700357 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -0700358 public void setVideoState(String connectionId, int videoState) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700359 mHandler.obtainMessage(MSG_SET_VIDEO_STATE, videoState, 0, connectionId).sendToTarget();
360 }
361
362 @Override
363 public void setCallVideoProvider(
364 String connectionId, ICallVideoProvider callVideoProvider) {
365 // not supported for remote connections.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700366 }
367
368 @Override
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700369 public final void setAudioModeIsVoip(String connectionId, boolean isVoip) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700370 mHandler.obtainMessage(MSG_SET_AUDIO_MODE_IS_VOIP, isVoip ? 1 : 0, 0,
371 connectionId).sendToTarget();
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700372 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700373
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700374 @Override
375 public final void setStatusHints(String connectionId, StatusHints statusHints) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700376 SomeArgs args = SomeArgs.obtain();
377 args.arg1 = connectionId;
378 args.arg2 = statusHints;
379 mHandler.obtainMessage(MSG_SET_STATUS_HINTS, args).sendToTarget();
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700380 }
Sailesh Nepal61203862014-07-11 14:50:13 -0700381
382 @Override
383 public final void setHandle(String connectionId, Uri handle, int presentation) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700384 SomeArgs args = SomeArgs.obtain();
385 args.arg1 = connectionId;
386 args.arg2 = handle;
387 args.argi1 = presentation;
388 mHandler.obtainMessage(MSG_SET_HANDLE, args).sendToTarget();
Sailesh Nepal61203862014-07-11 14:50:13 -0700389 }
390
391 @Override
392 public final void setCallerDisplayName(
393 String connectionId, String callerDisplayName, int presentation) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700394 SomeArgs args = SomeArgs.obtain();
395 args.arg1 = connectionId;
396 args.arg2 = callerDisplayName;
397 args.argi1 = presentation;
398 mHandler.obtainMessage(MSG_SET_CALLER_DISPLAY_NAME, args).sendToTarget();
Sailesh Nepal61203862014-07-11 14:50:13 -0700399 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700400
401 @Override
402 public final void startActivityFromInCall(String connectionId, PendingIntent intent) {
403 SomeArgs args = SomeArgs.obtain();
404 args.arg1 = connectionId;
405 args.arg2 = intent;
406 mHandler.obtainMessage(MSG_START_ACTIVITY_FROM_IN_CALL, args).sendToTarget();
407 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700408 };
409
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700410 RemoteConnectionService(ComponentName componentName, IConnectionService connectionService)
Santos Cordon52d8a152014-06-17 19:08:45 -0700411 throws RemoteException {
412 mComponentName = componentName;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700413 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700414
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700415 mConnectionService.addConnectionServiceAdapter(mAdapter);
416 mConnectionService.asBinder().linkToDeath(this, 0);
Santos Cordon52d8a152014-06-17 19:08:45 -0700417 }
418
419 @Override
420 public String toString() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700421 return "[RemoteCS - " + mConnectionService.asBinder().toString() + "]";
Santos Cordon52d8a152014-06-17 19:08:45 -0700422 }
423
424 /** ${inheritDoc} */
425 @Override
Sailesh Nepal091768c2014-06-30 15:15:23 -0700426 public final void binderDied() {
Santos Cordon52d8a152014-06-17 19:08:45 -0700427 if (mConnection != null) {
428 destroyConnection();
429 }
430
431 release();
432 }
433
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700434 final void createRemoteConnection(
Santos Cordon52d8a152014-06-17 19:08:45 -0700435 ConnectionRequest request,
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700436 ConnectionService.CreateConnectionResponse<RemoteConnection> response,
437 boolean isIncoming) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700438
439 if (mConnectionId == null) {
440 String id = UUID.randomUUID().toString();
Sailesh Nepal61203862014-07-11 14:50:13 -0700441 ConnectionRequest newRequest = new ConnectionRequest(
Evan Charlton8c8a0622014-07-20 12:31:00 -0700442 request.getAccountHandle(),
Sailesh Nepal61203862014-07-11 14:50:13 -0700443 id,
444 request.getHandle(),
445 request.getHandlePresentation(),
446 request.getExtras(),
447 request.getVideoState());
Santos Cordon52d8a152014-06-17 19:08:45 -0700448 try {
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700449 mConnectionService.createConnection(newRequest, isIncoming);
Santos Cordon52d8a152014-06-17 19:08:45 -0700450 mConnectionId = id;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700451 mPendingResponse = response;
Santos Cordon52d8a152014-06-17 19:08:45 -0700452 mPendingRequest = request;
453 } catch (RemoteException e) {
Sailesh Nepal506e3862014-06-25 13:35:14 -0700454 response.onFailure(request, DisconnectCause.ERROR_UNSPECIFIED, e.toString());
Santos Cordon52d8a152014-06-17 19:08:45 -0700455 }
456 } else {
Sailesh Nepal506e3862014-06-25 13:35:14 -0700457 response.onFailure(request, DisconnectCause.ERROR_UNSPECIFIED, null);
Santos Cordon52d8a152014-06-17 19:08:45 -0700458 }
459 }
460
Evan Charlton6eb262c2014-07-19 18:18:19 -0700461 final List<PhoneAccountHandle> lookupAccounts(Uri handle) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700462 // TODO(santoscordon): Update this so that is actually calls into the RemoteConnection
463 // each time.
Evan Charlton6eb262c2014-07-19 18:18:19 -0700464 List<PhoneAccountHandle> accounts = new LinkedList<>();
465 accounts.add(new PhoneAccountHandle(
Santos Cordon52d8a152014-06-17 19:08:45 -0700466 mComponentName,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700467 null /* id */));
Ihab Awad9c3f1882014-06-30 21:17:13 -0700468 return accounts;
Santos Cordon52d8a152014-06-17 19:08:45 -0700469 }
470
471 /**
472 * Releases the resources associated with this Remote connection service. Should be called when
473 * the remote service is no longer being used.
474 */
475 void release() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700476 mConnectionService.asBinder().unlinkToDeath(this, 0);
Santos Cordon52d8a152014-06-17 19:08:45 -0700477 }
478
479 private boolean isPendingConnection(String id) {
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700480 return TextUtils.equals(mConnectionId, id) && mPendingResponse != null;
Santos Cordon52d8a152014-06-17 19:08:45 -0700481 }
482
Sailesh Nepal48031592014-07-18 14:21:23 -0700483 private boolean isCurrentConnection(Object obj) {
484 return obj instanceof String && mConnection != null &&
485 TextUtils.equals(mConnectionId, (String) obj);
Santos Cordon52d8a152014-06-17 19:08:45 -0700486 }
487
488 private void clearPendingInformation() {
489 mPendingRequest = null;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700490 mPendingResponse = null;
Santos Cordon52d8a152014-06-17 19:08:45 -0700491 }
492
493 private void destroyConnection() {
494 mConnection.setDestroyed();
495 mConnection = null;
496 mConnectionId = null;
497 }
498}