blob: 6c024c6de68c4b1572eae2b481e86397533645f4 [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;
22import android.os.IBinder.DeathRecipient;
Sailesh Nepal48031592014-07-18 14:21:23 -070023import android.os.Handler;
24import android.os.Message;
Santos Cordon52d8a152014-06-17 19:08:45 -070025import android.os.RemoteException;
26import android.telephony.DisconnectCause;
27
28import android.text.TextUtils;
29
Sailesh Nepal48031592014-07-18 14:21:23 -070030import com.android.internal.os.SomeArgs;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070031import com.android.internal.telecomm.IConnectionService;
32import com.android.internal.telecomm.IConnectionServiceAdapter;
Andrew Lee5ffbe8b2014-06-20 16:29:33 -070033import com.android.internal.telecomm.ICallVideoProvider;
Santos Cordon52d8a152014-06-17 19:08:45 -070034import com.android.internal.telecomm.RemoteServiceCallback;
35
Santos Cordon52d8a152014-06-17 19:08:45 -070036import java.util.LinkedList;
37import java.util.List;
38import java.util.UUID;
39
40/**
41 * Remote connection service which other connection services can use to place calls on their behalf.
Sailesh Nepal091768c2014-06-30 15:15:23 -070042 *
43 * @hide
Santos Cordon52d8a152014-06-17 19:08:45 -070044 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070045final class RemoteConnectionService implements DeathRecipient {
Sailesh Nepal48031592014-07-18 14:21:23 -070046 private static final int MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL = 1;
47 private static final int MSG_HANDLE_CREATE_CONNECTION_FAILED = 2;
48 private static final int MSG_HANDLE_CREATE_CONNECTION_CANCELLED = 3;
49 private static final int MSG_SET_ACTIVE = 4;
50 private static final int MSG_SET_RINGING = 5;
51 private static final int MSG_SET_DIALING = 6;
52 private static final int MSG_SET_DISCONNECTED = 7;
53 private static final int MSG_SET_ON_HOLD = 8;
54 private static final int MSG_SET_REQUESTING_RINGBACK = 9;
55 private static final int MSG_SET_CALL_CAPABILITIES = 10;
56 private static final int MSG_SET_IS_CONFERENCED = 11;
57 private static final int MSG_ADD_CONFERENCE_CALL = 12;
58 private static final int MSG_REMOVE_CALL = 13;
59 private static final int MSG_ON_POST_DIAL_WAIT = 14;
60 private static final int MSG_QUERY_REMOTE_CALL_SERVICES = 15;
61 private static final int MSG_SET_VIDEO_STATE = 16;
62 private static final int MSG_SET_CALL_VIDEO_PROVIDER = 17;
63 private static final int MSG_SET_AUDIO_MODE_IS_VOIP = 18;
64 private static final int MSG_SET_STATUS_HINTS = 19;
65 private static final int MSG_SET_HANDLE = 20;
66 private static final int MSG_SET_CALLER_DISPLAY_NAME = 21;
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -070067 private static final int MSG_START_ACTIVITY_FROM_IN_CALL = 22;
Sailesh Nepal48031592014-07-18 14:21:23 -070068
Sailesh Nepal2a46b902014-07-04 17:21:07 -070069 private final IConnectionService mConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -070070 private final ComponentName mComponentName;
71
72 private String mConnectionId;
73 private ConnectionRequest mPendingRequest;
Sailesh Nepalc5b01572014-07-14 16:29:44 -070074 private ConnectionService.CreateConnectionResponse<RemoteConnection> mPendingResponse;
Santos Cordon52d8a152014-06-17 19:08:45 -070075 // Remote connection services only support a single connection.
76 private RemoteConnection mConnection;
77
Sailesh Nepal48031592014-07-18 14:21:23 -070078 private final Handler mHandler = new Handler() {
79 @Override
80 public void handleMessage(Message msg) {
81 switch (msg.what) {
82 case MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL: {
83 ConnectionRequest request = (ConnectionRequest) msg.obj;
84 if (isPendingConnection(request.getCallId())) {
85 mConnection = new RemoteConnection(mConnectionService, request.getCallId());
86 mPendingResponse.onSuccess(request, mConnection);
87 clearPendingInformation();
88 }
89 break;
90 }
91 case MSG_HANDLE_CREATE_CONNECTION_FAILED: {
92 SomeArgs args = (SomeArgs) msg.obj;
93 try {
94 ConnectionRequest request = (ConnectionRequest) args.arg1;
95 if (isPendingConnection(request.getCallId())) {
96 mPendingResponse.onFailure(request, args.argi1, (String) args.arg2);
97 mConnectionId = null;
98 clearPendingInformation();
99 }
100 } finally {
101 args.recycle();
102 }
103 break;
104 }
105 case MSG_HANDLE_CREATE_CONNECTION_CANCELLED: {
106 ConnectionRequest request = (ConnectionRequest) msg.obj;
107 if (isPendingConnection(request.getCallId())) {
108 mPendingResponse.onCancel(request);
109 mConnectionId = null;
110 clearPendingInformation();
111 }
112 break;
113 }
114 case MSG_SET_ACTIVE:
115 if (isCurrentConnection(msg.obj)) {
116 mConnection.setState(Connection.State.ACTIVE);
117 }
118 break;
119 case MSG_SET_RINGING:
120 if (isCurrentConnection(msg.obj)) {
121 mConnection.setState(Connection.State.RINGING);
122 }
123 break;
124 case MSG_SET_DIALING:
125 if (isCurrentConnection(msg.obj)) {
126 mConnection.setState(Connection.State.DIALING);
127 }
128 break;
129 case MSG_SET_DISCONNECTED: {
130 SomeArgs args = (SomeArgs) msg.obj;
131 try {
132 if (isCurrentConnection(args.arg1)) {
133 mConnection.setDisconnected(args.argi1, (String) args.arg2);
134 }
135 } finally {
136 args.recycle();
137 }
138 break;
139 }
140 case MSG_SET_ON_HOLD:
141 if (isCurrentConnection(msg.obj)) {
142 mConnection.setState(Connection.State.HOLDING);
143 }
144 break;
145 case MSG_SET_REQUESTING_RINGBACK:
146 if (isCurrentConnection(msg.obj)) {
147 mConnection.setRequestingRingback(msg.arg1 == 1);
148 }
149 break;
150 case MSG_SET_CALL_CAPABILITIES:
151 if (isCurrentConnection(msg.obj)) {
152 mConnection.setCallCapabilities(msg.arg1);
153 }
154 break;
155 case MSG_SET_IS_CONFERENCED:
156 // not supported for remote connections.
157 break;
158 case MSG_ADD_CONFERENCE_CALL:
159 // not supported for remote connections.
160 break;
161 case MSG_REMOVE_CALL:
162 if (isCurrentConnection(msg.obj)) {
163 destroyConnection();
164 }
165 break;
166 case MSG_ON_POST_DIAL_WAIT: {
167 SomeArgs args = (SomeArgs) msg.obj;
168 try {
169 if (isCurrentConnection(args.arg1)) {
170 mConnection.setPostDialWait((String) args.arg2);
171 }
172 } finally {
173 args.recycle();
174 }
175 break;
176 }
177 case MSG_QUERY_REMOTE_CALL_SERVICES:
178 // Not supported from remote connection service.
179 break;
180 case MSG_SET_VIDEO_STATE:
181 if (isCurrentConnection(msg.obj)) {
182 mConnection.setVideoState(msg.arg1);
183 }
184 break;
185 case MSG_SET_CALL_VIDEO_PROVIDER:
186 // not supported for remote connections.
187 break;
188 case MSG_SET_AUDIO_MODE_IS_VOIP:
189 if (isCurrentConnection(msg.obj)) {
190 mConnection.setAudioModeIsVoip(msg.arg1 == 1);
191 }
192 break;
193 case MSG_SET_STATUS_HINTS: {
194 SomeArgs args = (SomeArgs) msg.obj;
195 try {
196 if (isCurrentConnection(args.arg1)) {
197 mConnection.setStatusHints((StatusHints) args.arg2);
198 }
199 } finally {
200 args.recycle();
201 }
202 break;
203 }
204 case MSG_SET_HANDLE: {
205 SomeArgs args = (SomeArgs) msg.obj;
206 try {
207 if (isCurrentConnection(args.arg1)) {
208 mConnection.setHandle((Uri) args.arg2, args.argi1);
209 }
210 } finally {
211 args.recycle();
212 }
213 break;
214 }
215 case MSG_SET_CALLER_DISPLAY_NAME: {
216 SomeArgs args = (SomeArgs) msg.obj;
217 try {
218 if (isCurrentConnection(msg.arg1)) {
219 mConnection.setCallerDisplayName((String) args.arg2, args.argi1);
220 }
221 } finally {
222 args.recycle();
223 }
224 break;
225 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700226 case MSG_START_ACTIVITY_FROM_IN_CALL: {
227 SomeArgs args = (SomeArgs) msg.obj;
228 try {
229 if (isCurrentConnection(msg.arg1)) {
230 mConnection.startActivityFromInCall((PendingIntent) args.arg2);
231 }
232 } finally {
233 args.recycle();
234 }
235 break;
236 }
Sailesh Nepal48031592014-07-18 14:21:23 -0700237 }
238 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700239
240
Sailesh Nepal48031592014-07-18 14:21:23 -0700241 };
242
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700243 private final IConnectionServiceAdapter mAdapter = new IConnectionServiceAdapter.Stub() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700244 @Override
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700245 public void handleCreateConnectionSuccessful(ConnectionRequest request) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700246 mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL, request).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700247 }
248
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700249 @Override
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700250 public void handleCreateConnectionFailed(
Santos Cordon52d8a152014-06-17 19:08:45 -0700251 ConnectionRequest request, int errorCode, String errorMessage) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700252 SomeArgs args = SomeArgs.obtain();
253 args.arg1 = request;
254 args.argi1 = errorCode;
255 args.arg2 = errorMessage;
256 mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_FAILED, args).sendToTarget();
Sailesh Nepal506e3862014-06-25 13:35:14 -0700257 }
258
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700259 @Override
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700260 public void handleCreateConnectionCancelled(ConnectionRequest request) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700261 mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_CANCELLED, request).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700262 }
263
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700264 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700265 public void setActive(String connectionId) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700266 mHandler.obtainMessage(MSG_SET_ACTIVE, connectionId).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700267 }
268
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700269 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700270 public void setRinging(String connectionId) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700271 mHandler.obtainMessage(MSG_SET_RINGING, connectionId).sendToTarget();
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700272 }
273
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700274 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700275 public void setDialing(String connectionId) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700276 mHandler.obtainMessage(MSG_SET_DIALING, connectionId).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700277 }
278
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700279 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700280 public void setDisconnected(
281 String connectionId, int disconnectCause, String disconnectMessage) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700282 SomeArgs args = SomeArgs.obtain();
283 args.arg1 = connectionId;
284 args.arg2 = disconnectMessage;
285 args.argi1 = disconnectCause;
286 mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700287 }
288
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700289 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700290 public void setOnHold(String connectionId) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700291 mHandler.obtainMessage(MSG_SET_ON_HOLD, connectionId).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700292 }
293
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700294 @Override
Sailesh Nepal48031592014-07-18 14:21:23 -0700295 public void setRequestingRingback(String connectionId, boolean ringback) {
296 mHandler.obtainMessage(MSG_SET_REQUESTING_RINGBACK, ringback ? 1 : 0, 0, connectionId)
297 .sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700298 }
299
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700300 @Override
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700301 public void setCallCapabilities(String connectionId, int callCapabilities) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700302 mHandler.obtainMessage(MSG_SET_CALL_CAPABILITIES, callCapabilities, 0, connectionId)
303 .sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700304 }
305
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700306 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700307 public void setIsConferenced(String connectionId, String conferenceConnectionId) {
308 // not supported for remote connections.
309 }
310
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700311 @Override
312 public void addConferenceCall(String connectionId) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700313 // not supported for remote connections.
314 }
315
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700316 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700317 public void removeCall(String connectionId) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700318 mHandler.obtainMessage(MSG_REMOVE_CALL, connectionId).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700319 }
320
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700321 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700322 public void onPostDialWait(String connectionId, String remainingDigits) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700323 SomeArgs args = SomeArgs.obtain();
324 args.arg1 = connectionId;
325 args.arg2 = remainingDigits;
326 mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget();
Santos Cordon52d8a152014-06-17 19:08:45 -0700327 }
328
Santos Cordon52d8a152014-06-17 19:08:45 -0700329 @Override
330 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
331 try {
332 // Not supported from remote connection service.
333 callback.onError();
334 } catch (RemoteException e) {
335 }
336 }
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700337
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700338 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -0700339 public void setVideoState(String connectionId, int videoState) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700340 mHandler.obtainMessage(MSG_SET_VIDEO_STATE, videoState, 0, connectionId).sendToTarget();
341 }
342
343 @Override
344 public void setCallVideoProvider(
345 String connectionId, ICallVideoProvider callVideoProvider) {
346 // not supported for remote connections.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700347 }
348
349 @Override
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700350 public final void setAudioModeIsVoip(String connectionId, boolean isVoip) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700351 mHandler.obtainMessage(MSG_SET_AUDIO_MODE_IS_VOIP, isVoip ? 1 : 0, 0,
352 connectionId).sendToTarget();
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700353 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700354
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700355 @Override
356 public final void setStatusHints(String connectionId, StatusHints statusHints) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700357 SomeArgs args = SomeArgs.obtain();
358 args.arg1 = connectionId;
359 args.arg2 = statusHints;
360 mHandler.obtainMessage(MSG_SET_STATUS_HINTS, args).sendToTarget();
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700361 }
Sailesh Nepal61203862014-07-11 14:50:13 -0700362
363 @Override
364 public final void setHandle(String connectionId, Uri handle, int presentation) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700365 SomeArgs args = SomeArgs.obtain();
366 args.arg1 = connectionId;
367 args.arg2 = handle;
368 args.argi1 = presentation;
369 mHandler.obtainMessage(MSG_SET_HANDLE, args).sendToTarget();
Sailesh Nepal61203862014-07-11 14:50:13 -0700370 }
371
372 @Override
373 public final void setCallerDisplayName(
374 String connectionId, String callerDisplayName, int presentation) {
Sailesh Nepal48031592014-07-18 14:21:23 -0700375 SomeArgs args = SomeArgs.obtain();
376 args.arg1 = connectionId;
377 args.arg2 = callerDisplayName;
378 args.argi1 = presentation;
379 mHandler.obtainMessage(MSG_SET_CALLER_DISPLAY_NAME, args).sendToTarget();
Sailesh Nepal61203862014-07-11 14:50:13 -0700380 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700381
382 @Override
383 public final void startActivityFromInCall(String connectionId, PendingIntent intent) {
384 SomeArgs args = SomeArgs.obtain();
385 args.arg1 = connectionId;
386 args.arg2 = intent;
387 mHandler.obtainMessage(MSG_START_ACTIVITY_FROM_IN_CALL, args).sendToTarget();
388 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700389 };
390
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700391 RemoteConnectionService(ComponentName componentName, IConnectionService connectionService)
Santos Cordon52d8a152014-06-17 19:08:45 -0700392 throws RemoteException {
393 mComponentName = componentName;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700394 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700395
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700396 mConnectionService.addConnectionServiceAdapter(mAdapter);
397 mConnectionService.asBinder().linkToDeath(this, 0);
Santos Cordon52d8a152014-06-17 19:08:45 -0700398 }
399
400 @Override
401 public String toString() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700402 return "[RemoteCS - " + mConnectionService.asBinder().toString() + "]";
Santos Cordon52d8a152014-06-17 19:08:45 -0700403 }
404
405 /** ${inheritDoc} */
406 @Override
Sailesh Nepal091768c2014-06-30 15:15:23 -0700407 public final void binderDied() {
Santos Cordon52d8a152014-06-17 19:08:45 -0700408 if (mConnection != null) {
409 destroyConnection();
410 }
411
412 release();
413 }
414
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700415 final void createRemoteConnection(
Santos Cordon52d8a152014-06-17 19:08:45 -0700416 ConnectionRequest request,
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700417 ConnectionService.CreateConnectionResponse<RemoteConnection> response,
418 boolean isIncoming) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700419
420 if (mConnectionId == null) {
421 String id = UUID.randomUUID().toString();
Sailesh Nepal61203862014-07-11 14:50:13 -0700422 ConnectionRequest newRequest = new ConnectionRequest(
423 request.getAccount(),
424 id,
425 request.getHandle(),
426 request.getHandlePresentation(),
427 request.getExtras(),
428 request.getVideoState());
Santos Cordon52d8a152014-06-17 19:08:45 -0700429 try {
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700430 mConnectionService.createConnection(newRequest, isIncoming);
Santos Cordon52d8a152014-06-17 19:08:45 -0700431 mConnectionId = id;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700432 mPendingResponse = response;
Santos Cordon52d8a152014-06-17 19:08:45 -0700433 mPendingRequest = request;
434 } catch (RemoteException e) {
Sailesh Nepal506e3862014-06-25 13:35:14 -0700435 response.onFailure(request, DisconnectCause.ERROR_UNSPECIFIED, e.toString());
Santos Cordon52d8a152014-06-17 19:08:45 -0700436 }
437 } else {
Sailesh Nepal506e3862014-06-25 13:35:14 -0700438 response.onFailure(request, DisconnectCause.ERROR_UNSPECIFIED, null);
Santos Cordon52d8a152014-06-17 19:08:45 -0700439 }
440 }
441
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700442 final List<PhoneAccount> lookupAccounts(Uri handle) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700443 // TODO(santoscordon): Update this so that is actually calls into the RemoteConnection
444 // each time.
Ihab Awad9c3f1882014-06-30 21:17:13 -0700445 List<PhoneAccount> accounts = new LinkedList<>();
446 accounts.add(new PhoneAccount(
Santos Cordon52d8a152014-06-17 19:08:45 -0700447 mComponentName,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700448 null /* id */));
Ihab Awad9c3f1882014-06-30 21:17:13 -0700449 return accounts;
Santos Cordon52d8a152014-06-17 19:08:45 -0700450 }
451
452 /**
453 * Releases the resources associated with this Remote connection service. Should be called when
454 * the remote service is no longer being used.
455 */
456 void release() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700457 mConnectionService.asBinder().unlinkToDeath(this, 0);
Santos Cordon52d8a152014-06-17 19:08:45 -0700458 }
459
460 private boolean isPendingConnection(String id) {
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700461 return TextUtils.equals(mConnectionId, id) && mPendingResponse != null;
Santos Cordon52d8a152014-06-17 19:08:45 -0700462 }
463
Sailesh Nepal48031592014-07-18 14:21:23 -0700464 private boolean isCurrentConnection(Object obj) {
465 return obj instanceof String && mConnection != null &&
466 TextUtils.equals(mConnectionId, (String) obj);
Santos Cordon52d8a152014-06-17 19:08:45 -0700467 }
468
469 private void clearPendingInformation() {
470 mPendingRequest = null;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700471 mPendingResponse = null;
Santos Cordon52d8a152014-06-17 19:08:45 -0700472 }
473
474 private void destroyConnection() {
475 mConnection.setDestroyed();
476 mConnection = null;
477 mConnectionId = null;
478 }
479}