blob: 6a8c1cb281ba8f31e08fb3ea0c279aad1300b4c9 [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;
Santos Cordon6b7f9552015-05-27 17:21:45 -070020import android.os.Bundle;
Ihab Awad5d0410f2014-07-30 10:07:40 -070021import android.os.Handler;
22import android.os.Message;
23import android.os.RemoteException;
24
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070025import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070026import com.android.internal.telecom.IConnectionServiceAdapter;
27import com.android.internal.telecom.IVideoProvider;
28import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070029
30import java.util.List;
31
Ihab Awad5d0410f2014-07-30 10:07:40 -070032/**
33 * A component that provides an RPC servant implementation of {@link IConnectionServiceAdapter},
34 * posting incoming messages on the main thread on a client-supplied delegate object.
35 *
36 * TODO: Generate this and similar classes using a compiler starting from AIDL interfaces.
37 *
38 * @hide
39 */
40final class ConnectionServiceAdapterServant {
Ihab Awad6107bab2014-08-18 09:23:25 -070041 private static final int MSG_HANDLE_CREATE_CONNECTION_COMPLETE = 1;
42 private static final int MSG_SET_ACTIVE = 2;
43 private static final int MSG_SET_RINGING = 3;
44 private static final int MSG_SET_DIALING = 4;
45 private static final int MSG_SET_DISCONNECTED = 5;
46 private static final int MSG_SET_ON_HOLD = 6;
Andrew Lee100e2932014-09-08 15:34:24 -070047 private static final int MSG_SET_RINGBACK_REQUESTED = 7;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080048 private static final int MSG_SET_CONNECTION_CAPABILITIES = 8;
Ihab Awad6107bab2014-08-18 09:23:25 -070049 private static final int MSG_SET_IS_CONFERENCED = 9;
50 private static final int MSG_ADD_CONFERENCE_CALL = 10;
51 private static final int MSG_REMOVE_CALL = 11;
52 private static final int MSG_ON_POST_DIAL_WAIT = 12;
53 private static final int MSG_QUERY_REMOTE_CALL_SERVICES = 13;
54 private static final int MSG_SET_VIDEO_STATE = 14;
55 private static final int MSG_SET_VIDEO_CALL_PROVIDER = 15;
Andrew Lee100e2932014-09-08 15:34:24 -070056 private static final int MSG_SET_IS_VOIP_AUDIO_MODE = 16;
Ihab Awad6107bab2014-08-18 09:23:25 -070057 private static final int MSG_SET_STATUS_HINTS = 17;
Andrew Lee100e2932014-09-08 15:34:24 -070058 private static final int MSG_SET_ADDRESS = 18;
Ihab Awad6107bab2014-08-18 09:23:25 -070059 private static final int MSG_SET_CALLER_DISPLAY_NAME = 19;
Evan Charlton23dc2412014-09-03 10:07:03 -070060 private static final int MSG_SET_CONFERENCEABLE_CONNECTIONS = 20;
Tyler Gunn4a57b9b2014-10-30 14:27:48 -070061 private static final int MSG_ADD_EXISTING_CONNECTION = 21;
Nancy Chen27d1c2d2014-12-15 16:12:50 -080062 private static final int MSG_ON_POST_DIAL_CHAR = 22;
Anthony Lee17455a32015-04-24 15:25:29 -070063 private static final int MSG_SET_CONFERENCE_MERGE_FAILED = 23;
Santos Cordon6b7f9552015-05-27 17:21:45 -070064 private static final int MSG_SET_EXTRAS = 24;
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -080065 private static final int MSG_ON_CONNECTION_EVENT = 25;
Ihab Awad5d0410f2014-07-30 10:07:40 -070066
67 private final IConnectionServiceAdapter mDelegate;
68
69 private final Handler mHandler = new Handler() {
70 @Override
71 public void handleMessage(Message msg) {
72 try {
73 internalHandleMessage(msg);
74 } catch (RemoteException e) {
75 }
76 }
77
78 // Internal method defined to centralize handling of RemoteException
79 private void internalHandleMessage(Message msg) throws RemoteException {
80 switch (msg.what) {
Ihab Awad6107bab2014-08-18 09:23:25 -070081 case MSG_HANDLE_CREATE_CONNECTION_COMPLETE: {
Ihab Awad5d0410f2014-07-30 10:07:40 -070082 SomeArgs args = (SomeArgs) msg.obj;
83 try {
Ihab Awad6107bab2014-08-18 09:23:25 -070084 mDelegate.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -070085 (String) args.arg1,
86 (ConnectionRequest) args.arg2,
87 (ParcelableConnection) args.arg3);
Ihab Awad5d0410f2014-07-30 10:07:40 -070088 } finally {
89 args.recycle();
90 }
91 break;
92 }
Ihab Awad5d0410f2014-07-30 10:07:40 -070093 case MSG_SET_ACTIVE:
94 mDelegate.setActive((String) msg.obj);
95 break;
96 case MSG_SET_RINGING:
97 mDelegate.setRinging((String) msg.obj);
98 break;
99 case MSG_SET_DIALING:
100 mDelegate.setDialing((String) msg.obj);
101 break;
102 case MSG_SET_DISCONNECTED: {
103 SomeArgs args = (SomeArgs) msg.obj;
104 try {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700105 mDelegate.setDisconnected((String) args.arg1, (DisconnectCause) args.arg2);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700106 } finally {
107 args.recycle();
108 }
109 break;
110 }
111 case MSG_SET_ON_HOLD:
112 mDelegate.setOnHold((String) msg.obj);
113 break;
Andrew Lee100e2932014-09-08 15:34:24 -0700114 case MSG_SET_RINGBACK_REQUESTED:
115 mDelegate.setRingbackRequested((String) msg.obj, msg.arg1 == 1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700116 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800117 case MSG_SET_CONNECTION_CAPABILITIES:
118 mDelegate.setConnectionCapabilities((String) msg.obj, msg.arg1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700119 break;
120 case MSG_SET_IS_CONFERENCED: {
121 SomeArgs args = (SomeArgs) msg.obj;
122 try {
123 mDelegate.setIsConferenced((String) args.arg1, (String) args.arg2);
124 } finally {
125 args.recycle();
126 }
127 break;
128 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700129 case MSG_ADD_CONFERENCE_CALL: {
130 SomeArgs args = (SomeArgs) msg.obj;
131 try {
132 mDelegate.addConferenceCall(
133 (String) args.arg1, (ParcelableConference) args.arg2);
134 } finally {
135 args.recycle();
136 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700137 break;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700138 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700139 case MSG_REMOVE_CALL:
140 mDelegate.removeCall((String) msg.obj);
141 break;
142 case MSG_ON_POST_DIAL_WAIT: {
143 SomeArgs args = (SomeArgs) msg.obj;
144 try {
145 mDelegate.onPostDialWait((String) args.arg1, (String) args.arg2);
146 } finally {
147 args.recycle();
148 }
149 break;
150 }
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800151 case MSG_ON_POST_DIAL_CHAR: {
152 SomeArgs args = (SomeArgs) msg.obj;
153 try {
154 mDelegate.onPostDialChar((String) args.arg1, (char) args.argi1);
155 } finally {
156 args.recycle();
157 }
158 break;
159 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700160 case MSG_QUERY_REMOTE_CALL_SERVICES:
161 mDelegate.queryRemoteConnectionServices((RemoteServiceCallback) msg.obj);
162 break;
163 case MSG_SET_VIDEO_STATE:
164 mDelegate.setVideoState((String) msg.obj, msg.arg1);
165 break;
166 case MSG_SET_VIDEO_CALL_PROVIDER: {
167 SomeArgs args = (SomeArgs) msg.obj;
168 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700169 mDelegate.setVideoProvider((String) args.arg1,
170 (IVideoProvider) args.arg2);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700171 } finally {
172 args.recycle();
173 }
174 break;
175 }
Andrew Lee100e2932014-09-08 15:34:24 -0700176 case MSG_SET_IS_VOIP_AUDIO_MODE:
177 mDelegate.setIsVoipAudioMode((String) msg.obj, msg.arg1 == 1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700178 break;
179 case MSG_SET_STATUS_HINTS: {
180 SomeArgs args = (SomeArgs) msg.obj;
181 try {
182 mDelegate.setStatusHints((String) args.arg1, (StatusHints) args.arg2);
183 } finally {
184 args.recycle();
185 }
186 break;
187 }
Andrew Lee100e2932014-09-08 15:34:24 -0700188 case MSG_SET_ADDRESS: {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700189 SomeArgs args = (SomeArgs) msg.obj;
190 try {
Andrew Lee100e2932014-09-08 15:34:24 -0700191 mDelegate.setAddress((String) args.arg1, (Uri) args.arg2, args.argi1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700192 } finally {
193 args.recycle();
194 }
195 break;
196 }
197 case MSG_SET_CALLER_DISPLAY_NAME: {
198 SomeArgs args = (SomeArgs) msg.obj;
199 try {
200 mDelegate.setCallerDisplayName(
201 (String) args.arg1, (String) args.arg2, args.argi1);
202 } finally {
203 args.recycle();
204 }
205 break;
206 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700207 case MSG_SET_CONFERENCEABLE_CONNECTIONS: {
208 SomeArgs args = (SomeArgs) msg.obj;
209 try {
210 mDelegate.setConferenceableConnections(
211 (String) args.arg1, (List<String>) args.arg2);
212 } finally {
213 args.recycle();
214 }
215 break;
216 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700217 case MSG_ADD_EXISTING_CONNECTION: {
218 SomeArgs args = (SomeArgs) msg.obj;
219 try {
220 mDelegate.addExistingConnection(
221 (String) args.arg1, (ParcelableConnection) args.arg2);
222 } finally {
223 args.recycle();
224 }
225 break;
226 }
Anthony Lee17455a32015-04-24 15:25:29 -0700227 case MSG_SET_CONFERENCE_MERGE_FAILED: {
228 SomeArgs args = (SomeArgs) msg.obj;
229 try {
230 mDelegate.setConferenceMergeFailed((String) args.arg1);
231 } finally {
232 args.recycle();
233 }
234 break;
235 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700236 case MSG_SET_EXTRAS: {
237 SomeArgs args = (SomeArgs) msg.obj;
238 try {
239 mDelegate.setExtras((String) args.arg1, (Bundle) args.arg2);
240 } finally {
241 args.recycle();
242 }
Tyler Gunn86c9fb42016-02-24 13:17:21 -0800243 break;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700244 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800245 case MSG_ON_CONNECTION_EVENT: {
246 SomeArgs args = (SomeArgs) msg.obj;
247 try {
248 mDelegate.onConnectionEvent((String) args.arg1, (String) args.arg2);
249 } finally {
250 args.recycle();
251 }
Tyler Gunn86c9fb42016-02-24 13:17:21 -0800252 break;
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800253 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700254 }
255 }
256 };
257
258 private final IConnectionServiceAdapter mStub = new IConnectionServiceAdapter.Stub() {
259 @Override
Ihab Awad6107bab2014-08-18 09:23:25 -0700260 public void handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700261 String id,
262 ConnectionRequest request,
263 ParcelableConnection connection) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700264 SomeArgs args = SomeArgs.obtain();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700265 args.arg1 = id;
266 args.arg2 = request;
267 args.arg3 = connection;
Ihab Awad6107bab2014-08-18 09:23:25 -0700268 mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700269 }
270
271 @Override
272 public void setActive(String connectionId) {
273 mHandler.obtainMessage(MSG_SET_ACTIVE, connectionId).sendToTarget();
274 }
275
276 @Override
277 public void setRinging(String connectionId) {
278 mHandler.obtainMessage(MSG_SET_RINGING, connectionId).sendToTarget();
279 }
280
281 @Override
282 public void setDialing(String connectionId) {
283 mHandler.obtainMessage(MSG_SET_DIALING, connectionId).sendToTarget();
284 }
285
286 @Override
287 public void setDisconnected(
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700288 String connectionId, DisconnectCause disconnectCause) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700289 SomeArgs args = SomeArgs.obtain();
290 args.arg1 = connectionId;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700291 args.arg2 = disconnectCause;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700292 mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget();
293 }
294
295 @Override
296 public void setOnHold(String connectionId) {
297 mHandler.obtainMessage(MSG_SET_ON_HOLD, connectionId).sendToTarget();
298 }
299
300 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700301 public void setRingbackRequested(String connectionId, boolean ringback) {
302 mHandler.obtainMessage(MSG_SET_RINGBACK_REQUESTED, ringback ? 1 : 0, 0, connectionId)
Ihab Awad5d0410f2014-07-30 10:07:40 -0700303 .sendToTarget();
304 }
305
306 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800307 public void setConnectionCapabilities(String connectionId, int connectionCapabilities) {
308 mHandler.obtainMessage(
309 MSG_SET_CONNECTION_CAPABILITIES, connectionCapabilities, 0, connectionId)
Ihab Awad5d0410f2014-07-30 10:07:40 -0700310 .sendToTarget();
311 }
312
313 @Override
Anthony Lee17455a32015-04-24 15:25:29 -0700314 public void setConferenceMergeFailed(String callId) {
315 SomeArgs args = SomeArgs.obtain();
316 args.arg1 = callId;
317 mHandler.obtainMessage(MSG_SET_CONFERENCE_MERGE_FAILED, args).sendToTarget();
318 }
319
320 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700321 public void setIsConferenced(String callId, String conferenceCallId) {
322 SomeArgs args = SomeArgs.obtain();
323 args.arg1 = callId;
324 args.arg2 = conferenceCallId;
325 mHandler.obtainMessage(MSG_SET_IS_CONFERENCED, args).sendToTarget();
326 }
327
328 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -0700329 public void addConferenceCall(String callId, ParcelableConference parcelableConference) {
330 SomeArgs args = SomeArgs.obtain();
331 args.arg1 = callId;
332 args.arg2 = parcelableConference;
333 mHandler.obtainMessage(MSG_ADD_CONFERENCE_CALL, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700334 }
335
336 @Override
337 public void removeCall(String connectionId) {
338 mHandler.obtainMessage(MSG_REMOVE_CALL, connectionId).sendToTarget();
339 }
340
341 @Override
342 public void onPostDialWait(String connectionId, String remainingDigits) {
343 SomeArgs args = SomeArgs.obtain();
344 args.arg1 = connectionId;
345 args.arg2 = remainingDigits;
346 mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget();
347 }
348
349 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800350 public void onPostDialChar(String connectionId, char nextChar) {
351 SomeArgs args = SomeArgs.obtain();
352 args.arg1 = connectionId;
353 args.argi1 = nextChar;
354 mHandler.obtainMessage(MSG_ON_POST_DIAL_CHAR, args).sendToTarget();
355 }
356
357 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700358 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
359 mHandler.obtainMessage(MSG_QUERY_REMOTE_CALL_SERVICES, callback).sendToTarget();
360 }
361
362 @Override
363 public void setVideoState(String connectionId, int videoState) {
364 mHandler.obtainMessage(MSG_SET_VIDEO_STATE, videoState, 0, connectionId).sendToTarget();
365 }
366
367 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700368 public void setVideoProvider(String connectionId, IVideoProvider videoProvider) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700369 SomeArgs args = SomeArgs.obtain();
370 args.arg1 = connectionId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700371 args.arg2 = videoProvider;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700372 mHandler.obtainMessage(MSG_SET_VIDEO_CALL_PROVIDER, args).sendToTarget();
373 }
374
375 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700376 public final void setIsVoipAudioMode(String connectionId, boolean isVoip) {
377 mHandler.obtainMessage(MSG_SET_IS_VOIP_AUDIO_MODE, isVoip ? 1 : 0, 0,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700378 connectionId).sendToTarget();
379 }
380
381 @Override
382 public final void setStatusHints(String connectionId, StatusHints statusHints) {
383 SomeArgs args = SomeArgs.obtain();
384 args.arg1 = connectionId;
385 args.arg2 = statusHints;
386 mHandler.obtainMessage(MSG_SET_STATUS_HINTS, args).sendToTarget();
387 }
388
389 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700390 public final void setAddress(String connectionId, Uri address, int presentation) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700391 SomeArgs args = SomeArgs.obtain();
392 args.arg1 = connectionId;
Andrew Lee100e2932014-09-08 15:34:24 -0700393 args.arg2 = address;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700394 args.argi1 = presentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700395 mHandler.obtainMessage(MSG_SET_ADDRESS, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700396 }
397
398 @Override
399 public final void setCallerDisplayName(
400 String connectionId, String callerDisplayName, int presentation) {
401 SomeArgs args = SomeArgs.obtain();
402 args.arg1 = connectionId;
403 args.arg2 = callerDisplayName;
404 args.argi1 = presentation;
405 mHandler.obtainMessage(MSG_SET_CALLER_DISPLAY_NAME, args).sendToTarget();
406 }
407
408 @Override
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700409 public final void setConferenceableConnections(
410 String connectionId, List<String> conferenceableConnectionIds) {
411 SomeArgs args = SomeArgs.obtain();
412 args.arg1 = connectionId;
413 args.arg2 = conferenceableConnectionIds;
414 mHandler.obtainMessage(MSG_SET_CONFERENCEABLE_CONNECTIONS, args).sendToTarget();
415 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700416
417 @Override
418 public final void addExistingConnection(
419 String connectionId, ParcelableConnection connection) {
420 SomeArgs args = SomeArgs.obtain();
421 args.arg1 = connectionId;
422 args.arg2 = connection;
423 mHandler.obtainMessage(MSG_ADD_EXISTING_CONNECTION, args).sendToTarget();
424 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700425
426 @Override
427 public final void setExtras(String connectionId, Bundle extras) {
428 SomeArgs args = SomeArgs.obtain();
429 args.arg1 = connectionId;
430 args.arg2 = extras;
431 mHandler.obtainMessage(MSG_SET_EXTRAS, args).sendToTarget();
432 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800433
434 @Override
435 public final void onConnectionEvent(String connectionId, String event) {
436 SomeArgs args = SomeArgs.obtain();
437 args.arg1 = connectionId;
438 args.arg2 = event;
439 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
440 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700441 };
442
443 public ConnectionServiceAdapterServant(IConnectionServiceAdapter delegate) {
444 mDelegate = delegate;
445 }
446
447 public IConnectionServiceAdapter getStub() {
448 return mStub;
449 }
450}