blob: ffbbc8a653d8a693f5e883dec2694ccbfd40266a [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 {
99 mDelegate.setDisconnected(
100 (String) args.arg1, args.argi1, (String) args.arg2);
101 } finally {
102 args.recycle();
103 }
104 break;
105 }
106 case MSG_SET_ON_HOLD:
107 mDelegate.setOnHold((String) msg.obj);
108 break;
Andrew Lee100e2932014-09-08 15:34:24 -0700109 case MSG_SET_RINGBACK_REQUESTED:
110 mDelegate.setRingbackRequested((String) msg.obj, msg.arg1 == 1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700111 break;
112 case MSG_SET_CALL_CAPABILITIES:
113 mDelegate.setCallCapabilities((String) msg.obj, msg.arg1);
114 break;
115 case MSG_SET_IS_CONFERENCED: {
116 SomeArgs args = (SomeArgs) msg.obj;
117 try {
118 mDelegate.setIsConferenced((String) args.arg1, (String) args.arg2);
119 } finally {
120 args.recycle();
121 }
122 break;
123 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700124 case MSG_ADD_CONFERENCE_CALL: {
125 SomeArgs args = (SomeArgs) msg.obj;
126 try {
127 mDelegate.addConferenceCall(
128 (String) args.arg1, (ParcelableConference) args.arg2);
129 } finally {
130 args.recycle();
131 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700132 break;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700133 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700134 case MSG_REMOVE_CALL:
135 mDelegate.removeCall((String) msg.obj);
136 break;
137 case MSG_ON_POST_DIAL_WAIT: {
138 SomeArgs args = (SomeArgs) msg.obj;
139 try {
140 mDelegate.onPostDialWait((String) args.arg1, (String) args.arg2);
141 } finally {
142 args.recycle();
143 }
144 break;
145 }
146 case MSG_QUERY_REMOTE_CALL_SERVICES:
147 mDelegate.queryRemoteConnectionServices((RemoteServiceCallback) msg.obj);
148 break;
149 case MSG_SET_VIDEO_STATE:
150 mDelegate.setVideoState((String) msg.obj, msg.arg1);
151 break;
152 case MSG_SET_VIDEO_CALL_PROVIDER: {
153 SomeArgs args = (SomeArgs) msg.obj;
154 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700155 mDelegate.setVideoProvider((String) args.arg1,
156 (IVideoProvider) args.arg2);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700157 } finally {
158 args.recycle();
159 }
160 break;
161 }
Andrew Lee100e2932014-09-08 15:34:24 -0700162 case MSG_SET_IS_VOIP_AUDIO_MODE:
163 mDelegate.setIsVoipAudioMode((String) msg.obj, msg.arg1 == 1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700164 break;
165 case MSG_SET_STATUS_HINTS: {
166 SomeArgs args = (SomeArgs) msg.obj;
167 try {
168 mDelegate.setStatusHints((String) args.arg1, (StatusHints) args.arg2);
169 } finally {
170 args.recycle();
171 }
172 break;
173 }
Andrew Lee100e2932014-09-08 15:34:24 -0700174 case MSG_SET_ADDRESS: {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700175 SomeArgs args = (SomeArgs) msg.obj;
176 try {
Andrew Lee100e2932014-09-08 15:34:24 -0700177 mDelegate.setAddress((String) args.arg1, (Uri) args.arg2, args.argi1);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700178 } finally {
179 args.recycle();
180 }
181 break;
182 }
183 case MSG_SET_CALLER_DISPLAY_NAME: {
184 SomeArgs args = (SomeArgs) msg.obj;
185 try {
186 mDelegate.setCallerDisplayName(
187 (String) args.arg1, (String) args.arg2, args.argi1);
188 } finally {
189 args.recycle();
190 }
191 break;
192 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700193 case MSG_SET_CONFERENCEABLE_CONNECTIONS: {
194 SomeArgs args = (SomeArgs) msg.obj;
195 try {
196 mDelegate.setConferenceableConnections(
197 (String) args.arg1, (List<String>) args.arg2);
198 } finally {
199 args.recycle();
200 }
201 break;
202 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700203 }
204 }
205 };
206
207 private final IConnectionServiceAdapter mStub = new IConnectionServiceAdapter.Stub() {
208 @Override
Ihab Awad6107bab2014-08-18 09:23:25 -0700209 public void handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700210 String id,
211 ConnectionRequest request,
212 ParcelableConnection connection) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700213 SomeArgs args = SomeArgs.obtain();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700214 args.arg1 = id;
215 args.arg2 = request;
216 args.arg3 = connection;
Ihab Awad6107bab2014-08-18 09:23:25 -0700217 mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700218 }
219
220 @Override
221 public void setActive(String connectionId) {
222 mHandler.obtainMessage(MSG_SET_ACTIVE, connectionId).sendToTarget();
223 }
224
225 @Override
226 public void setRinging(String connectionId) {
227 mHandler.obtainMessage(MSG_SET_RINGING, connectionId).sendToTarget();
228 }
229
230 @Override
231 public void setDialing(String connectionId) {
232 mHandler.obtainMessage(MSG_SET_DIALING, connectionId).sendToTarget();
233 }
234
235 @Override
236 public void setDisconnected(
237 String connectionId, int disconnectCause, String disconnectMessage) {
238 SomeArgs args = SomeArgs.obtain();
239 args.arg1 = connectionId;
240 args.arg2 = disconnectMessage;
241 args.argi1 = disconnectCause;
242 mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget();
243 }
244
245 @Override
246 public void setOnHold(String connectionId) {
247 mHandler.obtainMessage(MSG_SET_ON_HOLD, connectionId).sendToTarget();
248 }
249
250 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700251 public void setRingbackRequested(String connectionId, boolean ringback) {
252 mHandler.obtainMessage(MSG_SET_RINGBACK_REQUESTED, ringback ? 1 : 0, 0, connectionId)
Ihab Awad5d0410f2014-07-30 10:07:40 -0700253 .sendToTarget();
254 }
255
256 @Override
257 public void setCallCapabilities(String connectionId, int callCapabilities) {
258 mHandler.obtainMessage(MSG_SET_CALL_CAPABILITIES, callCapabilities, 0, connectionId)
259 .sendToTarget();
260 }
261
262 @Override
263 public void setIsConferenced(String callId, String conferenceCallId) {
264 SomeArgs args = SomeArgs.obtain();
265 args.arg1 = callId;
266 args.arg2 = conferenceCallId;
267 mHandler.obtainMessage(MSG_SET_IS_CONFERENCED, args).sendToTarget();
268 }
269
270 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -0700271 public void addConferenceCall(String callId, ParcelableConference parcelableConference) {
272 SomeArgs args = SomeArgs.obtain();
273 args.arg1 = callId;
274 args.arg2 = parcelableConference;
275 mHandler.obtainMessage(MSG_ADD_CONFERENCE_CALL, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700276 }
277
278 @Override
279 public void removeCall(String connectionId) {
280 mHandler.obtainMessage(MSG_REMOVE_CALL, connectionId).sendToTarget();
281 }
282
283 @Override
284 public void onPostDialWait(String connectionId, String remainingDigits) {
285 SomeArgs args = SomeArgs.obtain();
286 args.arg1 = connectionId;
287 args.arg2 = remainingDigits;
288 mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget();
289 }
290
291 @Override
292 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
293 mHandler.obtainMessage(MSG_QUERY_REMOTE_CALL_SERVICES, callback).sendToTarget();
294 }
295
296 @Override
297 public void setVideoState(String connectionId, int videoState) {
298 mHandler.obtainMessage(MSG_SET_VIDEO_STATE, videoState, 0, connectionId).sendToTarget();
299 }
300
301 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700302 public void setVideoProvider(String connectionId, IVideoProvider videoProvider) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700303 SomeArgs args = SomeArgs.obtain();
304 args.arg1 = connectionId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700305 args.arg2 = videoProvider;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700306 mHandler.obtainMessage(MSG_SET_VIDEO_CALL_PROVIDER, args).sendToTarget();
307 }
308
309 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700310 public final void setIsVoipAudioMode(String connectionId, boolean isVoip) {
311 mHandler.obtainMessage(MSG_SET_IS_VOIP_AUDIO_MODE, isVoip ? 1 : 0, 0,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700312 connectionId).sendToTarget();
313 }
314
315 @Override
316 public final void setStatusHints(String connectionId, StatusHints statusHints) {
317 SomeArgs args = SomeArgs.obtain();
318 args.arg1 = connectionId;
319 args.arg2 = statusHints;
320 mHandler.obtainMessage(MSG_SET_STATUS_HINTS, args).sendToTarget();
321 }
322
323 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700324 public final void setAddress(String connectionId, Uri address, int presentation) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700325 SomeArgs args = SomeArgs.obtain();
326 args.arg1 = connectionId;
Andrew Lee100e2932014-09-08 15:34:24 -0700327 args.arg2 = address;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700328 args.argi1 = presentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700329 mHandler.obtainMessage(MSG_SET_ADDRESS, args).sendToTarget();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700330 }
331
332 @Override
333 public final void setCallerDisplayName(
334 String connectionId, String callerDisplayName, int presentation) {
335 SomeArgs args = SomeArgs.obtain();
336 args.arg1 = connectionId;
337 args.arg2 = callerDisplayName;
338 args.argi1 = presentation;
339 mHandler.obtainMessage(MSG_SET_CALLER_DISPLAY_NAME, args).sendToTarget();
340 }
341
342 @Override
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700343 public final void setConferenceableConnections(
344 String connectionId, List<String> conferenceableConnectionIds) {
345 SomeArgs args = SomeArgs.obtain();
346 args.arg1 = connectionId;
347 args.arg2 = conferenceableConnectionIds;
348 mHandler.obtainMessage(MSG_SET_CONFERENCEABLE_CONNECTIONS, args).sendToTarget();
349 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700350 };
351
352 public ConnectionServiceAdapterServant(IConnectionServiceAdapter delegate) {
353 mDelegate = delegate;
354 }
355
356 public IConnectionServiceAdapter getStub() {
357 return mStub;
358 }
359}