blob: db815ba7a86f7b977058f7a09f13054f883929a9 [file] [log] [blame]
Ihab Awad5d0410f2014-07-30 10:07:40 -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
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad5d0410f2014-07-30 10:07:40 -070018
Ihab Awad5d0410f2014-07-30 10:07:40 -070019import android.net.Uri;
20import android.os.Handler;
21import android.os.Message;
22import android.os.RemoteException;
23
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070024import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070025import com.android.internal.telecom.IConnectionServiceAdapter;
26import com.android.internal.telecom.IVideoProvider;
27import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070028
29import java.util.List;
30
Ihab Awad5d0410f2014-07-30 10:07:40 -070031/**
32 * A component that provides an RPC servant implementation of {@link IConnectionServiceAdapter},
33 * posting incoming messages on the main thread on a client-supplied delegate object.
34 *
35 * TODO: Generate this and similar classes using a compiler starting from AIDL interfaces.
36 *
37 * @hide
38 */
39final class ConnectionServiceAdapterServant {
Ihab Awad6107bab2014-08-18 09:23:25 -070040 private static final int MSG_HANDLE_CREATE_CONNECTION_COMPLETE = 1;
41 private static final int MSG_SET_ACTIVE = 2;
42 private static final int MSG_SET_RINGING = 3;
43 private static final int MSG_SET_DIALING = 4;
44 private static final int MSG_SET_DISCONNECTED = 5;
45 private static final int MSG_SET_ON_HOLD = 6;
Andrew Lee100e2932014-09-08 15:34:24 -070046 private static final int MSG_SET_RINGBACK_REQUESTED = 7;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080047 private static final int MSG_SET_CONNECTION_CAPABILITIES = 8;
Ihab Awad6107bab2014-08-18 09:23:25 -070048 private static final int MSG_SET_IS_CONFERENCED = 9;
49 private static final int MSG_ADD_CONFERENCE_CALL = 10;
50 private static final int MSG_REMOVE_CALL = 11;
51 private static final int MSG_ON_POST_DIAL_WAIT = 12;
52 private static final int MSG_QUERY_REMOTE_CALL_SERVICES = 13;
53 private static final int MSG_SET_VIDEO_STATE = 14;
54 private static final int MSG_SET_VIDEO_CALL_PROVIDER = 15;
Andrew Lee100e2932014-09-08 15:34:24 -070055 private static final int MSG_SET_IS_VOIP_AUDIO_MODE = 16;
Ihab Awad6107bab2014-08-18 09:23:25 -070056 private static final int MSG_SET_STATUS_HINTS = 17;
Andrew Lee100e2932014-09-08 15:34:24 -070057 private static final int MSG_SET_ADDRESS = 18;
Ihab Awad6107bab2014-08-18 09:23:25 -070058 private static final int MSG_SET_CALLER_DISPLAY_NAME = 19;
Evan Charlton23dc2412014-09-03 10:07:03 -070059 private static final int MSG_SET_CONFERENCEABLE_CONNECTIONS = 20;
Tyler Gunn4a57b9b2014-10-30 14:27:48 -070060 private static final int MSG_ADD_EXISTING_CONNECTION = 21;
Nancy Chen27d1c2d2014-12-15 16:12:50 -080061 private static final int MSG_ON_POST_DIAL_CHAR = 22;
Anthony Lee17455a32015-04-24 15:25:29 -070062 private static final int MSG_SET_CONFERENCE_MERGE_FAILED = 23;
Ihab Awad5d0410f2014-07-30 10:07:40 -070063
64 private final IConnectionServiceAdapter mDelegate;
65
66 private final Handler mHandler = new Handler() {
67 @Override
68 public void handleMessage(Message msg) {
69 try {
70 internalHandleMessage(msg);
71 } catch (RemoteException e) {
72 }
73 }
74
75 // Internal method defined to centralize handling of RemoteException
76 private void internalHandleMessage(Message msg) throws RemoteException {
77 switch (msg.what) {
Ihab Awad6107bab2014-08-18 09:23:25 -070078 case MSG_HANDLE_CREATE_CONNECTION_COMPLETE: {
Ihab Awad5d0410f2014-07-30 10:07:40 -070079 SomeArgs args = (SomeArgs) msg.obj;
80 try {
Ihab Awad6107bab2014-08-18 09:23:25 -070081 mDelegate.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -070082 (String) args.arg1,
83 (ConnectionRequest) args.arg2,
84 (ParcelableConnection) args.arg3);
Ihab Awad5d0410f2014-07-30 10:07:40 -070085 } finally {
86 args.recycle();
87 }
88 break;
89 }
Ihab Awad5d0410f2014-07-30 10:07:40 -070090 case MSG_SET_ACTIVE:
91 mDelegate.setActive((String) msg.obj);
92 break;
93 case MSG_SET_RINGING:
94 mDelegate.setRinging((String) msg.obj);
95 break;
96 case MSG_SET_DIALING:
97 mDelegate.setDialing((String) msg.obj);
98 break;
99 case MSG_SET_DISCONNECTED: {
100 SomeArgs args = (SomeArgs) msg.obj;
101 try {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700102 mDelegate.setDisconnected((String) args.arg1, (DisconnectCause) args.arg2);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700103 } finally {
104 args.recycle();
105 }
106 break;
107 }
108 case MSG_SET_ON_HOLD:
109 mDelegate.setOnHold((String) msg.obj);
110 break;
Andrew Lee100e2932014-09-08 15:34:24 -0700111 case MSG_SET_RINGBACK_REQUESTED:
112 mDelegate.setRingbackRequested((String) msg.obj, msg.arg1 == 1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700113 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800114 case MSG_SET_CONNECTION_CAPABILITIES:
115 mDelegate.setConnectionCapabilities((String) msg.obj, msg.arg1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700116 break;
117 case MSG_SET_IS_CONFERENCED: {
118 SomeArgs args = (SomeArgs) msg.obj;
119 try {
120 mDelegate.setIsConferenced((String) args.arg1, (String) args.arg2);
121 } finally {
122 args.recycle();
123 }
124 break;
125 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700126 case MSG_ADD_CONFERENCE_CALL: {
127 SomeArgs args = (SomeArgs) msg.obj;
128 try {
129 mDelegate.addConferenceCall(
130 (String) args.arg1, (ParcelableConference) args.arg2);
131 } finally {
132 args.recycle();
133 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700134 break;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700135 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700136 case MSG_REMOVE_CALL:
137 mDelegate.removeCall((String) msg.obj);
138 break;
139 case MSG_ON_POST_DIAL_WAIT: {
140 SomeArgs args = (SomeArgs) msg.obj;
141 try {
142 mDelegate.onPostDialWait((String) args.arg1, (String) args.arg2);
143 } finally {
144 args.recycle();
145 }
146 break;
147 }
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800148 case MSG_ON_POST_DIAL_CHAR: {
149 SomeArgs args = (SomeArgs) msg.obj;
150 try {
151 mDelegate.onPostDialChar((String) args.arg1, (char) args.argi1);
152 } finally {
153 args.recycle();
154 }
155 break;
156 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700157 case MSG_QUERY_REMOTE_CALL_SERVICES:
158 mDelegate.queryRemoteConnectionServices((RemoteServiceCallback) msg.obj);
159 break;
160 case MSG_SET_VIDEO_STATE:
161 mDelegate.setVideoState((String) msg.obj, msg.arg1);
162 break;
163 case MSG_SET_VIDEO_CALL_PROVIDER: {
164 SomeArgs args = (SomeArgs) msg.obj;
165 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700166 mDelegate.setVideoProvider((String) args.arg1,
167 (IVideoProvider) args.arg2);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700168 } finally {
169 args.recycle();
170 }
171 break;
172 }
Andrew Lee100e2932014-09-08 15:34:24 -0700173 case MSG_SET_IS_VOIP_AUDIO_MODE:
174 mDelegate.setIsVoipAudioMode((String) msg.obj, msg.arg1 == 1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700175 break;
176 case MSG_SET_STATUS_HINTS: {
177 SomeArgs args = (SomeArgs) msg.obj;
178 try {
179 mDelegate.setStatusHints((String) args.arg1, (StatusHints) args.arg2);
180 } finally {
181 args.recycle();
182 }
183 break;
184 }
Andrew Lee100e2932014-09-08 15:34:24 -0700185 case MSG_SET_ADDRESS: {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700186 SomeArgs args = (SomeArgs) msg.obj;
187 try {
Andrew Lee100e2932014-09-08 15:34:24 -0700188 mDelegate.setAddress((String) args.arg1, (Uri) args.arg2, args.argi1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700189 } finally {
190 args.recycle();
191 }
192 break;
193 }
194 case MSG_SET_CALLER_DISPLAY_NAME: {
195 SomeArgs args = (SomeArgs) msg.obj;
196 try {
197 mDelegate.setCallerDisplayName(
198 (String) args.arg1, (String) args.arg2, args.argi1);
199 } finally {
200 args.recycle();
201 }
202 break;
203 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700204 case MSG_SET_CONFERENCEABLE_CONNECTIONS: {
205 SomeArgs args = (SomeArgs) msg.obj;
206 try {
207 mDelegate.setConferenceableConnections(
208 (String) args.arg1, (List<String>) args.arg2);
209 } finally {
210 args.recycle();
211 }
212 break;
213 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700214 case MSG_ADD_EXISTING_CONNECTION: {
215 SomeArgs args = (SomeArgs) msg.obj;
216 try {
217 mDelegate.addExistingConnection(
218 (String) args.arg1, (ParcelableConnection) args.arg2);
219 } finally {
220 args.recycle();
221 }
222 break;
223 }
Anthony Lee17455a32015-04-24 15:25:29 -0700224 case MSG_SET_CONFERENCE_MERGE_FAILED: {
225 SomeArgs args = (SomeArgs) msg.obj;
226 try {
227 mDelegate.setConferenceMergeFailed((String) args.arg1);
228 } finally {
229 args.recycle();
230 }
231 break;
232 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700233 }
234 }
235 };
236
237 private final IConnectionServiceAdapter mStub = new IConnectionServiceAdapter.Stub() {
238 @Override
Ihab Awad6107bab2014-08-18 09:23:25 -0700239 public void handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700240 String id,
241 ConnectionRequest request,
242 ParcelableConnection connection) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700243 SomeArgs args = SomeArgs.obtain();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700244 args.arg1 = id;
245 args.arg2 = request;
246 args.arg3 = connection;
Ihab Awad6107bab2014-08-18 09:23:25 -0700247 mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700248 }
249
250 @Override
251 public void setActive(String connectionId) {
252 mHandler.obtainMessage(MSG_SET_ACTIVE, connectionId).sendToTarget();
253 }
254
255 @Override
256 public void setRinging(String connectionId) {
257 mHandler.obtainMessage(MSG_SET_RINGING, connectionId).sendToTarget();
258 }
259
260 @Override
261 public void setDialing(String connectionId) {
262 mHandler.obtainMessage(MSG_SET_DIALING, connectionId).sendToTarget();
263 }
264
265 @Override
266 public void setDisconnected(
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700267 String connectionId, DisconnectCause disconnectCause) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700268 SomeArgs args = SomeArgs.obtain();
269 args.arg1 = connectionId;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700270 args.arg2 = disconnectCause;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700271 mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget();
272 }
273
274 @Override
275 public void setOnHold(String connectionId) {
276 mHandler.obtainMessage(MSG_SET_ON_HOLD, connectionId).sendToTarget();
277 }
278
279 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700280 public void setRingbackRequested(String connectionId, boolean ringback) {
281 mHandler.obtainMessage(MSG_SET_RINGBACK_REQUESTED, ringback ? 1 : 0, 0, connectionId)
Ihab Awad5d0410f2014-07-30 10:07:40 -0700282 .sendToTarget();
283 }
284
285 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800286 public void setConnectionCapabilities(String connectionId, int connectionCapabilities) {
287 mHandler.obtainMessage(
288 MSG_SET_CONNECTION_CAPABILITIES, connectionCapabilities, 0, connectionId)
Ihab Awad5d0410f2014-07-30 10:07:40 -0700289 .sendToTarget();
290 }
291
292 @Override
Anthony Lee17455a32015-04-24 15:25:29 -0700293 public void setConferenceMergeFailed(String callId) {
294 SomeArgs args = SomeArgs.obtain();
295 args.arg1 = callId;
296 mHandler.obtainMessage(MSG_SET_CONFERENCE_MERGE_FAILED, args).sendToTarget();
297 }
298
299 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700300 public void setIsConferenced(String callId, String conferenceCallId) {
301 SomeArgs args = SomeArgs.obtain();
302 args.arg1 = callId;
303 args.arg2 = conferenceCallId;
304 mHandler.obtainMessage(MSG_SET_IS_CONFERENCED, args).sendToTarget();
305 }
306
307 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -0700308 public void addConferenceCall(String callId, ParcelableConference parcelableConference) {
309 SomeArgs args = SomeArgs.obtain();
310 args.arg1 = callId;
311 args.arg2 = parcelableConference;
312 mHandler.obtainMessage(MSG_ADD_CONFERENCE_CALL, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700313 }
314
315 @Override
316 public void removeCall(String connectionId) {
317 mHandler.obtainMessage(MSG_REMOVE_CALL, connectionId).sendToTarget();
318 }
319
320 @Override
321 public void onPostDialWait(String connectionId, String remainingDigits) {
322 SomeArgs args = SomeArgs.obtain();
323 args.arg1 = connectionId;
324 args.arg2 = remainingDigits;
325 mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget();
326 }
327
328 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800329 public void onPostDialChar(String connectionId, char nextChar) {
330 SomeArgs args = SomeArgs.obtain();
331 args.arg1 = connectionId;
332 args.argi1 = nextChar;
333 mHandler.obtainMessage(MSG_ON_POST_DIAL_CHAR, args).sendToTarget();
334 }
335
336 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700337 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
338 mHandler.obtainMessage(MSG_QUERY_REMOTE_CALL_SERVICES, callback).sendToTarget();
339 }
340
341 @Override
342 public void setVideoState(String connectionId, int videoState) {
343 mHandler.obtainMessage(MSG_SET_VIDEO_STATE, videoState, 0, connectionId).sendToTarget();
344 }
345
346 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700347 public void setVideoProvider(String connectionId, IVideoProvider videoProvider) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700348 SomeArgs args = SomeArgs.obtain();
349 args.arg1 = connectionId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700350 args.arg2 = videoProvider;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700351 mHandler.obtainMessage(MSG_SET_VIDEO_CALL_PROVIDER, args).sendToTarget();
352 }
353
354 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700355 public final void setIsVoipAudioMode(String connectionId, boolean isVoip) {
356 mHandler.obtainMessage(MSG_SET_IS_VOIP_AUDIO_MODE, isVoip ? 1 : 0, 0,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700357 connectionId).sendToTarget();
358 }
359
360 @Override
361 public final void setStatusHints(String connectionId, StatusHints statusHints) {
362 SomeArgs args = SomeArgs.obtain();
363 args.arg1 = connectionId;
364 args.arg2 = statusHints;
365 mHandler.obtainMessage(MSG_SET_STATUS_HINTS, args).sendToTarget();
366 }
367
368 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700369 public final void setAddress(String connectionId, Uri address, int presentation) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700370 SomeArgs args = SomeArgs.obtain();
371 args.arg1 = connectionId;
Andrew Lee100e2932014-09-08 15:34:24 -0700372 args.arg2 = address;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700373 args.argi1 = presentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700374 mHandler.obtainMessage(MSG_SET_ADDRESS, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700375 }
376
377 @Override
378 public final void setCallerDisplayName(
379 String connectionId, String callerDisplayName, int presentation) {
380 SomeArgs args = SomeArgs.obtain();
381 args.arg1 = connectionId;
382 args.arg2 = callerDisplayName;
383 args.argi1 = presentation;
384 mHandler.obtainMessage(MSG_SET_CALLER_DISPLAY_NAME, args).sendToTarget();
385 }
386
387 @Override
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700388 public final void setConferenceableConnections(
389 String connectionId, List<String> conferenceableConnectionIds) {
390 SomeArgs args = SomeArgs.obtain();
391 args.arg1 = connectionId;
392 args.arg2 = conferenceableConnectionIds;
393 mHandler.obtainMessage(MSG_SET_CONFERENCEABLE_CONNECTIONS, args).sendToTarget();
394 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700395
396 @Override
397 public final void addExistingConnection(
398 String connectionId, ParcelableConnection connection) {
399 SomeArgs args = SomeArgs.obtain();
400 args.arg1 = connectionId;
401 args.arg2 = connection;
402 mHandler.obtainMessage(MSG_ADD_EXISTING_CONNECTION, args).sendToTarget();
403 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700404 };
405
406 public ConnectionServiceAdapterServant(IConnectionServiceAdapter delegate) {
407 mDelegate = delegate;
408 }
409
410 public IConnectionServiceAdapter getStub() {
411 return mStub;
412 }
413}