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 { |
| 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 Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 109 | case MSG_SET_RINGBACK_REQUESTED: |
| 110 | mDelegate.setRingbackRequested((String) msg.obj, msg.arg1 == 1); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 111 | 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 Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 124 | 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 Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 132 | break; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 133 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 134 | 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 Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 155 | mDelegate.setVideoProvider((String) args.arg1, |
| 156 | (IVideoProvider) args.arg2); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 157 | } finally { |
| 158 | args.recycle(); |
| 159 | } |
| 160 | break; |
| 161 | } |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 162 | case MSG_SET_IS_VOIP_AUDIO_MODE: |
| 163 | mDelegate.setIsVoipAudioMode((String) msg.obj, msg.arg1 == 1); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 164 | 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 Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 174 | case MSG_SET_ADDRESS: { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 175 | SomeArgs args = (SomeArgs) msg.obj; |
| 176 | try { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 177 | mDelegate.setAddress((String) args.arg1, (Uri) args.arg2, args.argi1); |
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_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 Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 193 | 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 Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | }; |
| 206 | |
| 207 | private final IConnectionServiceAdapter mStub = new IConnectionServiceAdapter.Stub() { |
| 208 | @Override |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 209 | public void handleCreateConnectionComplete( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 210 | String id, |
| 211 | ConnectionRequest request, |
| 212 | ParcelableConnection connection) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 213 | SomeArgs args = SomeArgs.obtain(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 214 | args.arg1 = id; |
| 215 | args.arg2 = request; |
| 216 | args.arg3 = connection; |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 217 | mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_COMPLETE, args).sendToTarget(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 218 | } |
| 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 Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 251 | public void setRingbackRequested(String connectionId, boolean ringback) { |
| 252 | mHandler.obtainMessage(MSG_SET_RINGBACK_REQUESTED, ringback ? 1 : 0, 0, connectionId) |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 253 | .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 Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 271 | 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 Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 276 | } |
| 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 Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 302 | public void setVideoProvider(String connectionId, IVideoProvider videoProvider) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 303 | SomeArgs args = SomeArgs.obtain(); |
| 304 | args.arg1 = connectionId; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 305 | args.arg2 = videoProvider; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 306 | mHandler.obtainMessage(MSG_SET_VIDEO_CALL_PROVIDER, args).sendToTarget(); |
| 307 | } |
| 308 | |
| 309 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 310 | public final void setIsVoipAudioMode(String connectionId, boolean isVoip) { |
| 311 | mHandler.obtainMessage(MSG_SET_IS_VOIP_AUDIO_MODE, isVoip ? 1 : 0, 0, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 312 | 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 Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 324 | public final void setAddress(String connectionId, Uri address, int presentation) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 325 | SomeArgs args = SomeArgs.obtain(); |
| 326 | args.arg1 = connectionId; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 327 | args.arg2 = address; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 328 | args.argi1 = presentation; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 329 | mHandler.obtainMessage(MSG_SET_ADDRESS, args).sendToTarget(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 330 | } |
| 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 Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 343 | 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 Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 350 | }; |
| 351 | |
| 352 | public ConnectionServiceAdapterServant(IConnectionServiceAdapter delegate) { |
| 353 | mDelegate = delegate; |
| 354 | } |
| 355 | |
| 356 | public IConnectionServiceAdapter getStub() { |
| 357 | return mStub; |
| 358 | } |
| 359 | } |