1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
|
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.telecom;
import com.android.internal.telecom.IConnectionService;
import com.android.internal.telecom.IVideoCallback;
import com.android.internal.telecom.IVideoProvider;
import android.annotation.SystemApi;
import android.net.Uri;
import android.os.IBinder;
import android.os.RemoteException;
import android.view.Surface;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
* A connection provided to a {@link ConnectionService} by another {@code ConnectionService}
* running in a different process.
*
* @see ConnectionService#createRemoteOutgoingConnection(PhoneAccountHandle, ConnectionRequest)
* @see ConnectionService#createRemoteIncomingConnection(PhoneAccountHandle, ConnectionRequest)
* @hide
*/
@SystemApi
public final class RemoteConnection {
public static abstract class Callback {
/**
* Invoked when the state of this {@code RemoteConnection} has changed. See
* {@link #getState()}.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param state The new state of the {@code RemoteConnection}.
*/
public void onStateChanged(RemoteConnection connection, int state) {}
/**
* Invoked when this {@code RemoteConnection} is disconnected.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param disconnectCause The ({@see DisconnectCause}) associated with this failed
* connection.
*/
public void onDisconnected(
RemoteConnection connection,
DisconnectCause disconnectCause) {}
/**
* Invoked when this {@code RemoteConnection} is requesting ringback. See
* {@link #isRingbackRequested()}.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param ringback Whether the {@code RemoteConnection} is requesting ringback.
*/
public void onRingbackRequested(RemoteConnection connection, boolean ringback) {}
/** @hide */
@Deprecated public void onCallCapabilitiesChanged(
RemoteConnection connection,
int callCapabilities) {}
/**
* Indicates that the call capabilities of this {@code RemoteConnection} have changed.
* See {@link #getConnectionCapabilities()}.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param connectionCapabilities The new capabilities of the {@code RemoteConnection}.
*/
public void onConnectionCapabilitiesChanged(
RemoteConnection connection,
int connectionCapabilities) {}
/**
* Invoked when the post-dial sequence in the outgoing {@code Connection} has reached a
* pause character. This causes the post-dial signals to stop pending user confirmation. An
* implementation should present this choice to the user and invoke
* {@link RemoteConnection#postDialContinue(boolean)} when the user makes the choice.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param remainingPostDialSequence The post-dial characters that remain to be sent.
*/
public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {}
/**
* Invoked when the post-dial sequence in the outgoing {@code Connection} has processed
* a character.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param nextChar The character being processed.
*/
public void onPostDialChar(RemoteConnection connection, char nextChar) {}
/**
* Indicates that the VOIP audio status of this {@code RemoteConnection} has changed.
* See {@link #isVoipAudioMode()}.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param isVoip Whether the new audio state of the {@code RemoteConnection} is VOIP.
*/
public void onVoipAudioChanged(RemoteConnection connection, boolean isVoip) {}
/**
* Indicates that the status hints of this {@code RemoteConnection} have changed. See
* {@link #getStatusHints()} ()}.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param statusHints The new status hints of the {@code RemoteConnection}.
*/
public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {}
/**
* Indicates that the address (e.g., phone number) of this {@code RemoteConnection} has
* changed. See {@link #getAddress()} and {@link #getAddressPresentation()}.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param address The new address of the {@code RemoteConnection}.
* @param presentation The presentation requirements for the address.
* See {@link TelecomManager} for valid values.
*/
public void onAddressChanged(RemoteConnection connection, Uri address, int presentation) {}
/**
* Indicates that the caller display name of this {@code RemoteConnection} has changed.
* See {@link #getCallerDisplayName()} and {@link #getCallerDisplayNamePresentation()}.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param callerDisplayName The new caller display name of the {@code RemoteConnection}.
* @param presentation The presentation requirements for the handle.
* See {@link TelecomManager} for valid values.
*/
public void onCallerDisplayNameChanged(
RemoteConnection connection, String callerDisplayName, int presentation) {}
/**
* Indicates that the video state of this {@code RemoteConnection} has changed.
* See {@link #getVideoState()}.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param videoState The new video state of the {@code RemoteConnection}.
* @hide
*/
public void onVideoStateChanged(RemoteConnection connection, int videoState) {}
/**
* Indicates that the call substate of this {@code RemoteConnection} has changed.
* See {@link #getCallSubstate()}.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param callSubstate The new call substate of the {@code RemoteConnection}.
* @hide
*/
public void onCallSubstateChanged(RemoteConnection connection, int callSubstate) {}
/**
* Indicates that this {@code RemoteConnection} has been destroyed. No further requests
* should be made to the {@code RemoteConnection}, and references to it should be cleared.
*
* @param connection The {@code RemoteConnection} invoking this method.
*/
public void onDestroyed(RemoteConnection connection) {}
/**
* Indicates that the {@code RemoteConnection}s with which this {@code RemoteConnection}
* may be asked to create a conference has changed.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param conferenceableConnections The {@code RemoteConnection}s with which this
* {@code RemoteConnection} may be asked to create a conference.
*/
public void onConferenceableConnectionsChanged(
RemoteConnection connection,
List<RemoteConnection> conferenceableConnections) {}
/**
* Indicates that the {@code VideoProvider} associated with this {@code RemoteConnection}
* has changed.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param videoProvider The new {@code VideoProvider} associated with this
* {@code RemoteConnection}.
* @hide
*/
public void onVideoProviderChanged(
RemoteConnection connection, VideoProvider videoProvider) {}
/**
* Indicates that the {@code RemoteConference} that this {@code RemoteConnection} is a part
* of has changed.
*
* @param connection The {@code RemoteConnection} invoking this method.
* @param conference The {@code RemoteConference} of which this {@code RemoteConnection} is
* a part, which may be {@code null}.
*/
public void onConferenceChanged(
RemoteConnection connection,
RemoteConference conference) {}
}
/** {@hide} */
public static class VideoProvider {
public abstract static class Listener {
public void onReceiveSessionModifyRequest(
VideoProvider videoProvider,
VideoProfile videoProfile) {}
public void onReceiveSessionModifyResponse(
VideoProvider videoProvider,
int status,
VideoProfile requestedProfile,
VideoProfile responseProfile) {}
public void onHandleCallSessionEvent(VideoProvider videoProvider, int event) {}
public void onPeerDimensionsChanged(VideoProvider videoProvider, int width, int height) {}
public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) {}
public void onCameraCapabilitiesChanged(
VideoProvider videoProvider,
CameraCapabilities cameraCapabilities) {}
public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) {}
}
private final IVideoCallback mVideoCallbackDelegate = new IVideoCallback() {
@Override
public void receiveSessionModifyRequest(VideoProfile videoProfile) {
for (Listener l : mListeners) {
l.onReceiveSessionModifyRequest(VideoProvider.this, videoProfile);
}
}
@Override
public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile,
VideoProfile responseProfile) {
for (Listener l : mListeners) {
l.onReceiveSessionModifyResponse(
VideoProvider.this,
status,
requestedProfile,
responseProfile);
}
}
@Override
public void handleCallSessionEvent(int event) {
for (Listener l : mListeners) {
l.onHandleCallSessionEvent(VideoProvider.this, event);
}
}
@Override
public void changePeerDimensions(int width, int height) {
for (Listener l : mListeners) {
l.onPeerDimensionsChanged(VideoProvider.this, width, height);
}
}
@Override
public void changeCallDataUsage(long dataUsage) {
for (Listener l : mListeners) {
l.onCallDataUsageChanged(VideoProvider.this, dataUsage);
}
}
@Override
public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
for (Listener l : mListeners) {
l.onCameraCapabilitiesChanged(VideoProvider.this, cameraCapabilities);
}
}
@Override
public void changeVideoQuality(int videoQuality) {
for (Listener l : mListeners) {
l.onVideoQualityChanged(VideoProvider.this, videoQuality);
}
}
@Override
public IBinder asBinder() {
return null;
}
};
private final VideoCallbackServant mVideoCallbackServant =
new VideoCallbackServant(mVideoCallbackDelegate);
private final IVideoProvider mVideoProviderBinder;
/**
* ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
* load factor before resizing, 1 means we only expect a single thread to
* access the map so make only a single shard
*/
private final Set<Listener> mListeners = Collections.newSetFromMap(
new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
public VideoProvider(IVideoProvider videoProviderBinder) {
mVideoProviderBinder = videoProviderBinder;
try {
mVideoProviderBinder.setVideoCallback(mVideoCallbackServant.getStub().asBinder());
} catch (RemoteException e) {
}
}
public void addListener(Listener l) {
mListeners.add(l);
}
public void removeListener(Listener l) {
mListeners.remove(l);
}
public void setCamera(String cameraId) {
try {
mVideoProviderBinder.setCamera(cameraId);
} catch (RemoteException e) {
}
}
public void setPreviewSurface(Surface surface) {
try {
mVideoProviderBinder.setPreviewSurface(surface);
} catch (RemoteException e) {
}
}
public void setDisplaySurface(Surface surface) {
try {
mVideoProviderBinder.setDisplaySurface(surface);
} catch (RemoteException e) {
}
}
public void setDeviceOrientation(int rotation) {
try {
mVideoProviderBinder.setDeviceOrientation(rotation);
} catch (RemoteException e) {
}
}
public void setZoom(float value) {
try {
mVideoProviderBinder.setZoom(value);
} catch (RemoteException e) {
}
}
public void sendSessionModifyRequest(VideoProfile reqProfile) {
try {
mVideoProviderBinder.sendSessionModifyRequest(reqProfile);
} catch (RemoteException e) {
}
}
public void sendSessionModifyResponse(VideoProfile responseProfile) {
try {
mVideoProviderBinder.sendSessionModifyResponse(responseProfile);
} catch (RemoteException e) {
}
}
public void requestCameraCapabilities() {
try {
mVideoProviderBinder.requestCameraCapabilities();
} catch (RemoteException e) {
}
}
public void requestCallDataUsage() {
try {
mVideoProviderBinder.requestCallDataUsage();
} catch (RemoteException e) {
}
}
public void setPauseImage(String uri) {
try {
mVideoProviderBinder.setPauseImage(uri);
} catch (RemoteException e) {
}
}
}
private IConnectionService mConnectionService;
private final String mConnectionId;
/**
* ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
* load factor before resizing, 1 means we only expect a single thread to
* access the map so make only a single shard
*/
private final Set<Callback> mCallbacks = Collections.newSetFromMap(
new ConcurrentHashMap<Callback, Boolean>(8, 0.9f, 1));
private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>();
private final List<RemoteConnection> mUnmodifiableconferenceableConnections =
Collections.unmodifiableList(mConferenceableConnections);
private int mState = Connection.STATE_NEW;
private DisconnectCause mDisconnectCause;
private boolean mRingbackRequested;
private boolean mConnected;
private int mConnectionCapabilities;
private int mVideoState;
private int mCallSubstate;
private VideoProvider mVideoProvider;
private boolean mIsVoipAudioMode;
private StatusHints mStatusHints;
private Uri mAddress;
private int mAddressPresentation;
private String mCallerDisplayName;
private int mCallerDisplayNamePresentation;
private RemoteConference mConference;
/**
* @hide
*/
RemoteConnection(
String id,
IConnectionService connectionService,
ConnectionRequest request) {
mConnectionId = id;
mConnectionService = connectionService;
mConnected = true;
mState = Connection.STATE_INITIALIZING;
}
/**
* @hide
*/
RemoteConnection(String callId, IConnectionService connectionService,
ParcelableConnection connection) {
mConnectionId = callId;
mConnectionService = connectionService;
mConnected = true;
mState = connection.getState();
mDisconnectCause = connection.getDisconnectCause();
mRingbackRequested = connection.isRingbackRequested();
mConnectionCapabilities = connection.getConnectionCapabilities();
mVideoState = connection.getVideoState();
mVideoProvider = new RemoteConnection.VideoProvider(connection.getVideoProvider());
mIsVoipAudioMode = connection.getIsVoipAudioMode();
mStatusHints = connection.getStatusHints();
mAddress = connection.getHandle();
mAddressPresentation = connection.getHandlePresentation();
mCallerDisplayName = connection.getCallerDisplayName();
mCallerDisplayNamePresentation = connection.getCallerDisplayNamePresentation();
mConference = null;
}
/**
* Create a RemoteConnection which is used for failed connections. Note that using it for any
* "real" purpose will almost certainly fail. Callers should note the failure and act
* accordingly (moving on to another RemoteConnection, for example)
*
* @param disconnectCause The reason for the failed connection.
* @hide
*/
RemoteConnection(DisconnectCause disconnectCause) {
mConnectionId = "NULL";
mConnected = false;
mState = Connection.STATE_DISCONNECTED;
mDisconnectCause = disconnectCause;
}
/**
* Adds a callback to this {@code RemoteConnection}.
*
* @param callback A {@code Callback}.
*/
public void registerCallback(Callback callback) {
mCallbacks.add(callback);
}
/**
* Removes a callback from this {@code RemoteConnection}.
*
* @param callback A {@code Callback}.
*/
public void unregisterCallback(Callback callback) {
if (callback != null) {
mCallbacks.remove(callback);
}
}
/**
* Obtains the state of this {@code RemoteConnection}.
*
* @return A state value, chosen from the {@code STATE_*} constants.
*/
public int getState() {
return mState;
}
/**
* Obtains the reason why this {@code RemoteConnection} may have been disconnected.
*
* @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the
* disconnect cause expressed as a code chosen from among those declared in
* {@link DisconnectCause}.
*/
public DisconnectCause getDisconnectCause() {
return mDisconnectCause;
}
/**
* Obtains the capabilities of this {@code RemoteConnection}.
*
* @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in
* the {@code CAPABILITY_*} constants in class {@link Connection}.
*/
public int getConnectionCapabilities() {
return mConnectionCapabilities;
}
/**
* Determines if the audio mode of this {@code RemoteConnection} is VOIP.
*
* @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP.
*/
public boolean isVoipAudioMode() {
return mIsVoipAudioMode;
}
/**
* Obtains status hints pertaining to this {@code RemoteConnection}.
*
* @return The current {@link StatusHints} of this {@code RemoteConnection},
* or {@code null} if none have been set.
*/
public StatusHints getStatusHints() {
return mStatusHints;
}
/**
* Obtains the address of this {@code RemoteConnection}.
*
* @return The address (e.g., phone number) to which the {@code RemoteConnection}
* is currently connected.
*/
public Uri getAddress() {
return mAddress;
}
/**
* Obtains the presentation requirements for the address of this {@code RemoteConnection}.
*
* @return The presentation requirements for the address. See
* {@link TelecomManager} for valid values.
*/
public int getAddressPresentation() {
return mAddressPresentation;
}
/**
* Obtains the display name for this {@code RemoteConnection}'s caller.
*
* @return The display name for the caller.
*/
public CharSequence getCallerDisplayName() {
return mCallerDisplayName;
}
/**
* Obtains the presentation requirements for this {@code RemoteConnection}'s
* caller's display name.
*
* @return The presentation requirements for the caller display name. See
* {@link TelecomManager} for valid values.
*/
public int getCallerDisplayNamePresentation() {
return mCallerDisplayNamePresentation;
}
/**
* Obtains the video state of this {@code RemoteConnection}.
*
* @return The video state of the {@code RemoteConnection}. See {@link VideoProfile.VideoState}.
* @hide
*/
public int getVideoState() {
return mVideoState;
}
/**
*
* @return The call substate of the {@code RemoteConnection}. See
* @hide
*/
public int getCallSubstate() {
return mCallSubstate;
}
/**
* Obtains the video provider of this {@code RemoteConnection}.
* @return The video provider associated with this {@code RemoteConnection}.
* @hide
*/
public final VideoProvider getVideoProvider() {
return mVideoProvider;
}
/**
* Determines whether this {@code RemoteConnection} is requesting ringback.
*
* @return Whether the {@code RemoteConnection} is requesting that the framework play a
* ringback tone on its behalf.
*/
public boolean isRingbackRequested() {
return false;
}
/**
* Instructs this {@code RemoteConnection} to abort.
*/
public void abort() {
try {
if (mConnected) {
mConnectionService.abort(mConnectionId);
}
} catch (RemoteException ignored) {
}
}
/**
* Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
*/
public void answer() {
try {
if (mConnected) {
mConnectionService.answer(mConnectionId);
}
} catch (RemoteException ignored) {
}
}
/**
* Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
* @param videoState The video state in which to answer the call.
* @hide
*/
public void answer(int videoState) {
try {
if (mConnected) {
mConnectionService.answerVideo(mConnectionId, videoState);
}
} catch (RemoteException ignored) {
}
}
/**
* Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
*/
public void reject() {
try {
if (mConnected) {
mConnectionService.reject(mConnectionId);
}
} catch (RemoteException ignored) {
}
}
/**
* Instructs this {@code RemoteConnection} to go on hold.
*/
public void hold() {
try {
if (mConnected) {
mConnectionService.hold(mConnectionId);
}
} catch (RemoteException ignored) {
}
}
/**
* Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
*/
public void unhold() {
try {
if (mConnected) {
mConnectionService.unhold(mConnectionId);
}
} catch (RemoteException ignored) {
}
}
/**
* Instructs this {@code RemoteConnection} to disconnect.
*/
public void disconnect() {
try {
if (mConnected) {
mConnectionService.disconnect(mConnectionId);
}
} catch (RemoteException ignored) {
}
}
/**
* Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling
* (DTMF) tone.
*
* Any other currently playing DTMF tone in the specified call is immediately stopped.
*
* @param digit A character representing the DTMF digit for which to play the tone. This
* value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
*/
public void playDtmfTone(char digit) {
try {
if (mConnected) {
mConnectionService.playDtmfTone(mConnectionId, digit);
}
} catch (RemoteException ignored) {
}
}
/**
* Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling
* (DTMF) tone currently playing.
*
* DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
* currently playing, this method will do nothing.
*/
public void stopDtmfTone() {
try {
if (mConnected) {
mConnectionService.stopDtmfTone(mConnectionId);
}
} catch (RemoteException ignored) {
}
}
/**
* Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string.
*
* A post-dial DTMF string is a string of digits following the first instance of either
* {@link TelecomManager#DTMF_CHARACTER_WAIT} or {@link TelecomManager#DTMF_CHARACTER_PAUSE}.
* These digits are immediately sent as DTMF tones to the recipient as soon as the
* connection is made.
*
* If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
* {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period
* of time.
*
* If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
* {@code RemoteConnection} will pause playing the tones and notify callbacks via
* {@link Callback#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app
* should display to the user an indication of this state and an affordance to continue
* the postdial sequence. When the user decides to continue the postdial sequence, the in-call
* app should invoke the {@link #postDialContinue(boolean)} method.
*
* @param proceed Whether or not to continue with the post-dial sequence.
*/
public void postDialContinue(boolean proceed) {
try {
if (mConnected) {
mConnectionService.onPostDialContinue(mConnectionId, proceed);
}
} catch (RemoteException ignored) {
}
}
/**
* Set the audio state of this {@code RemoteConnection}.
*
* @param state The audio state of this {@code RemoteConnection}.
*/
public void setAudioState(AudioState state) {
try {
if (mConnected) {
mConnectionService.onAudioStateChanged(mConnectionId, state);
}
} catch (RemoteException ignored) {
}
}
/**
* Obtain the {@code RemoteConnection}s with which this {@code RemoteConnection} may be
* successfully asked to create a conference with.
*
* @return The {@code RemoteConnection}s with which this {@code RemoteConnection} may be
* merged into a {@link RemoteConference}.
*/
public List<RemoteConnection> getConferenceableConnections() {
return mUnmodifiableconferenceableConnections;
}
/**
* Obtain the {@code RemoteConference} that this {@code RemoteConnection} may be a part
* of, or {@code null} if there is no such {@code RemoteConference}.
*
* @return A {@code RemoteConference} or {@code null};
*/
public RemoteConference getConference() {
return mConference;
}
/** {@hide} */
String getId() {
return mConnectionId;
}
/** {@hide} */
IConnectionService getConnectionService() {
return mConnectionService;
}
/**
* @hide
*/
void setState(int state) {
if (mState != state) {
mState = state;
for (Callback c: mCallbacks) {
c.onStateChanged(this, state);
}
}
}
/**
* @hide
*/
void setDisconnected(DisconnectCause disconnectCause) {
if (mState != Connection.STATE_DISCONNECTED) {
mState = Connection.STATE_DISCONNECTED;
mDisconnectCause = disconnectCause;
for (Callback c : mCallbacks) {
c.onDisconnected(this, mDisconnectCause);
}
}
}
/**
* @hide
*/
void setRingbackRequested(boolean ringback) {
if (mRingbackRequested != ringback) {
mRingbackRequested = ringback;
for (Callback c : mCallbacks) {
c.onRingbackRequested(this, ringback);
}
}
}
/**
* @hide
*/
void setConnectionCapabilities(int connectionCapabilities) {
mConnectionCapabilities = connectionCapabilities;
for (Callback c : mCallbacks) {
c.onConnectionCapabilitiesChanged(this, connectionCapabilities);
c.onCallCapabilitiesChanged(this, connectionCapabilities);
}
}
/**
* @hide
*/
void setDestroyed() {
if (!mCallbacks.isEmpty()) {
// Make sure that the callbacks are notified that the call is destroyed first.
if (mState != Connection.STATE_DISCONNECTED) {
setDisconnected(
new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed."));
}
for (Callback c : mCallbacks) {
c.onDestroyed(this);
}
mCallbacks.clear();
mConnected = false;
}
}
/**
* @hide
*/
void setPostDialWait(String remainingDigits) {
for (Callback c : mCallbacks) {
c.onPostDialWait(this, remainingDigits);
}
}
/**
* @hide
*/
void onPostDialChar(char nextChar) {
for (Callback c : mCallbacks) {
c.onPostDialChar(this, nextChar);
}
}
/**
* @hide
*/
void setVideoState(int videoState) {
mVideoState = videoState;
for (Callback c : mCallbacks) {
c.onVideoStateChanged(this, videoState);
}
}
/**
* @hide
*/
void setCallSubstate(int callSubstate) {
mCallSubstate = callSubstate;
for (Callback c : mCallbacks) {
c.onCallSubstateChanged(this, callSubstate);
}
}
/**
* @hide
*/
void setVideoProvider(VideoProvider videoProvider) {
mVideoProvider = videoProvider;
for (Callback c : mCallbacks) {
c.onVideoProviderChanged(this, videoProvider);
}
}
/** @hide */
void setIsVoipAudioMode(boolean isVoip) {
mIsVoipAudioMode = isVoip;
for (Callback c : mCallbacks) {
c.onVoipAudioChanged(this, isVoip);
}
}
/** @hide */
void setStatusHints(StatusHints statusHints) {
mStatusHints = statusHints;
for (Callback c : mCallbacks) {
c.onStatusHintsChanged(this, statusHints);
}
}
/** @hide */
void setAddress(Uri address, int presentation) {
mAddress = address;
mAddressPresentation = presentation;
for (Callback c : mCallbacks) {
c.onAddressChanged(this, address, presentation);
}
}
/** @hide */
void setCallerDisplayName(String callerDisplayName, int presentation) {
mCallerDisplayName = callerDisplayName;
mCallerDisplayNamePresentation = presentation;
for (Callback c : mCallbacks) {
c.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
}
}
/** @hide */
void setConferenceableConnections(List<RemoteConnection> conferenceableConnections) {
mConferenceableConnections.clear();
mConferenceableConnections.addAll(conferenceableConnections);
for (Callback c : mCallbacks) {
c.onConferenceableConnectionsChanged(this, mUnmodifiableconferenceableConnections);
}
}
/** @hide */
void setConference(RemoteConference conference) {
if (mConference != conference) {
mConference = conference;
for (Callback c : mCallbacks) {
c.onConferenceChanged(this, conference);
}
}
}
/**
* Create a RemoteConnection represents a failure, and which will be in
* {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost
* certainly result in bad things happening. Do not do this.
*
* @return a failed {@link RemoteConnection}
*
* @hide
*/
public static RemoteConnection failure(DisconnectCause disconnectCause) {
return new RemoteConnection(disconnectCause);
}
}
|