blob: 217dbc3ac6f410c52a92c9a0fe4578be1ca4a854 [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 Awad6107bab2014-08-18 09:23:25 -070047 private static final int MSG_SET_CALL_CAPABILITIES = 8;
48 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;
Ihab Awad5d0410f2014-07-30 10:07:40 -070060
61 private final IConnectionServiceAdapter mDelegate;
62
63 private final Handler mHandler = new Handler() {
64 @Override
65 public void handleMessage(Message msg) {
66 try {
67 internalHandleMessage(msg);
68 } catch (RemoteException e) {
69 }
70 }
71
72 // Internal method defined to centralize handling of RemoteException
73 private void internalHandleMessage(Message msg) throws RemoteException {
74 switch (msg.what) {
Ihab Awad6107bab2014-08-18 09:23:25 -070075 case MSG_HANDLE_CREATE_CONNECTION_COMPLETE: {
Ihab Awad5d0410f2014-07-30 10:07:40 -070076 SomeArgs args = (SomeArgs) msg.obj;
77 try {
Ihab Awad6107bab2014-08-18 09:23:25 -070078 mDelegate.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -070079 (String) args.arg1,
80 (ConnectionRequest) args.arg2,
81 (ParcelableConnection) args.arg3);
Ihab Awad5d0410f2014-07-30 10:07:40 -070082 } finally {
83 args.recycle();
84 }
85 break;
86 }
Ihab Awad5d0410f2014-07-30 10:07:40 -070087 case MSG_SET_ACTIVE:
88 mDelegate.setActive((String) msg.obj);
89 break;
90 case MSG_SET_RINGING:
91 mDelegate.setRinging((String) msg.obj);
92 break;
93 case MSG_SET_DIALING:
94 mDelegate.setDialing((String) msg.obj);
95 break;
96 case MSG_SET_DISCONNECTED: {
97 SomeArgs args = (SomeArgs) msg.obj;
98 try {
Andrew Lee7f3d41f2014-09-11 17:33:16 -070099 mDelegate.setDisconnected((String) args.arg1, (DisconnectCause) args.arg2);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700100 } finally {
101 args.recycle();
102 }
103 break;
104 }
105 case MSG_SET_ON_HOLD:
106 mDelegate.setOnHold((String) msg.obj);
107 break;
Andrew Lee100e2932014-09-08 15:34:24 -0700108 case MSG_SET_RINGBACK_REQUESTED:
109 mDelegate.setRingbackRequested((String) msg.obj, msg.arg1 == 1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700110 break;
111 case MSG_SET_CALL_CAPABILITIES:
112 mDelegate.setCallCapabilities((String) msg.obj, msg.arg1);
113 break;
114 case MSG_SET_IS_CONFERENCED: {
115 SomeArgs args = (SomeArgs) msg.obj;
116 try {
117 mDelegate.setIsConferenced((String) args.arg1, (String) args.arg2);
118 } finally {
119 args.recycle();
120 }
121 break;
122 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700123 case MSG_ADD_CONFERENCE_CALL: {
124 SomeArgs args = (SomeArgs) msg.obj;
125 try {
126 mDelegate.addConferenceCall(
127 (String) args.arg1, (ParcelableConference) args.arg2);
128 } finally {
129 args.recycle();
130 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700131 break;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700132 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700133 case MSG_REMOVE_CALL:
134 mDelegate.removeCall((String) msg.obj);
135 break;
136 case MSG_ON_POST_DIAL_WAIT: {
137 SomeArgs args = (SomeArgs) msg.obj;
138 try {
139 mDelegate.onPostDialWait((String) args.arg1, (String) args.arg2);
140 } finally {
141 args.recycle();
142 }
143 break;
144 }
145 case MSG_QUERY_REMOTE_CALL_SERVICES:
146 mDelegate.queryRemoteConnectionServices((RemoteServiceCallback) msg.obj);
147 break;
148 case MSG_SET_VIDEO_STATE:
149 mDelegate.setVideoState((String) msg.obj, msg.arg1);
150 break;
151 case MSG_SET_VIDEO_CALL_PROVIDER: {
152 SomeArgs args = (SomeArgs) msg.obj;
153 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700154 mDelegate.setVideoProvider((String) args.arg1,
155 (IVideoProvider) args.arg2);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700156 } finally {
157 args.recycle();
158 }
159 break;
160 }
Andrew Lee100e2932014-09-08 15:34:24 -0700161 case MSG_SET_IS_VOIP_AUDIO_MODE:
162 mDelegate.setIsVoipAudioMode((String) msg.obj, msg.arg1 == 1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700163 break;
164 case MSG_SET_STATUS_HINTS: {
165 SomeArgs args = (SomeArgs) msg.obj;
166 try {
167 mDelegate.setStatusHints((String) args.arg1, (StatusHints) args.arg2);
168 } finally {
169 args.recycle();
170 }
171 break;
172 }
Andrew Lee100e2932014-09-08 15:34:24 -0700173 case MSG_SET_ADDRESS: {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700174 SomeArgs args = (SomeArgs) msg.obj;
175 try {
Andrew Lee100e2932014-09-08 15:34:24 -0700176 mDelegate.setAddress((String) args.arg1, (Uri) args.arg2, args.argi1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700177 } finally {
178 args.recycle();
179 }
180 break;
181 }
182 case MSG_SET_CALLER_DISPLAY_NAME: {
183 SomeArgs args = (SomeArgs) msg.obj;
184 try {
185 mDelegate.setCallerDisplayName(
186 (String) args.arg1, (String) args.arg2, args.argi1);
187 } finally {
188 args.recycle();
189 }
190 break;
191 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700192 case MSG_SET_CONFERENCEABLE_CONNECTIONS: {
193 SomeArgs args = (SomeArgs) msg.obj;
194 try {
195 mDelegate.setConferenceableConnections(
196 (String) args.arg1, (List<String>) args.arg2);
197 } finally {
198 args.recycle();
199 }
200 break;
201 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700202 }
203 }
204 };
205
206 private final IConnectionServiceAdapter mStub = new IConnectionServiceAdapter.Stub() {
207 @Override
Ihab Awad6107bab2014-08-18 09:23:25 -0700208 public void handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700209 String id,
210 ConnectionRequest request,
211 ParcelableConnection connection) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700212 SomeArgs args = SomeArgs.obtain();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700213 args.arg1 = id;
214 args.arg2 = request;
215 args.arg3 = connection;
Ihab Awad6107bab2014-08-18 09:23:25 -0700216 mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700217 }
218
219 @Override
220 public void setActive(String connectionId) {
221 mHandler.obtainMessage(MSG_SET_ACTIVE, connectionId).sendToTarget();
222 }
223
224 @Override
225 public void setRinging(String connectionId) {
226 mHandler.obtainMessage(MSG_SET_RINGING, connectionId).sendToTarget();
227 }
228
229 @Override
230 public void setDialing(String connectionId) {
231 mHandler.obtainMessage(MSG_SET_DIALING, connectionId).sendToTarget();
232 }
233
234 @Override
235 public void setDisconnected(
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700236 String connectionId, DisconnectCause disconnectCause) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700237 SomeArgs args = SomeArgs.obtain();
238 args.arg1 = connectionId;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700239 args.arg2 = disconnectCause;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700240 mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget();
241 }
242
243 @Override
244 public void setOnHold(String connectionId) {
245 mHandler.obtainMessage(MSG_SET_ON_HOLD, connectionId).sendToTarget();
246 }
247
248 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700249 public void setRingbackRequested(String connectionId, boolean ringback) {
250 mHandler.obtainMessage(MSG_SET_RINGBACK_REQUESTED, ringback ? 1 : 0, 0, connectionId)
Ihab Awad5d0410f2014-07-30 10:07:40 -0700251 .sendToTarget();
252 }
253
254 @Override
255 public void setCallCapabilities(String connectionId, int callCapabilities) {
256 mHandler.obtainMessage(MSG_SET_CALL_CAPABILITIES, callCapabilities, 0, connectionId)
257 .sendToTarget();
258 }
259
260 @Override
261 public void setIsConferenced(String callId, String conferenceCallId) {
262 SomeArgs args = SomeArgs.obtain();
263 args.arg1 = callId;
264 args.arg2 = conferenceCallId;
265 mHandler.obtainMessage(MSG_SET_IS_CONFERENCED, args).sendToTarget();
266 }
267
268 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -0700269 public void addConferenceCall(String callId, ParcelableConference parcelableConference) {
270 SomeArgs args = SomeArgs.obtain();
271 args.arg1 = callId;
272 args.arg2 = parcelableConference;
273 mHandler.obtainMessage(MSG_ADD_CONFERENCE_CALL, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700274 }
275
276 @Override
277 public void removeCall(String connectionId) {
278 mHandler.obtainMessage(MSG_REMOVE_CALL, connectionId).sendToTarget();
279 }
280
281 @Override
282 public void onPostDialWait(String connectionId, String remainingDigits) {
283 SomeArgs args = SomeArgs.obtain();
284 args.arg1 = connectionId;
285 args.arg2 = remainingDigits;
286 mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget();
287 }
288
289 @Override
290 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
291 mHandler.obtainMessage(MSG_QUERY_REMOTE_CALL_SERVICES, callback).sendToTarget();
292 }
293
294 @Override
295 public void setVideoState(String connectionId, int videoState) {
296 mHandler.obtainMessage(MSG_SET_VIDEO_STATE, videoState, 0, connectionId).sendToTarget();
297 }
298
299 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700300 public void setVideoProvider(String connectionId, IVideoProvider videoProvider) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700301 SomeArgs args = SomeArgs.obtain();
302 args.arg1 = connectionId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700303 args.arg2 = videoProvider;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700304 mHandler.obtainMessage(MSG_SET_VIDEO_CALL_PROVIDER, args).sendToTarget();
305 }
306
307 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700308 public final void setIsVoipAudioMode(String connectionId, boolean isVoip) {
309 mHandler.obtainMessage(MSG_SET_IS_VOIP_AUDIO_MODE, isVoip ? 1 : 0, 0,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700310 connectionId).sendToTarget();
311 }
312
313 @Override
314 public final void setStatusHints(String connectionId, StatusHints statusHints) {
315 SomeArgs args = SomeArgs.obtain();
316 args.arg1 = connectionId;
317 args.arg2 = statusHints;
318 mHandler.obtainMessage(MSG_SET_STATUS_HINTS, args).sendToTarget();
319 }
320
321 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700322 public final void setAddress(String connectionId, Uri address, int presentation) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700323 SomeArgs args = SomeArgs.obtain();
324 args.arg1 = connectionId;
Andrew Lee100e2932014-09-08 15:34:24 -0700325 args.arg2 = address;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700326 args.argi1 = presentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700327 mHandler.obtainMessage(MSG_SET_ADDRESS, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700328 }
329
330 @Override
331 public final void setCallerDisplayName(
332 String connectionId, String callerDisplayName, int presentation) {
333 SomeArgs args = SomeArgs.obtain();
334 args.arg1 = connectionId;
335 args.arg2 = callerDisplayName;
336 args.argi1 = presentation;
337 mHandler.obtainMessage(MSG_SET_CALLER_DISPLAY_NAME, args).sendToTarget();
338 }
339
340 @Override
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700341 public final void setConferenceableConnections(
342 String connectionId, List<String> conferenceableConnectionIds) {
343 SomeArgs args = SomeArgs.obtain();
344 args.arg1 = connectionId;
345 args.arg2 = conferenceableConnectionIds;
346 mHandler.obtainMessage(MSG_SET_CONFERENCEABLE_CONNECTIONS, args).sendToTarget();
347 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700348 };
349
350 public ConnectionServiceAdapterServant(IConnectionServiceAdapter delegate) {
351 mDelegate = delegate;
352 }
353
354 public IConnectionServiceAdapter getStub() {
355 return mStub;
356 }
357}