Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.telecomm; |
| 18 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 19 | import android.app.PendingIntent; |
| 20 | import android.net.Uri; |
| 21 | import android.os.Handler; |
| 22 | import android.os.Message; |
| 23 | import android.os.RemoteException; |
| 24 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 25 | import com.android.internal.os.SomeArgs; |
| 26 | import com.android.internal.telecomm.IConnectionServiceAdapter; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame^] | 27 | import com.android.internal.telecomm.IVideoProvider; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 28 | import com.android.internal.telecomm.RemoteServiceCallback; |
| 29 | |
| 30 | import java.util.List; |
| 31 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 32 | /** |
| 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 | */ |
| 40 | final class ConnectionServiceAdapterServant { |
| 41 | private static final int MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL = 1; |
| 42 | private static final int MSG_HANDLE_CREATE_CONNECTION_FAILED = 2; |
| 43 | private static final int MSG_HANDLE_CREATE_CONNECTION_CANCELLED = 3; |
| 44 | private static final int MSG_SET_ACTIVE = 4; |
| 45 | private static final int MSG_SET_RINGING = 5; |
| 46 | private static final int MSG_SET_DIALING = 6; |
| 47 | private static final int MSG_SET_DISCONNECTED = 7; |
| 48 | private static final int MSG_SET_ON_HOLD = 8; |
| 49 | private static final int MSG_SET_REQUESTING_RINGBACK = 9; |
| 50 | private static final int MSG_SET_CALL_CAPABILITIES = 10; |
| 51 | private static final int MSG_SET_IS_CONFERENCED = 11; |
| 52 | private static final int MSG_ADD_CONFERENCE_CALL = 12; |
| 53 | private static final int MSG_REMOVE_CALL = 13; |
| 54 | private static final int MSG_ON_POST_DIAL_WAIT = 14; |
| 55 | private static final int MSG_QUERY_REMOTE_CALL_SERVICES = 15; |
| 56 | private static final int MSG_SET_VIDEO_STATE = 16; |
| 57 | private static final int MSG_SET_VIDEO_CALL_PROVIDER = 17; |
| 58 | private static final int MSG_SET_AUDIO_MODE_IS_VOIP = 18; |
| 59 | private static final int MSG_SET_STATUS_HINTS = 19; |
| 60 | private static final int MSG_SET_HANDLE = 20; |
| 61 | private static final int MSG_SET_CALLER_DISPLAY_NAME = 21; |
| 62 | private static final int MSG_START_ACTIVITY_FROM_IN_CALL = 22; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 63 | private static final int MSG_SET_CONFERENCEABLE_CONNECTIONS = 23; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 64 | |
| 65 | private final IConnectionServiceAdapter mDelegate; |
| 66 | |
| 67 | private final Handler mHandler = new Handler() { |
| 68 | @Override |
| 69 | public void handleMessage(Message msg) { |
| 70 | try { |
| 71 | internalHandleMessage(msg); |
| 72 | } catch (RemoteException e) { |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // Internal method defined to centralize handling of RemoteException |
| 77 | private void internalHandleMessage(Message msg) throws RemoteException { |
| 78 | switch (msg.what) { |
| 79 | case MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL: { |
| 80 | SomeArgs args = (SomeArgs) msg.obj; |
| 81 | try { |
| 82 | mDelegate.handleCreateConnectionSuccessful( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame^] | 83 | (String) args.arg1, |
| 84 | (ConnectionRequest) args.arg2, |
| 85 | (ParcelableConnection) args.arg3); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 86 | } finally { |
| 87 | args.recycle(); |
| 88 | } |
| 89 | break; |
| 90 | } |
| 91 | case MSG_HANDLE_CREATE_CONNECTION_FAILED: { |
| 92 | SomeArgs args = (SomeArgs) msg.obj; |
| 93 | try { |
| 94 | mDelegate.handleCreateConnectionFailed( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame^] | 95 | (String) args.arg1, |
| 96 | (ConnectionRequest) args.arg2, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 97 | args.argi1, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame^] | 98 | (String) args.arg3); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 99 | } finally { |
| 100 | args.recycle(); |
| 101 | } |
| 102 | break; |
| 103 | } |
| 104 | case MSG_HANDLE_CREATE_CONNECTION_CANCELLED: { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame^] | 105 | SomeArgs args = (SomeArgs) msg.obj; |
| 106 | try { |
| 107 | mDelegate.handleCreateConnectionCancelled( |
| 108 | (String) args.arg1, |
| 109 | (ConnectionRequest) args.arg2); |
| 110 | } finally { |
| 111 | args.recycle(); |
| 112 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 113 | break; |
| 114 | } |
| 115 | case MSG_SET_ACTIVE: |
| 116 | mDelegate.setActive((String) msg.obj); |
| 117 | break; |
| 118 | case MSG_SET_RINGING: |
| 119 | mDelegate.setRinging((String) msg.obj); |
| 120 | break; |
| 121 | case MSG_SET_DIALING: |
| 122 | mDelegate.setDialing((String) msg.obj); |
| 123 | break; |
| 124 | case MSG_SET_DISCONNECTED: { |
| 125 | SomeArgs args = (SomeArgs) msg.obj; |
| 126 | try { |
| 127 | mDelegate.setDisconnected( |
| 128 | (String) args.arg1, args.argi1, (String) args.arg2); |
| 129 | } finally { |
| 130 | args.recycle(); |
| 131 | } |
| 132 | break; |
| 133 | } |
| 134 | case MSG_SET_ON_HOLD: |
| 135 | mDelegate.setOnHold((String) msg.obj); |
| 136 | break; |
| 137 | case MSG_SET_REQUESTING_RINGBACK: |
| 138 | mDelegate.setRequestingRingback((String) msg.obj, msg.arg1 == 1); |
| 139 | break; |
| 140 | case MSG_SET_CALL_CAPABILITIES: |
| 141 | mDelegate.setCallCapabilities((String) msg.obj, msg.arg1); |
| 142 | break; |
| 143 | case MSG_SET_IS_CONFERENCED: { |
| 144 | SomeArgs args = (SomeArgs) msg.obj; |
| 145 | try { |
| 146 | mDelegate.setIsConferenced((String) args.arg1, (String) args.arg2); |
| 147 | } finally { |
| 148 | args.recycle(); |
| 149 | } |
| 150 | break; |
| 151 | } |
| 152 | case MSG_ADD_CONFERENCE_CALL: |
| 153 | mDelegate.addConferenceCall((String) msg.obj); |
| 154 | break; |
| 155 | case MSG_REMOVE_CALL: |
| 156 | mDelegate.removeCall((String) msg.obj); |
| 157 | break; |
| 158 | case MSG_ON_POST_DIAL_WAIT: { |
| 159 | SomeArgs args = (SomeArgs) msg.obj; |
| 160 | try { |
| 161 | mDelegate.onPostDialWait((String) args.arg1, (String) args.arg2); |
| 162 | } finally { |
| 163 | args.recycle(); |
| 164 | } |
| 165 | break; |
| 166 | } |
| 167 | case MSG_QUERY_REMOTE_CALL_SERVICES: |
| 168 | mDelegate.queryRemoteConnectionServices((RemoteServiceCallback) msg.obj); |
| 169 | break; |
| 170 | case MSG_SET_VIDEO_STATE: |
| 171 | mDelegate.setVideoState((String) msg.obj, msg.arg1); |
| 172 | break; |
| 173 | case MSG_SET_VIDEO_CALL_PROVIDER: { |
| 174 | SomeArgs args = (SomeArgs) msg.obj; |
| 175 | try { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame^] | 176 | mDelegate.setVideoProvider((String) args.arg1, |
| 177 | (IVideoProvider) args.arg2); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 178 | } finally { |
| 179 | args.recycle(); |
| 180 | } |
| 181 | break; |
| 182 | } |
| 183 | case MSG_SET_AUDIO_MODE_IS_VOIP: |
| 184 | mDelegate.setAudioModeIsVoip((String) msg.obj, msg.arg1 == 1); |
| 185 | break; |
| 186 | case MSG_SET_STATUS_HINTS: { |
| 187 | SomeArgs args = (SomeArgs) msg.obj; |
| 188 | try { |
| 189 | mDelegate.setStatusHints((String) args.arg1, (StatusHints) args.arg2); |
| 190 | } finally { |
| 191 | args.recycle(); |
| 192 | } |
| 193 | break; |
| 194 | } |
| 195 | case MSG_SET_HANDLE: { |
| 196 | SomeArgs args = (SomeArgs) msg.obj; |
| 197 | try { |
| 198 | mDelegate.setHandle((String) args.arg1, (Uri) args.arg2, args.argi1); |
| 199 | } finally { |
| 200 | args.recycle(); |
| 201 | } |
| 202 | break; |
| 203 | } |
| 204 | case MSG_SET_CALLER_DISPLAY_NAME: { |
| 205 | SomeArgs args = (SomeArgs) msg.obj; |
| 206 | try { |
| 207 | mDelegate.setCallerDisplayName( |
| 208 | (String) args.arg1, (String) args.arg2, args.argi1); |
| 209 | } finally { |
| 210 | args.recycle(); |
| 211 | } |
| 212 | break; |
| 213 | } |
| 214 | case MSG_START_ACTIVITY_FROM_IN_CALL: { |
| 215 | SomeArgs args = (SomeArgs) msg.obj; |
| 216 | try { |
| 217 | mDelegate.startActivityFromInCall( |
| 218 | (String) args.arg1, (PendingIntent) args.arg2); |
| 219 | } finally { |
| 220 | args.recycle(); |
| 221 | } |
| 222 | break; |
| 223 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 224 | case MSG_SET_CONFERENCEABLE_CONNECTIONS: { |
| 225 | SomeArgs args = (SomeArgs) msg.obj; |
| 226 | try { |
| 227 | mDelegate.setConferenceableConnections( |
| 228 | (String) args.arg1, (List<String>) args.arg2); |
| 229 | } finally { |
| 230 | args.recycle(); |
| 231 | } |
| 232 | break; |
| 233 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | }; |
| 237 | |
| 238 | private final IConnectionServiceAdapter mStub = new IConnectionServiceAdapter.Stub() { |
| 239 | @Override |
| 240 | public void handleCreateConnectionSuccessful( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame^] | 241 | String id, |
| 242 | ConnectionRequest request, |
| 243 | ParcelableConnection connection) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 244 | SomeArgs args = SomeArgs.obtain(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame^] | 245 | args.arg1 = id; |
| 246 | args.arg2 = request; |
| 247 | args.arg3 = connection; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 248 | mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL, args).sendToTarget(); |
| 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public void handleCreateConnectionFailed( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame^] | 253 | String id, |
| 254 | ConnectionRequest request, |
| 255 | int errorCode, |
| 256 | String errorMessage) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 257 | SomeArgs args = SomeArgs.obtain(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame^] | 258 | args.arg1 = id; |
| 259 | args.arg2 = request; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 260 | args.argi1 = errorCode; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame^] | 261 | args.arg3 = errorMessage; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 262 | mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_FAILED, args).sendToTarget(); |
| 263 | } |
| 264 | |
| 265 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame^] | 266 | public void handleCreateConnectionCancelled( |
| 267 | String id, |
| 268 | ConnectionRequest request) { |
| 269 | SomeArgs args = SomeArgs.obtain(); |
| 270 | args.arg1 = id; |
| 271 | args.arg2 = request; |
| 272 | mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_CANCELLED, args).sendToTarget(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public void setActive(String connectionId) { |
| 277 | mHandler.obtainMessage(MSG_SET_ACTIVE, connectionId).sendToTarget(); |
| 278 | } |
| 279 | |
| 280 | @Override |
| 281 | public void setRinging(String connectionId) { |
| 282 | mHandler.obtainMessage(MSG_SET_RINGING, connectionId).sendToTarget(); |
| 283 | } |
| 284 | |
| 285 | @Override |
| 286 | public void setDialing(String connectionId) { |
| 287 | mHandler.obtainMessage(MSG_SET_DIALING, connectionId).sendToTarget(); |
| 288 | } |
| 289 | |
| 290 | @Override |
| 291 | public void setDisconnected( |
| 292 | String connectionId, int disconnectCause, String disconnectMessage) { |
| 293 | SomeArgs args = SomeArgs.obtain(); |
| 294 | args.arg1 = connectionId; |
| 295 | args.arg2 = disconnectMessage; |
| 296 | args.argi1 = disconnectCause; |
| 297 | mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget(); |
| 298 | } |
| 299 | |
| 300 | @Override |
| 301 | public void setOnHold(String connectionId) { |
| 302 | mHandler.obtainMessage(MSG_SET_ON_HOLD, connectionId).sendToTarget(); |
| 303 | } |
| 304 | |
| 305 | @Override |
| 306 | public void setRequestingRingback(String connectionId, boolean ringback) { |
| 307 | mHandler.obtainMessage(MSG_SET_REQUESTING_RINGBACK, ringback ? 1 : 0, 0, connectionId) |
| 308 | .sendToTarget(); |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public void setCallCapabilities(String connectionId, int callCapabilities) { |
| 313 | mHandler.obtainMessage(MSG_SET_CALL_CAPABILITIES, callCapabilities, 0, connectionId) |
| 314 | .sendToTarget(); |
| 315 | } |
| 316 | |
| 317 | @Override |
| 318 | public void setIsConferenced(String callId, String conferenceCallId) { |
| 319 | SomeArgs args = SomeArgs.obtain(); |
| 320 | args.arg1 = callId; |
| 321 | args.arg2 = conferenceCallId; |
| 322 | mHandler.obtainMessage(MSG_SET_IS_CONFERENCED, args).sendToTarget(); |
| 323 | } |
| 324 | |
| 325 | @Override |
| 326 | public void addConferenceCall(String callId) { |
| 327 | mHandler.obtainMessage(MSG_ADD_CONFERENCE_CALL, callId).sendToTarget(); |
| 328 | } |
| 329 | |
| 330 | @Override |
| 331 | public void removeCall(String connectionId) { |
| 332 | mHandler.obtainMessage(MSG_REMOVE_CALL, connectionId).sendToTarget(); |
| 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public void onPostDialWait(String connectionId, String remainingDigits) { |
| 337 | SomeArgs args = SomeArgs.obtain(); |
| 338 | args.arg1 = connectionId; |
| 339 | args.arg2 = remainingDigits; |
| 340 | mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget(); |
| 341 | } |
| 342 | |
| 343 | @Override |
| 344 | public void queryRemoteConnectionServices(RemoteServiceCallback callback) { |
| 345 | mHandler.obtainMessage(MSG_QUERY_REMOTE_CALL_SERVICES, callback).sendToTarget(); |
| 346 | } |
| 347 | |
| 348 | @Override |
| 349 | public void setVideoState(String connectionId, int videoState) { |
| 350 | mHandler.obtainMessage(MSG_SET_VIDEO_STATE, videoState, 0, connectionId).sendToTarget(); |
| 351 | } |
| 352 | |
| 353 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame^] | 354 | public void setVideoProvider(String connectionId, IVideoProvider videoProvider) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 355 | SomeArgs args = SomeArgs.obtain(); |
| 356 | args.arg1 = connectionId; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame^] | 357 | args.arg2 = videoProvider; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 358 | mHandler.obtainMessage(MSG_SET_VIDEO_CALL_PROVIDER, args).sendToTarget(); |
| 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public final void setAudioModeIsVoip(String connectionId, boolean isVoip) { |
| 363 | mHandler.obtainMessage(MSG_SET_AUDIO_MODE_IS_VOIP, isVoip ? 1 : 0, 0, |
| 364 | connectionId).sendToTarget(); |
| 365 | } |
| 366 | |
| 367 | @Override |
| 368 | public final void setStatusHints(String connectionId, StatusHints statusHints) { |
| 369 | SomeArgs args = SomeArgs.obtain(); |
| 370 | args.arg1 = connectionId; |
| 371 | args.arg2 = statusHints; |
| 372 | mHandler.obtainMessage(MSG_SET_STATUS_HINTS, args).sendToTarget(); |
| 373 | } |
| 374 | |
| 375 | @Override |
| 376 | public final void setHandle(String connectionId, Uri handle, int presentation) { |
| 377 | SomeArgs args = SomeArgs.obtain(); |
| 378 | args.arg1 = connectionId; |
| 379 | args.arg2 = handle; |
| 380 | args.argi1 = presentation; |
| 381 | mHandler.obtainMessage(MSG_SET_HANDLE, args).sendToTarget(); |
| 382 | } |
| 383 | |
| 384 | @Override |
| 385 | public final void setCallerDisplayName( |
| 386 | String connectionId, String callerDisplayName, int presentation) { |
| 387 | SomeArgs args = SomeArgs.obtain(); |
| 388 | args.arg1 = connectionId; |
| 389 | args.arg2 = callerDisplayName; |
| 390 | args.argi1 = presentation; |
| 391 | mHandler.obtainMessage(MSG_SET_CALLER_DISPLAY_NAME, args).sendToTarget(); |
| 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public final void startActivityFromInCall(String connectionId, PendingIntent intent) { |
| 396 | SomeArgs args = SomeArgs.obtain(); |
| 397 | args.arg1 = connectionId; |
| 398 | args.arg2 = intent; |
| 399 | mHandler.obtainMessage(MSG_START_ACTIVITY_FROM_IN_CALL, args).sendToTarget(); |
| 400 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 401 | |
| 402 | @Override |
| 403 | public final void setConferenceableConnections( |
| 404 | String connectionId, List<String> conferenceableConnectionIds) { |
| 405 | SomeArgs args = SomeArgs.obtain(); |
| 406 | args.arg1 = connectionId; |
| 407 | args.arg2 = conferenceableConnectionIds; |
| 408 | mHandler.obtainMessage(MSG_SET_CONFERENCEABLE_CONNECTIONS, args).sendToTarget(); |
| 409 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 410 | }; |
| 411 | |
| 412 | public ConnectionServiceAdapterServant(IConnectionServiceAdapter delegate) { |
| 413 | mDelegate = delegate; |
| 414 | } |
| 415 | |
| 416 | public IConnectionServiceAdapter getStub() { |
| 417 | return mStub; |
| 418 | } |
| 419 | } |