blob: a7909143e5f564267ef81dbe7248d7e09c5f9912 [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 }
243 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800244
245 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 }
252 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700253 }
254 }
255 };
256
257 private final IConnectionServiceAdapter mStub = new IConnectionServiceAdapter.Stub() {
258 @Override
Ihab Awad6107bab2014-08-18 09:23:25 -0700259 public void handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700260 String id,
261 ConnectionRequest request,
262 ParcelableConnection connection) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700263 SomeArgs args = SomeArgs.obtain();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700264 args.arg1 = id;
265 args.arg2 = request;
266 args.arg3 = connection;
Ihab Awad6107bab2014-08-18 09:23:25 -0700267 mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700268 }
269
270 @Override
271 public void setActive(String connectionId) {
272 mHandler.obtainMessage(MSG_SET_ACTIVE, connectionId).sendToTarget();
273 }
274
275 @Override
276 public void setRinging(String connectionId) {
277 mHandler.obtainMessage(MSG_SET_RINGING, connectionId).sendToTarget();
278 }
279
280 @Override
281 public void setDialing(String connectionId) {
282 mHandler.obtainMessage(MSG_SET_DIALING, connectionId).sendToTarget();
283 }
284
285 @Override
286 public void setDisconnected(
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700287 String connectionId, DisconnectCause disconnectCause) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700288 SomeArgs args = SomeArgs.obtain();
289 args.arg1 = connectionId;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700290 args.arg2 = disconnectCause;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700291 mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget();
292 }
293
294 @Override
295 public void setOnHold(String connectionId) {
296 mHandler.obtainMessage(MSG_SET_ON_HOLD, connectionId).sendToTarget();
297 }
298
299 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700300 public void setRingbackRequested(String connectionId, boolean ringback) {
301 mHandler.obtainMessage(MSG_SET_RINGBACK_REQUESTED, ringback ? 1 : 0, 0, connectionId)
Ihab Awad5d0410f2014-07-30 10:07:40 -0700302 .sendToTarget();
303 }
304
305 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800306 public void setConnectionCapabilities(String connectionId, int connectionCapabilities) {
307 mHandler.obtainMessage(
308 MSG_SET_CONNECTION_CAPABILITIES, connectionCapabilities, 0, connectionId)
Ihab Awad5d0410f2014-07-30 10:07:40 -0700309 .sendToTarget();
310 }
311
312 @Override
Anthony Lee17455a32015-04-24 15:25:29 -0700313 public void setConferenceMergeFailed(String callId) {
314 SomeArgs args = SomeArgs.obtain();
315 args.arg1 = callId;
316 mHandler.obtainMessage(MSG_SET_CONFERENCE_MERGE_FAILED, args).sendToTarget();
317 }
318
319 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700320 public void setIsConferenced(String callId, String conferenceCallId) {
321 SomeArgs args = SomeArgs.obtain();
322 args.arg1 = callId;
323 args.arg2 = conferenceCallId;
324 mHandler.obtainMessage(MSG_SET_IS_CONFERENCED, args).sendToTarget();
325 }
326
327 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -0700328 public void addConferenceCall(String callId, ParcelableConference parcelableConference) {
329 SomeArgs args = SomeArgs.obtain();
330 args.arg1 = callId;
331 args.arg2 = parcelableConference;
332 mHandler.obtainMessage(MSG_ADD_CONFERENCE_CALL, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700333 }
334
335 @Override
336 public void removeCall(String connectionId) {
337 mHandler.obtainMessage(MSG_REMOVE_CALL, connectionId).sendToTarget();
338 }
339
340 @Override
341 public void onPostDialWait(String connectionId, String remainingDigits) {
342 SomeArgs args = SomeArgs.obtain();
343 args.arg1 = connectionId;
344 args.arg2 = remainingDigits;
345 mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget();
346 }
347
348 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800349 public void onPostDialChar(String connectionId, char nextChar) {
350 SomeArgs args = SomeArgs.obtain();
351 args.arg1 = connectionId;
352 args.argi1 = nextChar;
353 mHandler.obtainMessage(MSG_ON_POST_DIAL_CHAR, args).sendToTarget();
354 }
355
356 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700357 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
358 mHandler.obtainMessage(MSG_QUERY_REMOTE_CALL_SERVICES, callback).sendToTarget();
359 }
360
361 @Override
362 public void setVideoState(String connectionId, int videoState) {
363 mHandler.obtainMessage(MSG_SET_VIDEO_STATE, videoState, 0, connectionId).sendToTarget();
364 }
365
366 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700367 public void setVideoProvider(String connectionId, IVideoProvider videoProvider) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700368 SomeArgs args = SomeArgs.obtain();
369 args.arg1 = connectionId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700370 args.arg2 = videoProvider;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700371 mHandler.obtainMessage(MSG_SET_VIDEO_CALL_PROVIDER, args).sendToTarget();
372 }
373
374 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700375 public final void setIsVoipAudioMode(String connectionId, boolean isVoip) {
376 mHandler.obtainMessage(MSG_SET_IS_VOIP_AUDIO_MODE, isVoip ? 1 : 0, 0,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700377 connectionId).sendToTarget();
378 }
379
380 @Override
381 public final void setStatusHints(String connectionId, StatusHints statusHints) {
382 SomeArgs args = SomeArgs.obtain();
383 args.arg1 = connectionId;
384 args.arg2 = statusHints;
385 mHandler.obtainMessage(MSG_SET_STATUS_HINTS, args).sendToTarget();
386 }
387
388 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700389 public final void setAddress(String connectionId, Uri address, int presentation) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700390 SomeArgs args = SomeArgs.obtain();
391 args.arg1 = connectionId;
Andrew Lee100e2932014-09-08 15:34:24 -0700392 args.arg2 = address;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700393 args.argi1 = presentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700394 mHandler.obtainMessage(MSG_SET_ADDRESS, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700395 }
396
397 @Override
398 public final void setCallerDisplayName(
399 String connectionId, String callerDisplayName, int presentation) {
400 SomeArgs args = SomeArgs.obtain();
401 args.arg1 = connectionId;
402 args.arg2 = callerDisplayName;
403 args.argi1 = presentation;
404 mHandler.obtainMessage(MSG_SET_CALLER_DISPLAY_NAME, args).sendToTarget();
405 }
406
407 @Override
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700408 public final void setConferenceableConnections(
409 String connectionId, List<String> conferenceableConnectionIds) {
410 SomeArgs args = SomeArgs.obtain();
411 args.arg1 = connectionId;
412 args.arg2 = conferenceableConnectionIds;
413 mHandler.obtainMessage(MSG_SET_CONFERENCEABLE_CONNECTIONS, args).sendToTarget();
414 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700415
416 @Override
417 public final void addExistingConnection(
418 String connectionId, ParcelableConnection connection) {
419 SomeArgs args = SomeArgs.obtain();
420 args.arg1 = connectionId;
421 args.arg2 = connection;
422 mHandler.obtainMessage(MSG_ADD_EXISTING_CONNECTION, args).sendToTarget();
423 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700424
425 @Override
426 public final void setExtras(String connectionId, Bundle extras) {
427 SomeArgs args = SomeArgs.obtain();
428 args.arg1 = connectionId;
429 args.arg2 = extras;
430 mHandler.obtainMessage(MSG_SET_EXTRAS, args).sendToTarget();
431 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800432
433 @Override
434 public final void onConnectionEvent(String connectionId, String event) {
435 SomeArgs args = SomeArgs.obtain();
436 args.arg1 = connectionId;
437 args.arg2 = event;
438 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
439 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700440 };
441
442 public ConnectionServiceAdapterServant(IConnectionServiceAdapter delegate) {
443 mDelegate = delegate;
444 }
445
446 public IConnectionServiceAdapter getStub() {
447 return mStub;
448 }
449}