blob: 0e1c516a042e8c76ca04a36c2b2d938c7307e20d [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
17package android.telecomm;
18
Ihab Awad5d0410f2014-07-30 10:07:40 -070019import android.app.PendingIntent;
20import android.net.Uri;
21import 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;
26import com.android.internal.telecomm.IConnectionServiceAdapter;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070027import com.android.internal.telecomm.IVideoProvider;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070028import com.android.internal.telecomm.RemoteServiceCallback;
29
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;
47 private static final int MSG_SET_REQUESTING_RINGBACK = 7;
48 private static final int MSG_SET_CALL_CAPABILITIES = 8;
49 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;
56 private static final int MSG_SET_AUDIO_MODE_IS_VOIP = 16;
57 private static final int MSG_SET_STATUS_HINTS = 17;
58 private static final int MSG_SET_HANDLE = 18;
59 private static final int MSG_SET_CALLER_DISPLAY_NAME = 19;
60 private static final int MSG_START_ACTIVITY_FROM_IN_CALL = 20;
61 private static final int MSG_SET_CONFERENCEABLE_CONNECTIONS = 21;
Ihab Awad5d0410f2014-07-30 10:07:40 -070062
63 private final IConnectionServiceAdapter mDelegate;
64
65 private final Handler mHandler = new Handler() {
66 @Override
67 public void handleMessage(Message msg) {
68 try {
69 internalHandleMessage(msg);
70 } catch (RemoteException e) {
71 }
72 }
73
74 // Internal method defined to centralize handling of RemoteException
75 private void internalHandleMessage(Message msg) throws RemoteException {
76 switch (msg.what) {
Ihab Awad6107bab2014-08-18 09:23:25 -070077 case MSG_HANDLE_CREATE_CONNECTION_COMPLETE: {
Ihab Awad5d0410f2014-07-30 10:07:40 -070078 SomeArgs args = (SomeArgs) msg.obj;
79 try {
Ihab Awad6107bab2014-08-18 09:23:25 -070080 mDelegate.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -070081 (String) args.arg1,
82 (ConnectionRequest) args.arg2,
83 (ParcelableConnection) args.arg3);
Ihab Awad5d0410f2014-07-30 10:07:40 -070084 } finally {
85 args.recycle();
86 }
87 break;
88 }
Ihab Awad5d0410f2014-07-30 10:07:40 -070089 case MSG_SET_ACTIVE:
90 mDelegate.setActive((String) msg.obj);
91 break;
92 case MSG_SET_RINGING:
93 mDelegate.setRinging((String) msg.obj);
94 break;
95 case MSG_SET_DIALING:
96 mDelegate.setDialing((String) msg.obj);
97 break;
98 case MSG_SET_DISCONNECTED: {
99 SomeArgs args = (SomeArgs) msg.obj;
100 try {
101 mDelegate.setDisconnected(
102 (String) args.arg1, args.argi1, (String) args.arg2);
103 } finally {
104 args.recycle();
105 }
106 break;
107 }
108 case MSG_SET_ON_HOLD:
109 mDelegate.setOnHold((String) msg.obj);
110 break;
111 case MSG_SET_REQUESTING_RINGBACK:
112 mDelegate.setRequestingRingback((String) msg.obj, msg.arg1 == 1);
113 break;
114 case MSG_SET_CALL_CAPABILITIES:
115 mDelegate.setCallCapabilities((String) msg.obj, msg.arg1);
116 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 }
148 case MSG_QUERY_REMOTE_CALL_SERVICES:
149 mDelegate.queryRemoteConnectionServices((RemoteServiceCallback) msg.obj);
150 break;
151 case MSG_SET_VIDEO_STATE:
152 mDelegate.setVideoState((String) msg.obj, msg.arg1);
153 break;
154 case MSG_SET_VIDEO_CALL_PROVIDER: {
155 SomeArgs args = (SomeArgs) msg.obj;
156 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700157 mDelegate.setVideoProvider((String) args.arg1,
158 (IVideoProvider) args.arg2);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700159 } finally {
160 args.recycle();
161 }
162 break;
163 }
164 case MSG_SET_AUDIO_MODE_IS_VOIP:
165 mDelegate.setAudioModeIsVoip((String) msg.obj, msg.arg1 == 1);
166 break;
167 case MSG_SET_STATUS_HINTS: {
168 SomeArgs args = (SomeArgs) msg.obj;
169 try {
170 mDelegate.setStatusHints((String) args.arg1, (StatusHints) args.arg2);
171 } finally {
172 args.recycle();
173 }
174 break;
175 }
176 case MSG_SET_HANDLE: {
177 SomeArgs args = (SomeArgs) msg.obj;
178 try {
179 mDelegate.setHandle((String) args.arg1, (Uri) args.arg2, args.argi1);
180 } finally {
181 args.recycle();
182 }
183 break;
184 }
185 case MSG_SET_CALLER_DISPLAY_NAME: {
186 SomeArgs args = (SomeArgs) msg.obj;
187 try {
188 mDelegate.setCallerDisplayName(
189 (String) args.arg1, (String) args.arg2, args.argi1);
190 } finally {
191 args.recycle();
192 }
193 break;
194 }
195 case MSG_START_ACTIVITY_FROM_IN_CALL: {
196 SomeArgs args = (SomeArgs) msg.obj;
197 try {
198 mDelegate.startActivityFromInCall(
199 (String) args.arg1, (PendingIntent) args.arg2);
200 } finally {
201 args.recycle();
202 }
203 break;
204 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700205 case MSG_SET_CONFERENCEABLE_CONNECTIONS: {
206 SomeArgs args = (SomeArgs) msg.obj;
207 try {
208 mDelegate.setConferenceableConnections(
209 (String) args.arg1, (List<String>) args.arg2);
210 } finally {
211 args.recycle();
212 }
213 break;
214 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700215 }
216 }
217 };
218
219 private final IConnectionServiceAdapter mStub = new IConnectionServiceAdapter.Stub() {
220 @Override
Ihab Awad6107bab2014-08-18 09:23:25 -0700221 public void handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700222 String id,
223 ConnectionRequest request,
224 ParcelableConnection connection) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700225 SomeArgs args = SomeArgs.obtain();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700226 args.arg1 = id;
227 args.arg2 = request;
228 args.arg3 = connection;
Ihab Awad6107bab2014-08-18 09:23:25 -0700229 mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700230 }
231
232 @Override
233 public void setActive(String connectionId) {
234 mHandler.obtainMessage(MSG_SET_ACTIVE, connectionId).sendToTarget();
235 }
236
237 @Override
238 public void setRinging(String connectionId) {
239 mHandler.obtainMessage(MSG_SET_RINGING, connectionId).sendToTarget();
240 }
241
242 @Override
243 public void setDialing(String connectionId) {
244 mHandler.obtainMessage(MSG_SET_DIALING, connectionId).sendToTarget();
245 }
246
247 @Override
248 public void setDisconnected(
249 String connectionId, int disconnectCause, String disconnectMessage) {
250 SomeArgs args = SomeArgs.obtain();
251 args.arg1 = connectionId;
252 args.arg2 = disconnectMessage;
253 args.argi1 = disconnectCause;
254 mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget();
255 }
256
257 @Override
258 public void setOnHold(String connectionId) {
259 mHandler.obtainMessage(MSG_SET_ON_HOLD, connectionId).sendToTarget();
260 }
261
262 @Override
263 public void setRequestingRingback(String connectionId, boolean ringback) {
264 mHandler.obtainMessage(MSG_SET_REQUESTING_RINGBACK, ringback ? 1 : 0, 0, connectionId)
265 .sendToTarget();
266 }
267
268 @Override
269 public void setCallCapabilities(String connectionId, int callCapabilities) {
270 mHandler.obtainMessage(MSG_SET_CALL_CAPABILITIES, callCapabilities, 0, connectionId)
271 .sendToTarget();
272 }
273
274 @Override
275 public void setIsConferenced(String callId, String conferenceCallId) {
276 SomeArgs args = SomeArgs.obtain();
277 args.arg1 = callId;
278 args.arg2 = conferenceCallId;
279 mHandler.obtainMessage(MSG_SET_IS_CONFERENCED, args).sendToTarget();
280 }
281
282 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -0700283 public void addConferenceCall(String callId, ParcelableConference parcelableConference) {
284 SomeArgs args = SomeArgs.obtain();
285 args.arg1 = callId;
286 args.arg2 = parcelableConference;
287 mHandler.obtainMessage(MSG_ADD_CONFERENCE_CALL, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700288 }
289
290 @Override
291 public void removeCall(String connectionId) {
292 mHandler.obtainMessage(MSG_REMOVE_CALL, connectionId).sendToTarget();
293 }
294
295 @Override
296 public void onPostDialWait(String connectionId, String remainingDigits) {
297 SomeArgs args = SomeArgs.obtain();
298 args.arg1 = connectionId;
299 args.arg2 = remainingDigits;
300 mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget();
301 }
302
303 @Override
304 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
305 mHandler.obtainMessage(MSG_QUERY_REMOTE_CALL_SERVICES, callback).sendToTarget();
306 }
307
308 @Override
309 public void setVideoState(String connectionId, int videoState) {
310 mHandler.obtainMessage(MSG_SET_VIDEO_STATE, videoState, 0, connectionId).sendToTarget();
311 }
312
313 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700314 public void setVideoProvider(String connectionId, IVideoProvider videoProvider) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700315 SomeArgs args = SomeArgs.obtain();
316 args.arg1 = connectionId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700317 args.arg2 = videoProvider;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700318 mHandler.obtainMessage(MSG_SET_VIDEO_CALL_PROVIDER, args).sendToTarget();
319 }
320
321 @Override
322 public final void setAudioModeIsVoip(String connectionId, boolean isVoip) {
323 mHandler.obtainMessage(MSG_SET_AUDIO_MODE_IS_VOIP, isVoip ? 1 : 0, 0,
324 connectionId).sendToTarget();
325 }
326
327 @Override
328 public final void setStatusHints(String connectionId, StatusHints statusHints) {
329 SomeArgs args = SomeArgs.obtain();
330 args.arg1 = connectionId;
331 args.arg2 = statusHints;
332 mHandler.obtainMessage(MSG_SET_STATUS_HINTS, args).sendToTarget();
333 }
334
335 @Override
336 public final void setHandle(String connectionId, Uri handle, int presentation) {
337 SomeArgs args = SomeArgs.obtain();
338 args.arg1 = connectionId;
339 args.arg2 = handle;
340 args.argi1 = presentation;
341 mHandler.obtainMessage(MSG_SET_HANDLE, args).sendToTarget();
342 }
343
344 @Override
345 public final void setCallerDisplayName(
346 String connectionId, String callerDisplayName, int presentation) {
347 SomeArgs args = SomeArgs.obtain();
348 args.arg1 = connectionId;
349 args.arg2 = callerDisplayName;
350 args.argi1 = presentation;
351 mHandler.obtainMessage(MSG_SET_CALLER_DISPLAY_NAME, args).sendToTarget();
352 }
353
354 @Override
355 public final void startActivityFromInCall(String connectionId, PendingIntent intent) {
356 SomeArgs args = SomeArgs.obtain();
357 args.arg1 = connectionId;
358 args.arg2 = intent;
359 mHandler.obtainMessage(MSG_START_ACTIVITY_FROM_IN_CALL, args).sendToTarget();
360 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700361
362 @Override
363 public final void setConferenceableConnections(
364 String connectionId, List<String> conferenceableConnectionIds) {
365 SomeArgs args = SomeArgs.obtain();
366 args.arg1 = connectionId;
367 args.arg2 = conferenceableConnectionIds;
368 mHandler.obtainMessage(MSG_SET_CONFERENCEABLE_CONNECTIONS, args).sendToTarget();
369 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700370 };
371
372 public ConnectionServiceAdapterServant(IConnectionServiceAdapter delegate) {
373 mDelegate = delegate;
374 }
375
376 public IConnectionServiceAdapter getStub() {
377 return mStub;
378 }
379}