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 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 18 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 19 | import android.net.Uri; |
| 20 | import android.os.Handler; |
| 21 | import android.os.Message; |
| 22 | import android.os.RemoteException; |
| 23 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 24 | import com.android.internal.os.SomeArgs; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 25 | import com.android.internal.telecom.IConnectionServiceAdapter; |
| 26 | import com.android.internal.telecom.IVideoProvider; |
| 27 | import com.android.internal.telecom.RemoteServiceCallback; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 28 | |
| 29 | import java.util.List; |
| 30 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 31 | /** |
| 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 | */ |
| 39 | final class ConnectionServiceAdapterServant { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 40 | 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 Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 46 | private static final int MSG_SET_RINGBACK_REQUESTED = 7; |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 47 | 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 Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 55 | private static final int MSG_SET_IS_VOIP_AUDIO_MODE = 16; |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 56 | private static final int MSG_SET_STATUS_HINTS = 17; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 57 | private static final int MSG_SET_ADDRESS = 18; |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 58 | private static final int MSG_SET_CALLER_DISPLAY_NAME = 19; |
Evan Charlton | 23dc241 | 2014-09-03 10:07:03 -0700 | [diff] [blame] | 59 | private static final int MSG_SET_CONFERENCEABLE_CONNECTIONS = 20; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 60 | |
| 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 Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 75 | case MSG_HANDLE_CREATE_CONNECTION_COMPLETE: { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 76 | SomeArgs args = (SomeArgs) msg.obj; |
| 77 | try { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 78 | mDelegate.handleCreateConnectionComplete( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 79 | (String) args.arg1, |
| 80 | (ConnectionRequest) args.arg2, |
| 81 | (ParcelableConnection) args.arg3); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 82 | } finally { |
| 83 | args.recycle(); |
| 84 | } |
| 85 | break; |
| 86 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 87 | 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 Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 99 | mDelegate.setDisconnected((String) args.arg1, (DisconnectCause) args.arg2); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 100 | } finally { |
| 101 | args.recycle(); |
| 102 | } |
| 103 | break; |
| 104 | } |
| 105 | case MSG_SET_ON_HOLD: |
| 106 | mDelegate.setOnHold((String) msg.obj); |
| 107 | break; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 108 | case MSG_SET_RINGBACK_REQUESTED: |
| 109 | mDelegate.setRingbackRequested((String) msg.obj, msg.arg1 == 1); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 110 | 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 Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 123 | 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 Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 131 | break; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 132 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 133 | 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 Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 154 | mDelegate.setVideoProvider((String) args.arg1, |
| 155 | (IVideoProvider) args.arg2); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 156 | } finally { |
| 157 | args.recycle(); |
| 158 | } |
| 159 | break; |
| 160 | } |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 161 | case MSG_SET_IS_VOIP_AUDIO_MODE: |
| 162 | mDelegate.setIsVoipAudioMode((String) msg.obj, msg.arg1 == 1); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 163 | 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 Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 173 | case MSG_SET_ADDRESS: { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 174 | SomeArgs args = (SomeArgs) msg.obj; |
| 175 | try { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 176 | mDelegate.setAddress((String) args.arg1, (Uri) args.arg2, args.argi1); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 177 | } 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 Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 192 | 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 Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | }; |
| 205 | |
| 206 | private final IConnectionServiceAdapter mStub = new IConnectionServiceAdapter.Stub() { |
| 207 | @Override |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 208 | public void handleCreateConnectionComplete( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 209 | String id, |
| 210 | ConnectionRequest request, |
| 211 | ParcelableConnection connection) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 212 | SomeArgs args = SomeArgs.obtain(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 213 | args.arg1 = id; |
| 214 | args.arg2 = request; |
| 215 | args.arg3 = connection; |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 216 | mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_COMPLETE, args).sendToTarget(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 217 | } |
| 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 Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 236 | String connectionId, DisconnectCause disconnectCause) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 237 | SomeArgs args = SomeArgs.obtain(); |
| 238 | args.arg1 = connectionId; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 239 | args.arg2 = disconnectCause; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 240 | 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 Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 249 | public void setRingbackRequested(String connectionId, boolean ringback) { |
| 250 | mHandler.obtainMessage(MSG_SET_RINGBACK_REQUESTED, ringback ? 1 : 0, 0, connectionId) |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 251 | .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 Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 269 | 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 Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 274 | } |
| 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 Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 300 | public void setVideoProvider(String connectionId, IVideoProvider videoProvider) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 301 | SomeArgs args = SomeArgs.obtain(); |
| 302 | args.arg1 = connectionId; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 303 | args.arg2 = videoProvider; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 304 | mHandler.obtainMessage(MSG_SET_VIDEO_CALL_PROVIDER, args).sendToTarget(); |
| 305 | } |
| 306 | |
| 307 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 308 | public final void setIsVoipAudioMode(String connectionId, boolean isVoip) { |
| 309 | mHandler.obtainMessage(MSG_SET_IS_VOIP_AUDIO_MODE, isVoip ? 1 : 0, 0, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 310 | 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 Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 322 | public final void setAddress(String connectionId, Uri address, int presentation) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 323 | SomeArgs args = SomeArgs.obtain(); |
| 324 | args.arg1 = connectionId; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 325 | args.arg2 = address; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 326 | args.argi1 = presentation; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 327 | mHandler.obtainMessage(MSG_SET_ADDRESS, args).sendToTarget(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 328 | } |
| 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 Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 341 | 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 Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 348 | }; |
| 349 | |
| 350 | public ConnectionServiceAdapterServant(IConnectionServiceAdapter delegate) { |
| 351 | mDelegate = delegate; |
| 352 | } |
| 353 | |
| 354 | public IConnectionServiceAdapter getStub() { |
| 355 | return mStub; |
| 356 | } |
| 357 | } |