blob: 5f937893cfe9e28058e6b31c1786ced5d645c1de [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;
Rekha Kumar07366812015-03-24 16:42:31 -070062 private static final int MSG_SET_CALL_SUBSTATE = 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 }
Rekha Kumar07366812015-03-24 16:42:31 -0700224 case MSG_SET_CALL_SUBSTATE: {
225 mDelegate.setCallSubstate((String) msg.obj, msg.arg1);
226 break;
227 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700228 }
229 }
230 };
231
232 private final IConnectionServiceAdapter mStub = new IConnectionServiceAdapter.Stub() {
233 @Override
Ihab Awad6107bab2014-08-18 09:23:25 -0700234 public void handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700235 String id,
236 ConnectionRequest request,
237 ParcelableConnection connection) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700238 SomeArgs args = SomeArgs.obtain();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700239 args.arg1 = id;
240 args.arg2 = request;
241 args.arg3 = connection;
Ihab Awad6107bab2014-08-18 09:23:25 -0700242 mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700243 }
244
245 @Override
246 public void setActive(String connectionId) {
247 mHandler.obtainMessage(MSG_SET_ACTIVE, connectionId).sendToTarget();
248 }
249
250 @Override
251 public void setRinging(String connectionId) {
252 mHandler.obtainMessage(MSG_SET_RINGING, connectionId).sendToTarget();
253 }
254
255 @Override
256 public void setDialing(String connectionId) {
257 mHandler.obtainMessage(MSG_SET_DIALING, connectionId).sendToTarget();
258 }
259
260 @Override
261 public void setDisconnected(
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700262 String connectionId, DisconnectCause disconnectCause) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700263 SomeArgs args = SomeArgs.obtain();
264 args.arg1 = connectionId;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700265 args.arg2 = disconnectCause;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700266 mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget();
267 }
268
269 @Override
270 public void setOnHold(String connectionId) {
271 mHandler.obtainMessage(MSG_SET_ON_HOLD, connectionId).sendToTarget();
272 }
273
274 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700275 public void setRingbackRequested(String connectionId, boolean ringback) {
276 mHandler.obtainMessage(MSG_SET_RINGBACK_REQUESTED, ringback ? 1 : 0, 0, connectionId)
Ihab Awad5d0410f2014-07-30 10:07:40 -0700277 .sendToTarget();
278 }
279
280 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800281 public void setConnectionCapabilities(String connectionId, int connectionCapabilities) {
282 mHandler.obtainMessage(
283 MSG_SET_CONNECTION_CAPABILITIES, connectionCapabilities, 0, connectionId)
Ihab Awad5d0410f2014-07-30 10:07:40 -0700284 .sendToTarget();
285 }
286
287 @Override
288 public void setIsConferenced(String callId, String conferenceCallId) {
289 SomeArgs args = SomeArgs.obtain();
290 args.arg1 = callId;
291 args.arg2 = conferenceCallId;
292 mHandler.obtainMessage(MSG_SET_IS_CONFERENCED, args).sendToTarget();
293 }
294
295 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -0700296 public void addConferenceCall(String callId, ParcelableConference parcelableConference) {
297 SomeArgs args = SomeArgs.obtain();
298 args.arg1 = callId;
299 args.arg2 = parcelableConference;
300 mHandler.obtainMessage(MSG_ADD_CONFERENCE_CALL, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700301 }
302
303 @Override
304 public void removeCall(String connectionId) {
305 mHandler.obtainMessage(MSG_REMOVE_CALL, connectionId).sendToTarget();
306 }
307
308 @Override
309 public void onPostDialWait(String connectionId, String remainingDigits) {
310 SomeArgs args = SomeArgs.obtain();
311 args.arg1 = connectionId;
312 args.arg2 = remainingDigits;
313 mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget();
314 }
315
316 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800317 public void onPostDialChar(String connectionId, char nextChar) {
318 SomeArgs args = SomeArgs.obtain();
319 args.arg1 = connectionId;
320 args.argi1 = nextChar;
321 mHandler.obtainMessage(MSG_ON_POST_DIAL_CHAR, args).sendToTarget();
322 }
323
324 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700325 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
326 mHandler.obtainMessage(MSG_QUERY_REMOTE_CALL_SERVICES, callback).sendToTarget();
327 }
328
329 @Override
330 public void setVideoState(String connectionId, int videoState) {
331 mHandler.obtainMessage(MSG_SET_VIDEO_STATE, videoState, 0, connectionId).sendToTarget();
332 }
333
334 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700335 public void setVideoProvider(String connectionId, IVideoProvider videoProvider) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700336 SomeArgs args = SomeArgs.obtain();
337 args.arg1 = connectionId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700338 args.arg2 = videoProvider;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700339 mHandler.obtainMessage(MSG_SET_VIDEO_CALL_PROVIDER, args).sendToTarget();
340 }
341
342 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700343 public final void setIsVoipAudioMode(String connectionId, boolean isVoip) {
344 mHandler.obtainMessage(MSG_SET_IS_VOIP_AUDIO_MODE, isVoip ? 1 : 0, 0,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700345 connectionId).sendToTarget();
346 }
347
348 @Override
349 public final void setStatusHints(String connectionId, StatusHints statusHints) {
350 SomeArgs args = SomeArgs.obtain();
351 args.arg1 = connectionId;
352 args.arg2 = statusHints;
353 mHandler.obtainMessage(MSG_SET_STATUS_HINTS, args).sendToTarget();
354 }
355
356 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700357 public final void setAddress(String connectionId, Uri address, int presentation) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700358 SomeArgs args = SomeArgs.obtain();
359 args.arg1 = connectionId;
Andrew Lee100e2932014-09-08 15:34:24 -0700360 args.arg2 = address;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700361 args.argi1 = presentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700362 mHandler.obtainMessage(MSG_SET_ADDRESS, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700363 }
364
365 @Override
366 public final void setCallerDisplayName(
367 String connectionId, String callerDisplayName, int presentation) {
368 SomeArgs args = SomeArgs.obtain();
369 args.arg1 = connectionId;
370 args.arg2 = callerDisplayName;
371 args.argi1 = presentation;
372 mHandler.obtainMessage(MSG_SET_CALLER_DISPLAY_NAME, args).sendToTarget();
373 }
374
375 @Override
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700376 public final void setConferenceableConnections(
377 String connectionId, List<String> conferenceableConnectionIds) {
378 SomeArgs args = SomeArgs.obtain();
379 args.arg1 = connectionId;
380 args.arg2 = conferenceableConnectionIds;
381 mHandler.obtainMessage(MSG_SET_CONFERENCEABLE_CONNECTIONS, args).sendToTarget();
382 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700383
384 @Override
385 public final void addExistingConnection(
386 String connectionId, ParcelableConnection connection) {
387 SomeArgs args = SomeArgs.obtain();
388 args.arg1 = connectionId;
389 args.arg2 = connection;
390 mHandler.obtainMessage(MSG_ADD_EXISTING_CONNECTION, args).sendToTarget();
391 }
Rekha Kumar07366812015-03-24 16:42:31 -0700392
393 @Override
394 public void setCallSubstate(String connectionId, int callSubstate) {
395 mHandler.obtainMessage(MSG_SET_CALL_SUBSTATE, callSubstate, 0,
396 connectionId).sendToTarget();
397 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700398 };
399
400 public ConnectionServiceAdapterServant(IConnectionServiceAdapter delegate) {
401 mDelegate = delegate;
402 }
403
404 public IConnectionServiceAdapter getStub() {
405 return mStub;
406 }
407}