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.telecom;
18 
19 import android.net.Uri;
20 import android.os.Bundle;
21 import android.os.Handler;
22 import android.os.Message;
23 import android.os.RemoteException;
24 import android.telecom.Logging.Session;
25 
26 import com.android.internal.os.SomeArgs;
27 import com.android.internal.telecom.IConnectionServiceAdapter;
28 import com.android.internal.telecom.IVideoProvider;
29 import com.android.internal.telecom.RemoteServiceCallback;
30 
31 import java.util.List;
32 
33 /**
34  * A component that provides an RPC servant implementation of {@link IConnectionServiceAdapter},
35  * posting incoming messages on the main thread on a client-supplied delegate object.
36  *
37  * TODO: Generate this and similar classes using a compiler starting from AIDL interfaces.
38  *
39  * @hide
40  */
41 final class ConnectionServiceAdapterServant {
42     private static final int MSG_HANDLE_CREATE_CONNECTION_COMPLETE = 1;
43     private static final int MSG_SET_ACTIVE = 2;
44     private static final int MSG_SET_RINGING = 3;
45     private static final int MSG_SET_DIALING = 4;
46     private static final int MSG_SET_DISCONNECTED = 5;
47     private static final int MSG_SET_ON_HOLD = 6;
48     private static final int MSG_SET_RINGBACK_REQUESTED = 7;
49     private static final int MSG_SET_CONNECTION_CAPABILITIES = 8;
50     private static final int MSG_SET_IS_CONFERENCED = 9;
51     private static final int MSG_ADD_CONFERENCE_CALL = 10;
52     private static final int MSG_REMOVE_CALL = 11;
53     private static final int MSG_ON_POST_DIAL_WAIT = 12;
54     private static final int MSG_QUERY_REMOTE_CALL_SERVICES = 13;
55     private static final int MSG_SET_VIDEO_STATE = 14;
56     private static final int MSG_SET_VIDEO_CALL_PROVIDER = 15;
57     private static final int MSG_SET_IS_VOIP_AUDIO_MODE = 16;
58     private static final int MSG_SET_STATUS_HINTS = 17;
59     private static final int MSG_SET_ADDRESS = 18;
60     private static final int MSG_SET_CALLER_DISPLAY_NAME = 19;
61     private static final int MSG_SET_CONFERENCEABLE_CONNECTIONS = 20;
62     private static final int MSG_ADD_EXISTING_CONNECTION = 21;
63     private static final int MSG_ON_POST_DIAL_CHAR = 22;
64     private static final int MSG_SET_CONFERENCE_MERGE_FAILED = 23;
65     private static final int MSG_PUT_EXTRAS = 24;
66     private static final int MSG_REMOVE_EXTRAS = 25;
67     private static final int MSG_ON_CONNECTION_EVENT = 26;
68     private static final int MSG_SET_CONNECTION_PROPERTIES = 27;
69     private static final int MSG_SET_PULLING = 28;
70     private static final int MSG_SET_AUDIO_ROUTE = 29;
71     private static final int MSG_ON_RTT_INITIATION_SUCCESS = 30;
72     private static final int MSG_ON_RTT_INITIATION_FAILURE = 31;
73     private static final int MSG_ON_RTT_REMOTELY_TERMINATED = 32;
74     private static final int MSG_ON_RTT_UPGRADE_REQUEST = 33;
75     private static final int MSG_SET_PHONE_ACCOUNT_CHANGED = 34;
76     private static final int MSG_CONNECTION_SERVICE_FOCUS_RELEASED = 35;
77     private static final int MSG_SET_CONFERENCE_STATE = 36;
78     private static final int MSG_HANDLE_CREATE_CONFERENCE_COMPLETE = 37;
79     private static final int MSG_SET_CALL_DIRECTION = 38;
80 
81     private final IConnectionServiceAdapter mDelegate;
82 
83     private final Handler mHandler = new Handler() {
84         @Override
85         public void handleMessage(Message msg) {
86             try {
87                 internalHandleMessage(msg);
88             } catch (RemoteException e) {
89             }
90         }
91 
92         // Internal method defined to centralize handling of RemoteException
93         private void internalHandleMessage(Message msg) throws RemoteException {
94             switch (msg.what) {
95                 case MSG_HANDLE_CREATE_CONNECTION_COMPLETE: {
96                     SomeArgs args = (SomeArgs) msg.obj;
97                     try {
98                         mDelegate.handleCreateConnectionComplete(
99                                 (String) args.arg1,
100                                 (ConnectionRequest) args.arg2,
101                                 (ParcelableConnection) args.arg3,
102                                 null /*Session.Info*/);
103                     } finally {
104                         args.recycle();
105                     }
106                     break;
107                 }
108                 case MSG_HANDLE_CREATE_CONFERENCE_COMPLETE: {
109                     SomeArgs args = (SomeArgs) msg.obj;
110                     try {
111                         mDelegate.handleCreateConferenceComplete(
112                                 (String) args.arg1,
113                                 (ConnectionRequest) args.arg2,
114                                 (ParcelableConference) args.arg3,
115                                 null /*Session.Info*/);
116                     } finally {
117                         args.recycle();
118                     }
119                     break;
120                 }
121                 case MSG_SET_ACTIVE:
122                     mDelegate.setActive((String) msg.obj, null /*Session.Info*/);
123                     break;
124                 case MSG_SET_RINGING:
125                     mDelegate.setRinging((String) msg.obj, null /*Session.Info*/);
126                     break;
127                 case MSG_SET_DIALING:
128                     mDelegate.setDialing((String) msg.obj, null /*Session.Info*/);
129                     break;
130                 case MSG_SET_PULLING:
131                     mDelegate.setPulling((String) msg.obj, null /*Session.Info*/);
132                     break;
133                 case MSG_SET_DISCONNECTED: {
134                     SomeArgs args = (SomeArgs) msg.obj;
135                     try {
136                         mDelegate.setDisconnected((String) args.arg1, (DisconnectCause) args.arg2,
137                                 null /*Session.Info*/);
138                     } finally {
139                         args.recycle();
140                     }
141                     break;
142                 }
143                 case MSG_SET_ON_HOLD:
144                     mDelegate.setOnHold((String) msg.obj, null /*Session.Info*/);
145                     break;
146                 case MSG_SET_RINGBACK_REQUESTED:
147                     mDelegate.setRingbackRequested((String) msg.obj, msg.arg1 == 1,
148                             null /*Session.Info*/);
149                     break;
150                 case MSG_SET_CONNECTION_CAPABILITIES:
151                     mDelegate.setConnectionCapabilities((String) msg.obj, msg.arg1,
152                             null /*Session.Info*/);
153                     break;
154                 case MSG_SET_CONNECTION_PROPERTIES:
155                     mDelegate.setConnectionProperties((String) msg.obj, msg.arg1,
156                             null /*Session.Info*/);
157                     break;
158                 case MSG_SET_IS_CONFERENCED: {
159                     SomeArgs args = (SomeArgs) msg.obj;
160                     try {
161                         mDelegate.setIsConferenced((String) args.arg1, (String) args.arg2,
162                                 null /*Session.Info*/);
163                     } finally {
164                         args.recycle();
165                     }
166                     break;
167                 }
168                 case MSG_ADD_CONFERENCE_CALL: {
169                     SomeArgs args = (SomeArgs) msg.obj;
170                     try {
171                         mDelegate.addConferenceCall(
172                                 (String) args.arg1, (ParcelableConference) args.arg2,
173                                 null /*Session.Info*/);
174                     } finally {
175                         args.recycle();
176                     }
177                     break;
178                 }
179                 case MSG_REMOVE_CALL:
180                     mDelegate.removeCall((String) msg.obj,
181                             null /*Session.Info*/);
182                     break;
183                 case MSG_ON_POST_DIAL_WAIT: {
184                     SomeArgs args = (SomeArgs) msg.obj;
185                     try {
186                         mDelegate.onPostDialWait((String) args.arg1, (String) args.arg2,
187                                 null /*Session.Info*/);
188                     } finally {
189                         args.recycle();
190                     }
191                     break;
192                 }
193                 case MSG_ON_POST_DIAL_CHAR: {
194                     SomeArgs args = (SomeArgs) msg.obj;
195                     try {
196                         mDelegate.onPostDialChar((String) args.arg1, (char) args.argi1,
197                                 null /*Session.Info*/);
198                     } finally {
199                         args.recycle();
200                     }
201                     break;
202                 }
203                 case MSG_QUERY_REMOTE_CALL_SERVICES:
204                     SomeArgs args2 = (SomeArgs) msg.obj;
205                     try {
206                         mDelegate.queryRemoteConnectionServices((RemoteServiceCallback) args2.arg1,
207                                 (String) args2.arg2, null /*Session.Info*/);
208                     } finally {
209                         args2.recycle();
210                     }
211                     break;
212                 case MSG_SET_VIDEO_STATE:
213                     mDelegate.setVideoState((String) msg.obj, msg.arg1, null /*Session.Info*/);
214                     break;
215                 case MSG_SET_VIDEO_CALL_PROVIDER: {
216                     SomeArgs args = (SomeArgs) msg.obj;
217                     try {
218                         mDelegate.setVideoProvider((String) args.arg1,
219                                 (IVideoProvider) args.arg2, null /*Session.Info*/);
220                     } finally {
221                         args.recycle();
222                     }
223                     break;
224                 }
225                 case MSG_SET_IS_VOIP_AUDIO_MODE:
226                     mDelegate.setIsVoipAudioMode((String) msg.obj, msg.arg1 == 1,
227                             null /*Session.Info*/);
228                     break;
229                 case MSG_SET_STATUS_HINTS: {
230                     SomeArgs args = (SomeArgs) msg.obj;
231                     try {
232                         mDelegate.setStatusHints((String) args.arg1, (StatusHints) args.arg2,
233                                 null /*Session.Info*/);
234                     } finally {
235                         args.recycle();
236                     }
237                     break;
238                 }
239                 case MSG_SET_ADDRESS: {
240                     SomeArgs args = (SomeArgs) msg.obj;
241                     try {
242                         mDelegate.setAddress((String) args.arg1, (Uri) args.arg2, args.argi1,
243                                 null /*Session.Info*/);
244                     } finally {
245                         args.recycle();
246                     }
247                     break;
248                 }
249                 case MSG_SET_CALLER_DISPLAY_NAME: {
250                     SomeArgs args = (SomeArgs) msg.obj;
251                     try {
252                         mDelegate.setCallerDisplayName(
253                                 (String) args.arg1, (String) args.arg2, args.argi1,
254                                 null /*Session.Info*/);
255                     } finally {
256                         args.recycle();
257                     }
258                     break;
259                 }
260                 case MSG_SET_CONFERENCEABLE_CONNECTIONS: {
261                     SomeArgs args = (SomeArgs) msg.obj;
262                     try {
263                         mDelegate.setConferenceableConnections((String) args.arg1,
264                                 (List<String>) args.arg2, null /*Session.Info*/);
265                     } finally {
266                         args.recycle();
267                     }
268                     break;
269                 }
270                 case MSG_ADD_EXISTING_CONNECTION: {
271                     SomeArgs args = (SomeArgs) msg.obj;
272                     try {
273                         mDelegate.addExistingConnection((String) args.arg1,
274                                 (ParcelableConnection) args.arg2, null /*Session.Info*/);
275                     } finally {
276                         args.recycle();
277                     }
278                     break;
279                 }
280                 case MSG_SET_CONFERENCE_MERGE_FAILED: {
281                     SomeArgs args = (SomeArgs) msg.obj;
282                     try {
283                         mDelegate.setConferenceMergeFailed((String) args.arg1,
284                                 null /*Session.Info*/);
285                     } finally {
286                         args.recycle();
287                     }
288                     break;
289                 }
290                 case MSG_PUT_EXTRAS: {
291                     SomeArgs args = (SomeArgs) msg.obj;
292                     try {
293                         mDelegate.putExtras((String) args.arg1, (Bundle) args.arg2,
294                                 null /*Session.Info*/);
295                     } finally {
296                         args.recycle();
297                     }
298                     break;
299                 }
300                 case MSG_REMOVE_EXTRAS: {
301                     SomeArgs args = (SomeArgs) msg.obj;
302                     try {
303                         mDelegate.removeExtras((String) args.arg1, (List<String>) args.arg2,
304                                 null /*Session.Info*/);
305                     } finally {
306                         args.recycle();
307                     }
308                     break;
309                 }
310                 case MSG_ON_CONNECTION_EVENT: {
311                     SomeArgs args = (SomeArgs) msg.obj;
312                     try {
313                         mDelegate.onConnectionEvent((String) args.arg1, (String) args.arg2,
314                                 (Bundle) args.arg3, null /*Session.Info*/);
315                     } finally {
316                         args.recycle();
317                     }
318                     break;
319                 }
320                 case MSG_SET_AUDIO_ROUTE: {
321                     SomeArgs args = (SomeArgs) msg.obj;
322                     try {
323                         mDelegate.setAudioRoute((String) args.arg1, args.argi1, (String) args.arg2,
324                                 (Session.Info) args.arg3);
325                     } finally {
326                         args.recycle();
327                     }
328                     break;
329                 }
330                 case MSG_ON_RTT_INITIATION_SUCCESS:
331                     mDelegate.onRttInitiationSuccess((String) msg.obj, null /*Session.Info*/);
332                     break;
333                 case MSG_ON_RTT_INITIATION_FAILURE:
334                     mDelegate.onRttInitiationFailure((String) msg.obj, msg.arg1,
335                             null /*Session.Info*/);
336                     break;
337                 case MSG_ON_RTT_REMOTELY_TERMINATED:
338                     mDelegate.onRttSessionRemotelyTerminated((String) msg.obj,
339                             null /*Session.Info*/);
340                     break;
341                 case MSG_ON_RTT_UPGRADE_REQUEST:
342                     mDelegate.onRemoteRttRequest((String) msg.obj, null /*Session.Info*/);
343                     break;
344                 case MSG_SET_PHONE_ACCOUNT_CHANGED: {
345                     SomeArgs args = (SomeArgs) msg.obj;
346                     try {
347                         mDelegate.onPhoneAccountChanged((String) args.arg1,
348                                 (PhoneAccountHandle) args.arg2, null /*Session.Info*/);
349                     } finally {
350                         args.recycle();
351                     }
352                     break;
353                 }
354                 case MSG_CONNECTION_SERVICE_FOCUS_RELEASED:
355                     mDelegate.onConnectionServiceFocusReleased(null /*Session.Info*/);
356                     break;
357                 case MSG_SET_CONFERENCE_STATE: {
358                     SomeArgs args = (SomeArgs) msg.obj;
359                     try {
360                         mDelegate.setConferenceState((String) args.arg1, (Boolean) args.arg2,
361                                 (Session.Info) args.arg3);
362                     } finally {
363                         args.recycle();
364                     }
365                     break;
366                 }
367                 case MSG_SET_CALL_DIRECTION: {
368                     SomeArgs args = (SomeArgs) msg.obj;
369                     try {
370                         mDelegate.setCallDirection((String) args.arg1, args.argi1,
371                                 (Session.Info) args.arg2);
372                     } finally {
373                         args.recycle();
374                     }
375                 }
376             }
377         }
378     };
379 
380     private final IConnectionServiceAdapter mStub = new IConnectionServiceAdapter.Stub() {
381         @Override
382         public void handleCreateConnectionComplete(
383                 String id,
384                 ConnectionRequest request,
385                 ParcelableConnection connection,
386                 Session.Info sessionInfo) {
387             SomeArgs args = SomeArgs.obtain();
388             args.arg1 = id;
389             args.arg2 = request;
390             args.arg3 = connection;
391             mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
392         }
393 
394         @Override
395         public void handleCreateConferenceComplete(
396                 String id,
397                 ConnectionRequest request,
398                 ParcelableConference conference,
399                 Session.Info sessionInfo) {
400             SomeArgs args = SomeArgs.obtain();
401             args.arg1 = id;
402             args.arg2 = request;
403             args.arg3 = conference;
404             mHandler.obtainMessage(MSG_HANDLE_CREATE_CONFERENCE_COMPLETE, args).sendToTarget();
405         }
406 
407 
408         @Override
409         public void setActive(String connectionId, Session.Info sessionInfo) {
410             mHandler.obtainMessage(MSG_SET_ACTIVE, connectionId).sendToTarget();
411         }
412 
413         @Override
414         public void setRinging(String connectionId, Session.Info sessionInfo) {
415             mHandler.obtainMessage(MSG_SET_RINGING, connectionId).sendToTarget();
416         }
417 
418         @Override
419         public void setDialing(String connectionId, Session.Info sessionInfo) {
420             mHandler.obtainMessage(MSG_SET_DIALING, connectionId).sendToTarget();
421         }
422 
423         @Override
424         public void setPulling(String connectionId, Session.Info sessionInfo) {
425             mHandler.obtainMessage(MSG_SET_PULLING, connectionId).sendToTarget();
426         }
427 
428         @Override
429         public void setDisconnected(String connectionId, DisconnectCause disconnectCause,
430                 Session.Info sessionInfo) {
431             SomeArgs args = SomeArgs.obtain();
432             args.arg1 = connectionId;
433             args.arg2 = disconnectCause;
434             mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget();
435         }
436 
437         @Override
438         public void setOnHold(String connectionId, Session.Info sessionInfo) {
439             mHandler.obtainMessage(MSG_SET_ON_HOLD, connectionId).sendToTarget();
440         }
441 
442         @Override
443         public void setRingbackRequested(String connectionId, boolean ringback,
444                 Session.Info sessionInfo) {
445             mHandler.obtainMessage(MSG_SET_RINGBACK_REQUESTED, ringback ? 1 : 0, 0, connectionId)
446                     .sendToTarget();
447         }
448 
449         @Override
450         public void setConnectionCapabilities(String connectionId, int connectionCapabilities,
451                 Session.Info sessionInfo) {
452             mHandler.obtainMessage(
453                     MSG_SET_CONNECTION_CAPABILITIES, connectionCapabilities, 0, connectionId)
454                     .sendToTarget();
455         }
456 
457         @Override
458         public void setConnectionProperties(String connectionId, int connectionProperties,
459                 Session.Info sessionInfo) {
460             mHandler.obtainMessage(
461                     MSG_SET_CONNECTION_PROPERTIES, connectionProperties, 0, connectionId)
462                     .sendToTarget();
463         }
464 
465         @Override
466         public void setConferenceMergeFailed(String callId, Session.Info sessionInfo) {
467             SomeArgs args = SomeArgs.obtain();
468             args.arg1 = callId;
469             mHandler.obtainMessage(MSG_SET_CONFERENCE_MERGE_FAILED, args).sendToTarget();
470         }
471 
472         @Override
473         public void setIsConferenced(String callId, String conferenceCallId,
474                 Session.Info sessionInfo) {
475             SomeArgs args = SomeArgs.obtain();
476             args.arg1 = callId;
477             args.arg2 = conferenceCallId;
478             mHandler.obtainMessage(MSG_SET_IS_CONFERENCED, args).sendToTarget();
479         }
480 
481         @Override
482         public void addConferenceCall(String callId, ParcelableConference parcelableConference,
483                 Session.Info sessionInfo) {
484             SomeArgs args = SomeArgs.obtain();
485             args.arg1 = callId;
486             args.arg2 = parcelableConference;
487             mHandler.obtainMessage(MSG_ADD_CONFERENCE_CALL, args).sendToTarget();
488         }
489 
490         @Override
491         public void removeCall(String connectionId,
492                 Session.Info sessionInfo) {
493             mHandler.obtainMessage(MSG_REMOVE_CALL, connectionId).sendToTarget();
494         }
495 
496         @Override
497         public void onPostDialWait(String connectionId, String remainingDigits,
498                 Session.Info sessionInfo) {
499             SomeArgs args = SomeArgs.obtain();
500             args.arg1 = connectionId;
501             args.arg2 = remainingDigits;
502             mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget();
503         }
504 
505         @Override
506         public void onPostDialChar(String connectionId, char nextChar,
507                 Session.Info sessionInfo) {
508             SomeArgs args = SomeArgs.obtain();
509             args.arg1 = connectionId;
510             args.argi1 = nextChar;
511             mHandler.obtainMessage(MSG_ON_POST_DIAL_CHAR, args).sendToTarget();
512         }
513 
514         @Override
515         public void queryRemoteConnectionServices(RemoteServiceCallback callback,
516                 String callingPackage, Session.Info sessionInfo) {
517             SomeArgs args = SomeArgs.obtain();
518             args.arg1 = callback;
519             args.arg2 = callingPackage;
520             mHandler.obtainMessage(MSG_QUERY_REMOTE_CALL_SERVICES, args).sendToTarget();
521         }
522 
523         @Override
524         public void setVideoState(String connectionId, int videoState,
525                 Session.Info sessionInfo) {
526             mHandler.obtainMessage(MSG_SET_VIDEO_STATE, videoState, 0, connectionId).sendToTarget();
527         }
528 
529         @Override
530         public void setVideoProvider(String connectionId, IVideoProvider videoProvider,
531                 Session.Info sessionInfo) {
532             SomeArgs args = SomeArgs.obtain();
533             args.arg1 = connectionId;
534             args.arg2 = videoProvider;
535             mHandler.obtainMessage(MSG_SET_VIDEO_CALL_PROVIDER, args).sendToTarget();
536         }
537 
538         @Override
539         public final void setIsVoipAudioMode(String connectionId, boolean isVoip,
540                 Session.Info sessionInfo) {
541             mHandler.obtainMessage(MSG_SET_IS_VOIP_AUDIO_MODE, isVoip ? 1 : 0, 0,
542                     connectionId).sendToTarget();
543         }
544 
545         @Override
546         public final void setStatusHints(String connectionId, StatusHints statusHints,
547                 Session.Info sessionInfo) {
548             SomeArgs args = SomeArgs.obtain();
549             args.arg1 = connectionId;
550             args.arg2 = statusHints;
551             mHandler.obtainMessage(MSG_SET_STATUS_HINTS, args).sendToTarget();
552         }
553 
554         @Override
555         public final void setAddress(String connectionId, Uri address, int presentation,
556                 Session.Info sessionInfo) {
557             SomeArgs args = SomeArgs.obtain();
558             args.arg1 = connectionId;
559             args.arg2 = address;
560             args.argi1 = presentation;
561             mHandler.obtainMessage(MSG_SET_ADDRESS, args).sendToTarget();
562         }
563 
564         @Override
565         public final void setCallerDisplayName(
566                 String connectionId, String callerDisplayName, int presentation,
567                 Session.Info sessionInfo) {
568             SomeArgs args = SomeArgs.obtain();
569             args.arg1 = connectionId;
570             args.arg2 = callerDisplayName;
571             args.argi1 = presentation;
572             mHandler.obtainMessage(MSG_SET_CALLER_DISPLAY_NAME, args).sendToTarget();
573         }
574 
575         @Override
576         public final void setConferenceableConnections(String connectionId,
577                 List<String> conferenceableConnectionIds, Session.Info sessionInfo) {
578             SomeArgs args = SomeArgs.obtain();
579             args.arg1 = connectionId;
580             args.arg2 = conferenceableConnectionIds;
581             mHandler.obtainMessage(MSG_SET_CONFERENCEABLE_CONNECTIONS, args).sendToTarget();
582         }
583 
584         @Override
585         public final void addExistingConnection(String connectionId,
586                 ParcelableConnection connection, Session.Info sessionInfo) {
587             SomeArgs args = SomeArgs.obtain();
588             args.arg1 = connectionId;
589             args.arg2 = connection;
590             mHandler.obtainMessage(MSG_ADD_EXISTING_CONNECTION, args).sendToTarget();
591         }
592 
593         @Override
594         public final void putExtras(String connectionId, Bundle extras, Session.Info sessionInfo) {
595             SomeArgs args = SomeArgs.obtain();
596             args.arg1 = connectionId;
597             args.arg2 = extras;
598             mHandler.obtainMessage(MSG_PUT_EXTRAS, args).sendToTarget();
599         }
600 
601         @Override
602         public final void removeExtras(String connectionId, List<String> keys,
603                 Session.Info sessionInfo) {
604             SomeArgs args = SomeArgs.obtain();
605             args.arg1 = connectionId;
606             args.arg2 = keys;
607             mHandler.obtainMessage(MSG_REMOVE_EXTRAS, args).sendToTarget();
608         }
609 
610         @Override
611         public final void setAudioRoute(String connectionId, int audioRoute,
612                 String bluetoothAddress, Session.Info sessionInfo) {
613             SomeArgs args = SomeArgs.obtain();
614             args.arg1 = connectionId;
615             args.argi1 = audioRoute;
616             args.arg2 = bluetoothAddress;
617             args.arg3 = sessionInfo;
618             mHandler.obtainMessage(MSG_SET_AUDIO_ROUTE, args).sendToTarget();
619         }
620 
621         @Override
622         public final void onConnectionEvent(String connectionId, String event, Bundle extras,
623                 Session.Info sessionInfo) {
624             SomeArgs args = SomeArgs.obtain();
625             args.arg1 = connectionId;
626             args.arg2 = event;
627             args.arg3 = extras;
628             mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
629         }
630 
631         @Override
632         public void onRttInitiationSuccess(String connectionId, Session.Info sessionInfo)
633                 throws RemoteException {
634             mHandler.obtainMessage(MSG_ON_RTT_INITIATION_SUCCESS, connectionId).sendToTarget();
635         }
636 
637         @Override
638         public void onRttInitiationFailure(String connectionId, int reason,
639                 Session.Info sessionInfo)
640                 throws RemoteException {
641             mHandler.obtainMessage(MSG_ON_RTT_INITIATION_FAILURE, reason, 0, connectionId)
642                     .sendToTarget();
643         }
644 
645         @Override
646         public void onRttSessionRemotelyTerminated(String connectionId, Session.Info sessionInfo)
647                 throws RemoteException {
648             mHandler.obtainMessage(MSG_ON_RTT_REMOTELY_TERMINATED, connectionId).sendToTarget();
649         }
650 
651         @Override
652         public void onRemoteRttRequest(String connectionId, Session.Info sessionInfo)
653                 throws RemoteException {
654             mHandler.obtainMessage(MSG_ON_RTT_UPGRADE_REQUEST, connectionId).sendToTarget();
655         }
656 
657         @Override
658         public void onPhoneAccountChanged(String callId, PhoneAccountHandle pHandle,
659                 Session.Info sessionInfo) {
660             SomeArgs args = SomeArgs.obtain();
661             args.arg1 = callId;
662             args.arg2 = pHandle;
663             mHandler.obtainMessage(MSG_SET_PHONE_ACCOUNT_CHANGED, args).sendToTarget();
664         }
665 
666         @Override
667         public void onConnectionServiceFocusReleased(Session.Info sessionInfo) {
668             mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_RELEASED).sendToTarget();
669         }
670 
671         @Override
672         public void resetConnectionTime(String callId, Session.Info sessionInfo) {
673             // Do nothing
674         }
675 
676         @Override
677         public void setConferenceState(String callId, boolean isConference,
678                 Session.Info sessionInfo) {
679             SomeArgs args = SomeArgs.obtain();
680             args.arg1 = callId;
681             args.arg2 = isConference;
682             args.arg3 = sessionInfo;
683             mHandler.obtainMessage(MSG_SET_CONFERENCE_STATE, args).sendToTarget();
684         }
685 
686         @Override
687         public void setCallDirection(String callId, int direction,
688                 Session.Info sessionInfo) {
689             SomeArgs args = SomeArgs.obtain();
690             args.arg1 = callId;
691             args.argi1 = direction;
692             args.arg2 = sessionInfo;
693             mHandler.obtainMessage(MSG_SET_CALL_DIRECTION, args).sendToTarget();
694         }
695     };
696 
ConnectionServiceAdapterServant(IConnectionServiceAdapter delegate)697     public ConnectionServiceAdapterServant(IConnectionServiceAdapter delegate) {
698         mDelegate = delegate;
699     }
700 
getStub()701     public IConnectionServiceAdapter getStub() {
702         return mStub;
703     }
704 }
705