blob: 293dc1199923b038a5f29f67bdb7a221f28a0a41 [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;
Ihab Awad5d0410f2014-07-30 10:07:40 -070065
66 private final IConnectionServiceAdapter mDelegate;
67
68 private final Handler mHandler = new Handler() {
69 @Override
70 public void handleMessage(Message msg) {
71 try {
72 internalHandleMessage(msg);
73 } catch (RemoteException e) {
74 }
75 }
76
77 // Internal method defined to centralize handling of RemoteException
78 private void internalHandleMessage(Message msg) throws RemoteException {
79 switch (msg.what) {
Ihab Awad6107bab2014-08-18 09:23:25 -070080 case MSG_HANDLE_CREATE_CONNECTION_COMPLETE: {
Ihab Awad5d0410f2014-07-30 10:07:40 -070081 SomeArgs args = (SomeArgs) msg.obj;
82 try {
Ihab Awad6107bab2014-08-18 09:23:25 -070083 mDelegate.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -070084 (String) args.arg1,
85 (ConnectionRequest) args.arg2,
86 (ParcelableConnection) args.arg3);
Ihab Awad5d0410f2014-07-30 10:07:40 -070087 } finally {
88 args.recycle();
89 }
90 break;
91 }
Ihab Awad5d0410f2014-07-30 10:07:40 -070092 case MSG_SET_ACTIVE:
93 mDelegate.setActive((String) msg.obj);
94 break;
95 case MSG_SET_RINGING:
96 mDelegate.setRinging((String) msg.obj);
97 break;
98 case MSG_SET_DIALING:
99 mDelegate.setDialing((String) msg.obj);
100 break;
101 case MSG_SET_DISCONNECTED: {
102 SomeArgs args = (SomeArgs) msg.obj;
103 try {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700104 mDelegate.setDisconnected((String) args.arg1, (DisconnectCause) args.arg2);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700105 } finally {
106 args.recycle();
107 }
108 break;
109 }
110 case MSG_SET_ON_HOLD:
111 mDelegate.setOnHold((String) msg.obj);
112 break;
Andrew Lee100e2932014-09-08 15:34:24 -0700113 case MSG_SET_RINGBACK_REQUESTED:
114 mDelegate.setRingbackRequested((String) msg.obj, msg.arg1 == 1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700115 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800116 case MSG_SET_CONNECTION_CAPABILITIES:
117 mDelegate.setConnectionCapabilities((String) msg.obj, msg.arg1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700118 break;
119 case MSG_SET_IS_CONFERENCED: {
120 SomeArgs args = (SomeArgs) msg.obj;
121 try {
122 mDelegate.setIsConferenced((String) args.arg1, (String) args.arg2);
123 } finally {
124 args.recycle();
125 }
126 break;
127 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700128 case MSG_ADD_CONFERENCE_CALL: {
129 SomeArgs args = (SomeArgs) msg.obj;
130 try {
131 mDelegate.addConferenceCall(
132 (String) args.arg1, (ParcelableConference) args.arg2);
133 } finally {
134 args.recycle();
135 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700136 break;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700137 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700138 case MSG_REMOVE_CALL:
139 mDelegate.removeCall((String) msg.obj);
140 break;
141 case MSG_ON_POST_DIAL_WAIT: {
142 SomeArgs args = (SomeArgs) msg.obj;
143 try {
144 mDelegate.onPostDialWait((String) args.arg1, (String) args.arg2);
145 } finally {
146 args.recycle();
147 }
148 break;
149 }
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800150 case MSG_ON_POST_DIAL_CHAR: {
151 SomeArgs args = (SomeArgs) msg.obj;
152 try {
153 mDelegate.onPostDialChar((String) args.arg1, (char) args.argi1);
154 } finally {
155 args.recycle();
156 }
157 break;
158 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700159 case MSG_QUERY_REMOTE_CALL_SERVICES:
160 mDelegate.queryRemoteConnectionServices((RemoteServiceCallback) msg.obj);
161 break;
162 case MSG_SET_VIDEO_STATE:
163 mDelegate.setVideoState((String) msg.obj, msg.arg1);
164 break;
165 case MSG_SET_VIDEO_CALL_PROVIDER: {
166 SomeArgs args = (SomeArgs) msg.obj;
167 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700168 mDelegate.setVideoProvider((String) args.arg1,
169 (IVideoProvider) args.arg2);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700170 } finally {
171 args.recycle();
172 }
173 break;
174 }
Andrew Lee100e2932014-09-08 15:34:24 -0700175 case MSG_SET_IS_VOIP_AUDIO_MODE:
176 mDelegate.setIsVoipAudioMode((String) msg.obj, msg.arg1 == 1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700177 break;
178 case MSG_SET_STATUS_HINTS: {
179 SomeArgs args = (SomeArgs) msg.obj;
180 try {
181 mDelegate.setStatusHints((String) args.arg1, (StatusHints) args.arg2);
182 } finally {
183 args.recycle();
184 }
185 break;
186 }
Andrew Lee100e2932014-09-08 15:34:24 -0700187 case MSG_SET_ADDRESS: {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700188 SomeArgs args = (SomeArgs) msg.obj;
189 try {
Andrew Lee100e2932014-09-08 15:34:24 -0700190 mDelegate.setAddress((String) args.arg1, (Uri) args.arg2, args.argi1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700191 } finally {
192 args.recycle();
193 }
194 break;
195 }
196 case MSG_SET_CALLER_DISPLAY_NAME: {
197 SomeArgs args = (SomeArgs) msg.obj;
198 try {
199 mDelegate.setCallerDisplayName(
200 (String) args.arg1, (String) args.arg2, args.argi1);
201 } finally {
202 args.recycle();
203 }
204 break;
205 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700206 case MSG_SET_CONFERENCEABLE_CONNECTIONS: {
207 SomeArgs args = (SomeArgs) msg.obj;
208 try {
209 mDelegate.setConferenceableConnections(
210 (String) args.arg1, (List<String>) args.arg2);
211 } finally {
212 args.recycle();
213 }
214 break;
215 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700216 case MSG_ADD_EXISTING_CONNECTION: {
217 SomeArgs args = (SomeArgs) msg.obj;
218 try {
219 mDelegate.addExistingConnection(
220 (String) args.arg1, (ParcelableConnection) args.arg2);
221 } finally {
222 args.recycle();
223 }
224 break;
225 }
Anthony Lee17455a32015-04-24 15:25:29 -0700226 case MSG_SET_CONFERENCE_MERGE_FAILED: {
227 SomeArgs args = (SomeArgs) msg.obj;
228 try {
229 mDelegate.setConferenceMergeFailed((String) args.arg1);
230 } finally {
231 args.recycle();
232 }
233 break;
234 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700235 case MSG_SET_EXTRAS: {
236 SomeArgs args = (SomeArgs) msg.obj;
237 try {
238 mDelegate.setExtras((String) args.arg1, (Bundle) args.arg2);
239 } finally {
240 args.recycle();
241 }
242 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700243 }
244 }
245 };
246
247 private final IConnectionServiceAdapter mStub = new IConnectionServiceAdapter.Stub() {
248 @Override
Ihab Awad6107bab2014-08-18 09:23:25 -0700249 public void handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700250 String id,
251 ConnectionRequest request,
252 ParcelableConnection connection) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700253 SomeArgs args = SomeArgs.obtain();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700254 args.arg1 = id;
255 args.arg2 = request;
256 args.arg3 = connection;
Ihab Awad6107bab2014-08-18 09:23:25 -0700257 mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700258 }
259
260 @Override
261 public void setActive(String connectionId) {
262 mHandler.obtainMessage(MSG_SET_ACTIVE, connectionId).sendToTarget();
263 }
264
265 @Override
266 public void setRinging(String connectionId) {
267 mHandler.obtainMessage(MSG_SET_RINGING, connectionId).sendToTarget();
268 }
269
270 @Override
271 public void setDialing(String connectionId) {
272 mHandler.obtainMessage(MSG_SET_DIALING, connectionId).sendToTarget();
273 }
274
275 @Override
276 public void setDisconnected(
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700277 String connectionId, DisconnectCause disconnectCause) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700278 SomeArgs args = SomeArgs.obtain();
279 args.arg1 = connectionId;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700280 args.arg2 = disconnectCause;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700281 mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget();
282 }
283
284 @Override
285 public void setOnHold(String connectionId) {
286 mHandler.obtainMessage(MSG_SET_ON_HOLD, connectionId).sendToTarget();
287 }
288
289 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700290 public void setRingbackRequested(String connectionId, boolean ringback) {
291 mHandler.obtainMessage(MSG_SET_RINGBACK_REQUESTED, ringback ? 1 : 0, 0, connectionId)
Ihab Awad5d0410f2014-07-30 10:07:40 -0700292 .sendToTarget();
293 }
294
295 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800296 public void setConnectionCapabilities(String connectionId, int connectionCapabilities) {
297 mHandler.obtainMessage(
298 MSG_SET_CONNECTION_CAPABILITIES, connectionCapabilities, 0, connectionId)
Ihab Awad5d0410f2014-07-30 10:07:40 -0700299 .sendToTarget();
300 }
301
302 @Override
Anthony Lee17455a32015-04-24 15:25:29 -0700303 public void setConferenceMergeFailed(String callId) {
304 SomeArgs args = SomeArgs.obtain();
305 args.arg1 = callId;
306 mHandler.obtainMessage(MSG_SET_CONFERENCE_MERGE_FAILED, args).sendToTarget();
307 }
308
309 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700310 public void setIsConferenced(String callId, String conferenceCallId) {
311 SomeArgs args = SomeArgs.obtain();
312 args.arg1 = callId;
313 args.arg2 = conferenceCallId;
314 mHandler.obtainMessage(MSG_SET_IS_CONFERENCED, args).sendToTarget();
315 }
316
317 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -0700318 public void addConferenceCall(String callId, ParcelableConference parcelableConference) {
319 SomeArgs args = SomeArgs.obtain();
320 args.arg1 = callId;
321 args.arg2 = parcelableConference;
322 mHandler.obtainMessage(MSG_ADD_CONFERENCE_CALL, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700323 }
324
325 @Override
326 public void removeCall(String connectionId) {
327 mHandler.obtainMessage(MSG_REMOVE_CALL, connectionId).sendToTarget();
328 }
329
330 @Override
331 public void onPostDialWait(String connectionId, String remainingDigits) {
332 SomeArgs args = SomeArgs.obtain();
333 args.arg1 = connectionId;
334 args.arg2 = remainingDigits;
335 mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget();
336 }
337
338 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800339 public void onPostDialChar(String connectionId, char nextChar) {
340 SomeArgs args = SomeArgs.obtain();
341 args.arg1 = connectionId;
342 args.argi1 = nextChar;
343 mHandler.obtainMessage(MSG_ON_POST_DIAL_CHAR, args).sendToTarget();
344 }
345
346 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700347 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
348 mHandler.obtainMessage(MSG_QUERY_REMOTE_CALL_SERVICES, callback).sendToTarget();
349 }
350
351 @Override
352 public void setVideoState(String connectionId, int videoState) {
353 mHandler.obtainMessage(MSG_SET_VIDEO_STATE, videoState, 0, connectionId).sendToTarget();
354 }
355
356 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700357 public void setVideoProvider(String connectionId, IVideoProvider videoProvider) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700358 SomeArgs args = SomeArgs.obtain();
359 args.arg1 = connectionId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700360 args.arg2 = videoProvider;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700361 mHandler.obtainMessage(MSG_SET_VIDEO_CALL_PROVIDER, args).sendToTarget();
362 }
363
364 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700365 public final void setIsVoipAudioMode(String connectionId, boolean isVoip) {
366 mHandler.obtainMessage(MSG_SET_IS_VOIP_AUDIO_MODE, isVoip ? 1 : 0, 0,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700367 connectionId).sendToTarget();
368 }
369
370 @Override
371 public final void setStatusHints(String connectionId, StatusHints statusHints) {
372 SomeArgs args = SomeArgs.obtain();
373 args.arg1 = connectionId;
374 args.arg2 = statusHints;
375 mHandler.obtainMessage(MSG_SET_STATUS_HINTS, args).sendToTarget();
376 }
377
378 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700379 public final void setAddress(String connectionId, Uri address, int presentation) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700380 SomeArgs args = SomeArgs.obtain();
381 args.arg1 = connectionId;
Andrew Lee100e2932014-09-08 15:34:24 -0700382 args.arg2 = address;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700383 args.argi1 = presentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700384 mHandler.obtainMessage(MSG_SET_ADDRESS, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700385 }
386
387 @Override
388 public final void setCallerDisplayName(
389 String connectionId, String callerDisplayName, int presentation) {
390 SomeArgs args = SomeArgs.obtain();
391 args.arg1 = connectionId;
392 args.arg2 = callerDisplayName;
393 args.argi1 = presentation;
394 mHandler.obtainMessage(MSG_SET_CALLER_DISPLAY_NAME, args).sendToTarget();
395 }
396
397 @Override
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700398 public final void setConferenceableConnections(
399 String connectionId, List<String> conferenceableConnectionIds) {
400 SomeArgs args = SomeArgs.obtain();
401 args.arg1 = connectionId;
402 args.arg2 = conferenceableConnectionIds;
403 mHandler.obtainMessage(MSG_SET_CONFERENCEABLE_CONNECTIONS, args).sendToTarget();
404 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700405
406 @Override
407 public final void addExistingConnection(
408 String connectionId, ParcelableConnection connection) {
409 SomeArgs args = SomeArgs.obtain();
410 args.arg1 = connectionId;
411 args.arg2 = connection;
412 mHandler.obtainMessage(MSG_ADD_EXISTING_CONNECTION, args).sendToTarget();
413 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700414
415 @Override
416 public final void setExtras(String connectionId, Bundle extras) {
417 SomeArgs args = SomeArgs.obtain();
418 args.arg1 = connectionId;
419 args.arg2 = extras;
420 mHandler.obtainMessage(MSG_SET_EXTRAS, args).sendToTarget();
421 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700422 };
423
424 public ConnectionServiceAdapterServant(IConnectionServiceAdapter delegate) {
425 mDelegate = delegate;
426 }
427
428 public IConnectionServiceAdapter getStub() {
429 return mStub;
430 }
431}