| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.telecom; |
| 18 |
|
| 19 |
import android.Manifest; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.Nullable; |
| 22 |
import android.annotation.RequiresPermission; |
| 23 |
import android.annotation.SystemApi; |
| 24 |
import android.hardware.camera2.CameraManager; |
| 25 |
import android.net.Uri; |
| 26 |
import android.os.BadParcelableException; |
| 27 |
import android.os.Bundle; |
| 28 |
import android.os.Handler; |
| 29 |
import android.os.IBinder; |
| 30 |
import android.os.RemoteException; |
| 31 |
import android.telecom.Logging.Session; |
| 32 |
import android.view.Surface; |
| 33 |
|
| 34 |
import com.android.internal.telecom.IConnectionService; |
| 35 |
import com.android.internal.telecom.IVideoCallback; |
| 36 |
import com.android.internal.telecom.IVideoProvider; |
| 37 |
|
| 38 |
import java.util.ArrayList; |
| 39 |
import java.util.Arrays; |
| 40 |
import java.util.Collections; |
| 41 |
import java.util.List; |
| 42 |
import java.util.Set; |
| 43 |
import java.util.concurrent.ConcurrentHashMap; |
| 44 |
import java.util.stream.Collectors; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public final class RemoteConnection { |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public static abstract class Callback { |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public void onStateChanged(RemoteConnection connection, int state) {} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public void onDisconnected( |
| 76 |
RemoteConnection connection, |
| 77 |
DisconnectCause disconnectCause) {} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public void onRingbackRequested(RemoteConnection connection, boolean ringback) {} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public void onConnectionCapabilitiesChanged( |
| 96 |
RemoteConnection connection, |
| 97 |
int connectionCapabilities) {} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
public void onConnectionPropertiesChanged( |
| 107 |
RemoteConnection connection, |
| 108 |
int connectionProperties) {} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
public void onPostDialChar(RemoteConnection connection, char nextChar) {} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public void onVoipAudioChanged(RemoteConnection connection, boolean isVoip) {} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
public void onAddressChanged(RemoteConnection connection, Uri address, int presentation) {} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
public void onCallerDisplayNameChanged( |
| 169 |
RemoteConnection connection, String callerDisplayName, int presentation) {} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
public void onVideoStateChanged(RemoteConnection connection, int videoState) {} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
public void onDestroyed(RemoteConnection connection) {} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
public void onConferenceableConnectionsChanged( |
| 197 |
RemoteConnection connection, |
| 198 |
List<RemoteConnection> conferenceableConnections) {} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
public void onVideoProviderChanged( |
| 209 |
RemoteConnection connection, VideoProvider videoProvider) {} |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
public void onConferenceChanged( |
| 220 |
RemoteConnection connection, |
| 221 |
RemoteConference conference) {} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
public void onExtrasChanged(RemoteConnection connection, @Nullable Bundle extras) {} |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
public void onConnectionEvent(RemoteConnection connection, String event, Bundle extras) {} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
public void onRttInitiationSuccess(RemoteConnection connection) {} |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
public void onRttInitiationFailure(RemoteConnection connection, int reason) {} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
public void onRttSessionRemotelyTerminated(RemoteConnection connection) {} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
public void onRemoteRttRequest(RemoteConnection connection) {} |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
public static class VideoProvider { |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
public abstract static class Callback { |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
public void onSessionModifyRequestReceived( |
| 302 |
VideoProvider videoProvider, |
| 303 |
VideoProfile videoProfile) {} |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
public void onSessionModifyResponseReceived( |
| 319 |
VideoProvider videoProvider, |
| 320 |
int status, |
| 321 |
VideoProfile requestedProfile, |
| 322 |
VideoProfile responseProfile) {} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
public void onCallSessionEvent(VideoProvider videoProvider, int event) {} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
public void onPeerDimensionsChanged(VideoProvider videoProvider, int width, |
| 346 |
int height) {} |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) {} |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
public void onCameraCapabilitiesChanged( |
| 371 |
VideoProvider videoProvider, |
| 372 |
VideoProfile.CameraCapabilities cameraCapabilities) {} |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) {} |
| 384 |
} |
| 385 |
|
| 386 |
private final IVideoCallback mVideoCallbackDelegate = new IVideoCallback() { |
| 387 |
@Override |
| 388 |
public void receiveSessionModifyRequest(VideoProfile videoProfile) { |
| 389 |
for (Callback l : mCallbacks) { |
| 390 |
l.onSessionModifyRequestReceived(VideoProvider.this, videoProfile); |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
@Override |
| 395 |
public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile, |
| 396 |
VideoProfile responseProfile) { |
| 397 |
for (Callback l : mCallbacks) { |
| 398 |
l.onSessionModifyResponseReceived( |
| 399 |
VideoProvider.this, |
| 400 |
status, |
| 401 |
requestedProfile, |
| 402 |
responseProfile); |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 406 |
@Override |
| 407 |
public void handleCallSessionEvent(int event) { |
| 408 |
for (Callback l : mCallbacks) { |
| 409 |
l.onCallSessionEvent(VideoProvider.this, event); |
| 410 |
} |
| 411 |
} |
| 412 |
|
| 413 |
@Override |
| 414 |
public void changePeerDimensions(int width, int height) { |
| 415 |
for (Callback l : mCallbacks) { |
| 416 |
l.onPeerDimensionsChanged(VideoProvider.this, width, height); |
| 417 |
} |
| 418 |
} |
| 419 |
|
| 420 |
@Override |
| 421 |
public void changeCallDataUsage(long dataUsage) { |
| 422 |
for (Callback l : mCallbacks) { |
| 423 |
l.onCallDataUsageChanged(VideoProvider.this, dataUsage); |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 427 |
@Override |
| 428 |
public void changeCameraCapabilities( |
| 429 |
VideoProfile.CameraCapabilities cameraCapabilities) { |
| 430 |
for (Callback l : mCallbacks) { |
| 431 |
l.onCameraCapabilitiesChanged(VideoProvider.this, cameraCapabilities); |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
@Override |
| 436 |
public void changeVideoQuality(int videoQuality) { |
| 437 |
for (Callback l : mCallbacks) { |
| 438 |
l.onVideoQualityChanged(VideoProvider.this, videoQuality); |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
@Override |
| 443 |
public IBinder asBinder() { |
| 444 |
return null; |
| 445 |
} |
| 446 |
}; |
| 447 |
|
| 448 |
private final VideoCallbackServant mVideoCallbackServant = |
| 449 |
new VideoCallbackServant(mVideoCallbackDelegate); |
| 450 |
|
| 451 |
private final IVideoProvider mVideoProviderBinder; |
| 452 |
|
| 453 |
private final String mCallingPackage; |
| 454 |
|
| 455 |
private final int mTargetSdkVersion; |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
private final Set<Callback> mCallbacks = Collections.newSetFromMap( |
| 463 |
new ConcurrentHashMap<Callback, Boolean>(8, 0.9f, 1)); |
| 464 |
|
| 465 |
VideoProvider(IVideoProvider videoProviderBinder, String callingPackage, |
| 466 |
int targetSdkVersion) { |
| 467 |
|
| 468 |
mVideoProviderBinder = videoProviderBinder; |
| 469 |
mCallingPackage = callingPackage; |
| 470 |
mTargetSdkVersion = targetSdkVersion; |
| 471 |
try { |
| 472 |
mVideoProviderBinder.addVideoCallback(mVideoCallbackServant.getStub().asBinder()); |
| 473 |
} catch (RemoteException e) { |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
public void registerCallback(Callback l) { |
| 483 |
mCallbacks.add(l); |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
public void unregisterCallback(Callback l) { |
| 492 |
mCallbacks.remove(l); |
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
public void setCamera(String cameraId) { |
| 504 |
try { |
| 505 |
mVideoProviderBinder.setCamera(cameraId, mCallingPackage, mTargetSdkVersion); |
| 506 |
} catch (RemoteException e) { |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
public void setPreviewSurface(Surface surface) { |
| 518 |
try { |
| 519 |
mVideoProviderBinder.setPreviewSurface(surface); |
| 520 |
} catch (RemoteException e) { |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
public void setDisplaySurface(Surface surface) { |
| 532 |
try { |
| 533 |
mVideoProviderBinder.setDisplaySurface(surface); |
| 534 |
} catch (RemoteException e) { |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
public void setDeviceOrientation(int rotation) { |
| 546 |
try { |
| 547 |
mVideoProviderBinder.setDeviceOrientation(rotation); |
| 548 |
} catch (RemoteException e) { |
| 549 |
} |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
public void setZoom(float value) { |
| 559 |
try { |
| 560 |
mVideoProviderBinder.setZoom(value); |
| 561 |
} catch (RemoteException e) { |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) { |
| 574 |
try { |
| 575 |
mVideoProviderBinder.sendSessionModifyRequest(fromProfile, toProfile); |
| 576 |
} catch (RemoteException e) { |
| 577 |
} |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
public void sendSessionModifyResponse(VideoProfile responseProfile) { |
| 588 |
try { |
| 589 |
mVideoProviderBinder.sendSessionModifyResponse(responseProfile); |
| 590 |
} catch (RemoteException e) { |
| 591 |
} |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
public void requestCameraCapabilities() { |
| 601 |
try { |
| 602 |
mVideoProviderBinder.requestCameraCapabilities(); |
| 603 |
} catch (RemoteException e) { |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
public void requestCallDataUsage() { |
| 614 |
try { |
| 615 |
mVideoProviderBinder.requestCallDataUsage(); |
| 616 |
} catch (RemoteException e) { |
| 617 |
} |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
public void setPauseImage(Uri uri) { |
| 627 |
try { |
| 628 |
mVideoProviderBinder.setPauseImage(uri); |
| 629 |
} catch (RemoteException e) { |
| 630 |
} |
| 631 |
} |
| 632 |
} |
| 633 |
|
| 634 |
private IConnectionService mConnectionService; |
| 635 |
private final String mConnectionId; |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
private final Set<CallbackRecord> mCallbackRecords = Collections.newSetFromMap( |
| 642 |
new ConcurrentHashMap<CallbackRecord, Boolean>(8, 0.9f, 1)); |
| 643 |
private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>(); |
| 644 |
private final List<RemoteConnection> mUnmodifiableconferenceableConnections = |
| 645 |
Collections.unmodifiableList(mConferenceableConnections); |
| 646 |
|
| 647 |
private int mState = Connection.STATE_NEW; |
| 648 |
private DisconnectCause mDisconnectCause; |
| 649 |
private boolean mRingbackRequested; |
| 650 |
private boolean mConnected; |
| 651 |
private int mConnectionCapabilities; |
| 652 |
private int mConnectionProperties; |
| 653 |
private int mVideoState; |
| 654 |
private VideoProvider mVideoProvider; |
| 655 |
private boolean mIsVoipAudioMode; |
| 656 |
private StatusHints mStatusHints; |
| 657 |
private Uri mAddress; |
| 658 |
private int mAddressPresentation; |
| 659 |
private String mCallerDisplayName; |
| 660 |
private int mCallerDisplayNamePresentation; |
| 661 |
private RemoteConference mConference; |
| 662 |
private Bundle mExtras; |
| 663 |
private String mCallingPackageAbbreviation; |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
RemoteConnection( |
| 669 |
String id, |
| 670 |
IConnectionService connectionService, |
| 671 |
ConnectionRequest request) { |
| 672 |
mConnectionId = id; |
| 673 |
mConnectionService = connectionService; |
| 674 |
mConnected = true; |
| 675 |
mState = Connection.STATE_INITIALIZING; |
| 676 |
if (request != null && request.getExtras() != null |
| 677 |
&& request.getExtras().containsKey( |
| 678 |
Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME)) { |
| 679 |
String callingPackage = request.getExtras().getString( |
| 680 |
Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME); |
| 681 |
mCallingPackageAbbreviation = Log.getPackageAbbreviation(callingPackage); |
| 682 |
} |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
RemoteConnection(String callId, IConnectionService connectionService, |
| 689 |
ParcelableConnection connection, String callingPackage, int targetSdkVersion) { |
| 690 |
mConnectionId = callId; |
| 691 |
mConnectionService = connectionService; |
| 692 |
mConnected = true; |
| 693 |
mState = connection.getState(); |
| 694 |
mDisconnectCause = connection.getDisconnectCause(); |
| 695 |
mRingbackRequested = connection.isRingbackRequested(); |
| 696 |
mConnectionCapabilities = connection.getConnectionCapabilities(); |
| 697 |
mConnectionProperties = connection.getConnectionProperties(); |
| 698 |
mVideoState = connection.getVideoState(); |
| 699 |
IVideoProvider videoProvider = connection.getVideoProvider(); |
| 700 |
if (videoProvider != null) { |
| 701 |
mVideoProvider = new RemoteConnection.VideoProvider(videoProvider, callingPackage, |
| 702 |
targetSdkVersion); |
| 703 |
} else { |
| 704 |
mVideoProvider = null; |
| 705 |
} |
| 706 |
mIsVoipAudioMode = connection.getIsVoipAudioMode(); |
| 707 |
mStatusHints = connection.getStatusHints(); |
| 708 |
mAddress = connection.getHandle(); |
| 709 |
mAddressPresentation = connection.getHandlePresentation(); |
| 710 |
mCallerDisplayName = connection.getCallerDisplayName(); |
| 711 |
mCallerDisplayNamePresentation = connection.getCallerDisplayNamePresentation(); |
| 712 |
mConference = null; |
| 713 |
putExtras(connection.getExtras()); |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
Bundle newExtras = new Bundle(); |
| 719 |
newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId); |
| 720 |
putExtras(newExtras); |
| 721 |
mCallingPackageAbbreviation = Log.getPackageAbbreviation(callingPackage); |
| 722 |
} |
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
RemoteConnection(DisconnectCause disconnectCause) { |
| 733 |
mConnectionId = "NULL"; |
| 734 |
mConnected = false; |
| 735 |
mState = Connection.STATE_DISCONNECTED; |
| 736 |
mDisconnectCause = disconnectCause; |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
public void registerCallback(Callback callback) { |
| 745 |
registerCallback(callback, new Handler()); |
| 746 |
} |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
public void registerCallback(Callback callback, Handler handler) { |
| 755 |
unregisterCallback(callback); |
| 756 |
if (callback != null && handler != null) { |
| 757 |
mCallbackRecords.add(new CallbackRecord(callback, handler)); |
| 758 |
} |
| 759 |
} |
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
public void unregisterCallback(Callback callback) { |
| 767 |
if (callback != null) { |
| 768 |
for (CallbackRecord record : mCallbackRecords) { |
| 769 |
if (record.getCallback() == callback) { |
| 770 |
mCallbackRecords.remove(record); |
| 771 |
break; |
| 772 |
} |
| 773 |
} |
| 774 |
} |
| 775 |
} |
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
public int getState() { |
| 783 |
return mState; |
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
public DisconnectCause getDisconnectCause() { |
| 794 |
return mDisconnectCause; |
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
public int getConnectionCapabilities() { |
| 804 |
return mConnectionCapabilities; |
| 805 |
} |
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
public int getConnectionProperties() { |
| 814 |
return mConnectionProperties; |
| 815 |
} |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
public boolean isVoipAudioMode() { |
| 823 |
return mIsVoipAudioMode; |
| 824 |
} |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
public StatusHints getStatusHints() { |
| 833 |
return mStatusHints; |
| 834 |
} |
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
public Uri getAddress() { |
| 843 |
return mAddress; |
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
public int getAddressPresentation() { |
| 853 |
return mAddressPresentation; |
| 854 |
} |
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
public CharSequence getCallerDisplayName() { |
| 862 |
return mCallerDisplayName; |
| 863 |
} |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
public int getCallerDisplayNamePresentation() { |
| 873 |
return mCallerDisplayNamePresentation; |
| 874 |
} |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
public int getVideoState() { |
| 882 |
return mVideoState; |
| 883 |
} |
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
public final VideoProvider getVideoProvider() { |
| 890 |
return mVideoProvider; |
| 891 |
} |
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
public final Bundle getExtras() { |
| 899 |
return mExtras; |
| 900 |
} |
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
public boolean isRingbackRequested() { |
| 909 |
return mRingbackRequested; |
| 910 |
} |
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
public void abort() { |
| 916 |
Log.startSession("RC.a", getActiveOwnerInfo()); |
| 917 |
try { |
| 918 |
if (mConnected) { |
| 919 |
mConnectionService.abort(mConnectionId, Log.getExternalSession( |
| 920 |
mCallingPackageAbbreviation)); |
| 921 |
} |
| 922 |
} catch (RemoteException ignored) { |
| 923 |
} finally { |
| 924 |
Log.endSession(); |
| 925 |
} |
| 926 |
} |
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
public void answer() { |
| 932 |
Log.startSession("RC.an", getActiveOwnerInfo()); |
| 933 |
try { |
| 934 |
if (mConnected) { |
| 935 |
mConnectionService.answer(mConnectionId, Log.getExternalSession( |
| 936 |
mCallingPackageAbbreviation)); |
| 937 |
} |
| 938 |
} catch (RemoteException ignored) { |
| 939 |
} finally { |
| 940 |
Log.endSession(); |
| 941 |
} |
| 942 |
} |
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
public void answer(int videoState) { |
| 950 |
Log.startSession("RC.an2", getActiveOwnerInfo()); |
| 951 |
try { |
| 952 |
if (mConnected) { |
| 953 |
mConnectionService.answerVideo(mConnectionId, videoState, |
| 954 |
Log.getExternalSession(mCallingPackageAbbreviation)); |
| 955 |
} |
| 956 |
} catch (RemoteException ignored) { |
| 957 |
} finally { |
| 958 |
Log.endSession(); |
| 959 |
} |
| 960 |
} |
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
public void reject() { |
| 966 |
Log.startSession("RC.r", getActiveOwnerInfo()); |
| 967 |
try { |
| 968 |
if (mConnected) { |
| 969 |
mConnectionService.reject(mConnectionId, Log.getExternalSession( |
| 970 |
mCallingPackageAbbreviation)); |
| 971 |
} |
| 972 |
} catch (RemoteException ignored) { |
| 973 |
} finally { |
| 974 |
Log.endSession(); |
| 975 |
} |
| 976 |
} |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
public void hold() { |
| 982 |
Log.startSession("RC.h", getActiveOwnerInfo()); |
| 983 |
try { |
| 984 |
if (mConnected) { |
| 985 |
mConnectionService.hold(mConnectionId, Log.getExternalSession( |
| 986 |
mCallingPackageAbbreviation)); |
| 987 |
} |
| 988 |
} catch (RemoteException ignored) { |
| 989 |
} finally { |
| 990 |
Log.endSession(); |
| 991 |
} |
| 992 |
} |
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
public void unhold() { |
| 998 |
Log.startSession("RC.u", getActiveOwnerInfo()); |
| 999 |
try { |
| 1000 |
if (mConnected) { |
| 1001 |
mConnectionService.unhold(mConnectionId, Log.getExternalSession( |
| 1002 |
mCallingPackageAbbreviation)); |
| 1003 |
} |
| 1004 |
} catch (RemoteException ignored) { |
| 1005 |
} finally { |
| 1006 |
Log.endSession(); |
| 1007 |
} |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
public void disconnect() { |
| 1014 |
Log.startSession("RC.d", getActiveOwnerInfo()); |
| 1015 |
try { |
| 1016 |
if (mConnected) { |
| 1017 |
mConnectionService.disconnect(mConnectionId, Log.getExternalSession( |
| 1018 |
mCallingPackageAbbreviation)); |
| 1019 |
} |
| 1020 |
} catch (RemoteException ignored) { |
| 1021 |
} finally { |
| 1022 |
Log.endSession(); |
| 1023 |
} |
| 1024 |
} |
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
public void playDtmfTone(char digit) { |
| 1036 |
Log.startSession("RC.pDT", getActiveOwnerInfo()); |
| 1037 |
try { |
| 1038 |
if (mConnected) { |
| 1039 |
mConnectionService.playDtmfTone(mConnectionId, digit, null ); |
| 1040 |
} |
| 1041 |
} catch (RemoteException ignored) { |
| 1042 |
} finally { |
| 1043 |
Log.endSession(); |
| 1044 |
} |
| 1045 |
} |
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
public void stopDtmfTone() { |
| 1055 |
Log.startSession("RC.sDT", getActiveOwnerInfo()); |
| 1056 |
try { |
| 1057 |
if (mConnected) { |
| 1058 |
mConnectionService.stopDtmfTone(mConnectionId, null ); |
| 1059 |
} |
| 1060 |
} catch (RemoteException ignored) { |
| 1061 |
} finally { |
| 1062 |
Log.endSession(); |
| 1063 |
} |
| 1064 |
} |
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
public void postDialContinue(boolean proceed) { |
| 1088 |
Log.startSession("RC.pDC", getActiveOwnerInfo()); |
| 1089 |
try { |
| 1090 |
if (mConnected) { |
| 1091 |
mConnectionService.onPostDialContinue(mConnectionId, proceed, |
| 1092 |
null ); |
| 1093 |
} |
| 1094 |
} catch (RemoteException ignored) { |
| 1095 |
|
| 1096 |
} finally { |
| 1097 |
Log.endSession(); |
| 1098 |
} |
| 1099 |
} |
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
public void pullExternalCall() { |
| 1107 |
Log.startSession("RC.pEC", getActiveOwnerInfo()); |
| 1108 |
try { |
| 1109 |
if (mConnected) { |
| 1110 |
mConnectionService.pullExternalCall(mConnectionId, null ); |
| 1111 |
} |
| 1112 |
} catch (RemoteException ignored) { |
| 1113 |
} finally { |
| 1114 |
Log.endSession(); |
| 1115 |
} |
| 1116 |
} |
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
public void addConferenceParticipants(@NonNull List<Uri> participants) { |
| 1126 |
try { |
| 1127 |
if (mConnected) { |
| 1128 |
mConnectionService.addConferenceParticipants(mConnectionId, participants, |
| 1129 |
null ); |
| 1130 |
} |
| 1131 |
} catch (RemoteException ignored) { |
| 1132 |
} |
| 1133 |
} |
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
@SystemApi |
| 1143 |
@Deprecated |
| 1144 |
public void setAudioState(AudioState state) { |
| 1145 |
setCallAudioState(new CallAudioState(state)); |
| 1146 |
} |
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
public void setCallAudioState(CallAudioState state) { |
| 1154 |
Log.startSession("RC.sCAS", getActiveOwnerInfo()); |
| 1155 |
try { |
| 1156 |
if (mConnected) { |
| 1157 |
mConnectionService.onCallAudioStateChanged(mConnectionId, state, |
| 1158 |
null ); |
| 1159 |
} |
| 1160 |
} catch (RemoteException ignored) { |
| 1161 |
} finally { |
| 1162 |
Log.endSession(); |
| 1163 |
} |
| 1164 |
} |
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
public void startRtt(@NonNull Connection.RttTextStream rttTextStream) { |
| 1173 |
Log.startSession("RC.sR", getActiveOwnerInfo()); |
| 1174 |
try { |
| 1175 |
if (mConnected) { |
| 1176 |
mConnectionService.startRtt(mConnectionId, rttTextStream.getFdFromInCall(), |
| 1177 |
rttTextStream.getFdToInCall(), null ); |
| 1178 |
} |
| 1179 |
} catch (RemoteException ignored) { |
| 1180 |
} finally { |
| 1181 |
Log.endSession(); |
| 1182 |
} |
| 1183 |
} |
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
public void stopRtt() { |
| 1191 |
Log.startSession("RC.stR", getActiveOwnerInfo()); |
| 1192 |
try { |
| 1193 |
if (mConnected) { |
| 1194 |
mConnectionService.stopRtt(mConnectionId, null ); |
| 1195 |
} |
| 1196 |
} catch (RemoteException ignored) { |
| 1197 |
} finally { |
| 1198 |
Log.endSession(); |
| 1199 |
} |
| 1200 |
} |
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
@SystemApi |
| 1210 |
@RequiresPermission(Manifest.permission.READ_CONTACTS) |
| 1211 |
public void onCallFilteringCompleted( |
| 1212 |
@NonNull Connection.CallFilteringCompletionInfo completionInfo) { |
| 1213 |
Log.startSession("RC.oCFC", getActiveOwnerInfo()); |
| 1214 |
try { |
| 1215 |
if (mConnected) { |
| 1216 |
mConnectionService.onCallFilteringCompleted(mConnectionId, completionInfo, |
| 1217 |
null ); |
| 1218 |
} |
| 1219 |
} catch (RemoteException ignored) { |
| 1220 |
} finally { |
| 1221 |
Log.endSession(); |
| 1222 |
} |
| 1223 |
} |
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
public void sendRttUpgradeResponse(@Nullable Connection.RttTextStream rttTextStream) { |
| 1235 |
Log.startSession("RC.sRUR", getActiveOwnerInfo()); |
| 1236 |
try { |
| 1237 |
if (mConnected) { |
| 1238 |
if (rttTextStream == null) { |
| 1239 |
mConnectionService.respondToRttUpgradeRequest(mConnectionId, |
| 1240 |
null, null, null ); |
| 1241 |
} else { |
| 1242 |
mConnectionService.respondToRttUpgradeRequest(mConnectionId, |
| 1243 |
rttTextStream.getFdFromInCall(), rttTextStream.getFdToInCall(), |
| 1244 |
null ); |
| 1245 |
} |
| 1246 |
} |
| 1247 |
} catch (RemoteException ignored) { |
| 1248 |
} finally { |
| 1249 |
Log.endSession(); |
| 1250 |
} |
| 1251 |
} |
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
public List<RemoteConnection> getConferenceableConnections() { |
| 1261 |
return mUnmodifiableconferenceableConnections; |
| 1262 |
} |
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
public RemoteConference getConference() { |
| 1271 |
return mConference; |
| 1272 |
} |
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
private String getActiveOwnerInfo() { |
| 1283 |
Session.Info info = Log.getExternalSession(); |
| 1284 |
if (info == null) { |
| 1285 |
return null; |
| 1286 |
} |
| 1287 |
return info.ownerInfo; |
| 1288 |
} |
| 1289 |
|
| 1290 |
|
| 1291 |
String getId() { |
| 1292 |
return mConnectionId; |
| 1293 |
} |
| 1294 |
|
| 1295 |
|
| 1296 |
IConnectionService getConnectionService() { |
| 1297 |
return mConnectionService; |
| 1298 |
} |
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
void setState(final int state) { |
| 1304 |
if (mState != state) { |
| 1305 |
mState = state; |
| 1306 |
for (CallbackRecord record: mCallbackRecords) { |
| 1307 |
final RemoteConnection connection = this; |
| 1308 |
final Callback callback = record.getCallback(); |
| 1309 |
record.getHandler().post(new Runnable() { |
| 1310 |
@Override |
| 1311 |
public void run() { |
| 1312 |
callback.onStateChanged(connection, state); |
| 1313 |
} |
| 1314 |
}); |
| 1315 |
} |
| 1316 |
} |
| 1317 |
} |
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
void setDisconnected(final DisconnectCause disconnectCause) { |
| 1323 |
if (mState != Connection.STATE_DISCONNECTED) { |
| 1324 |
mState = Connection.STATE_DISCONNECTED; |
| 1325 |
mDisconnectCause = disconnectCause; |
| 1326 |
|
| 1327 |
for (CallbackRecord record : mCallbackRecords) { |
| 1328 |
final RemoteConnection connection = this; |
| 1329 |
final Callback callback = record.getCallback(); |
| 1330 |
record.getHandler().post(new Runnable() { |
| 1331 |
@Override |
| 1332 |
public void run() { |
| 1333 |
callback.onDisconnected(connection, disconnectCause); |
| 1334 |
} |
| 1335 |
}); |
| 1336 |
} |
| 1337 |
} |
| 1338 |
} |
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
void setRingbackRequested(final boolean ringback) { |
| 1344 |
if (mRingbackRequested != ringback) { |
| 1345 |
mRingbackRequested = ringback; |
| 1346 |
for (CallbackRecord record : mCallbackRecords) { |
| 1347 |
final RemoteConnection connection = this; |
| 1348 |
final Callback callback = record.getCallback(); |
| 1349 |
record.getHandler().post(new Runnable() { |
| 1350 |
@Override |
| 1351 |
public void run() { |
| 1352 |
callback.onRingbackRequested(connection, ringback); |
| 1353 |
} |
| 1354 |
}); |
| 1355 |
} |
| 1356 |
} |
| 1357 |
} |
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
void setConnectionCapabilities(final int connectionCapabilities) { |
| 1363 |
mConnectionCapabilities = connectionCapabilities; |
| 1364 |
for (CallbackRecord record : mCallbackRecords) { |
| 1365 |
final RemoteConnection connection = this; |
| 1366 |
final Callback callback = record.getCallback(); |
| 1367 |
record.getHandler().post(new Runnable() { |
| 1368 |
@Override |
| 1369 |
public void run() { |
| 1370 |
callback.onConnectionCapabilitiesChanged(connection, connectionCapabilities); |
| 1371 |
} |
| 1372 |
}); |
| 1373 |
} |
| 1374 |
} |
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
void setConnectionProperties(final int connectionProperties) { |
| 1380 |
mConnectionProperties = connectionProperties; |
| 1381 |
for (CallbackRecord record : mCallbackRecords) { |
| 1382 |
final RemoteConnection connection = this; |
| 1383 |
final Callback callback = record.getCallback(); |
| 1384 |
record.getHandler().post(new Runnable() { |
| 1385 |
@Override |
| 1386 |
public void run() { |
| 1387 |
callback.onConnectionPropertiesChanged(connection, connectionProperties); |
| 1388 |
} |
| 1389 |
}); |
| 1390 |
} |
| 1391 |
} |
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
void setDestroyed() { |
| 1397 |
if (!mCallbackRecords.isEmpty()) { |
| 1398 |
|
| 1399 |
if (mState != Connection.STATE_DISCONNECTED) { |
| 1400 |
setDisconnected( |
| 1401 |
new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed.")); |
| 1402 |
} |
| 1403 |
|
| 1404 |
for (CallbackRecord record : mCallbackRecords) { |
| 1405 |
final RemoteConnection connection = this; |
| 1406 |
final Callback callback = record.getCallback(); |
| 1407 |
record.getHandler().post(new Runnable() { |
| 1408 |
@Override |
| 1409 |
public void run() { |
| 1410 |
callback.onDestroyed(connection); |
| 1411 |
} |
| 1412 |
}); |
| 1413 |
} |
| 1414 |
mCallbackRecords.clear(); |
| 1415 |
|
| 1416 |
mConnected = false; |
| 1417 |
} |
| 1418 |
} |
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
void setPostDialWait(final String remainingDigits) { |
| 1424 |
for (CallbackRecord record : mCallbackRecords) { |
| 1425 |
final RemoteConnection connection = this; |
| 1426 |
final Callback callback = record.getCallback(); |
| 1427 |
record.getHandler().post(new Runnable() { |
| 1428 |
@Override |
| 1429 |
public void run() { |
| 1430 |
callback.onPostDialWait(connection, remainingDigits); |
| 1431 |
} |
| 1432 |
}); |
| 1433 |
} |
| 1434 |
} |
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
void onPostDialChar(final char nextChar) { |
| 1440 |
for (CallbackRecord record : mCallbackRecords) { |
| 1441 |
final RemoteConnection connection = this; |
| 1442 |
final Callback callback = record.getCallback(); |
| 1443 |
record.getHandler().post(new Runnable() { |
| 1444 |
@Override |
| 1445 |
public void run() { |
| 1446 |
callback.onPostDialChar(connection, nextChar); |
| 1447 |
} |
| 1448 |
}); |
| 1449 |
} |
| 1450 |
} |
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
void setVideoState(final int videoState) { |
| 1456 |
mVideoState = videoState; |
| 1457 |
for (CallbackRecord record : mCallbackRecords) { |
| 1458 |
final RemoteConnection connection = this; |
| 1459 |
final Callback callback = record.getCallback(); |
| 1460 |
record.getHandler().post(new Runnable() { |
| 1461 |
@Override |
| 1462 |
public void run() { |
| 1463 |
callback.onVideoStateChanged(connection, videoState); |
| 1464 |
} |
| 1465 |
}); |
| 1466 |
} |
| 1467 |
} |
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
void setVideoProvider(final VideoProvider videoProvider) { |
| 1473 |
mVideoProvider = videoProvider; |
| 1474 |
for (CallbackRecord record : mCallbackRecords) { |
| 1475 |
final RemoteConnection connection = this; |
| 1476 |
final Callback callback = record.getCallback(); |
| 1477 |
record.getHandler().post(new Runnable() { |
| 1478 |
@Override |
| 1479 |
public void run() { |
| 1480 |
callback.onVideoProviderChanged(connection, videoProvider); |
| 1481 |
} |
| 1482 |
}); |
| 1483 |
} |
| 1484 |
} |
| 1485 |
|
| 1486 |
|
| 1487 |
void setIsVoipAudioMode(final boolean isVoip) { |
| 1488 |
mIsVoipAudioMode = isVoip; |
| 1489 |
for (CallbackRecord record : mCallbackRecords) { |
| 1490 |
final RemoteConnection connection = this; |
| 1491 |
final Callback callback = record.getCallback(); |
| 1492 |
record.getHandler().post(new Runnable() { |
| 1493 |
@Override |
| 1494 |
public void run() { |
| 1495 |
callback.onVoipAudioChanged(connection, isVoip); |
| 1496 |
} |
| 1497 |
}); |
| 1498 |
} |
| 1499 |
} |
| 1500 |
|
| 1501 |
|
| 1502 |
void setStatusHints(final StatusHints statusHints) { |
| 1503 |
mStatusHints = statusHints; |
| 1504 |
for (CallbackRecord record : mCallbackRecords) { |
| 1505 |
final RemoteConnection connection = this; |
| 1506 |
final Callback callback = record.getCallback(); |
| 1507 |
record.getHandler().post(new Runnable() { |
| 1508 |
@Override |
| 1509 |
public void run() { |
| 1510 |
callback.onStatusHintsChanged(connection, statusHints); |
| 1511 |
} |
| 1512 |
}); |
| 1513 |
} |
| 1514 |
} |
| 1515 |
|
| 1516 |
|
| 1517 |
void setAddress(final Uri address, final int presentation) { |
| 1518 |
mAddress = address; |
| 1519 |
mAddressPresentation = presentation; |
| 1520 |
for (CallbackRecord record : mCallbackRecords) { |
| 1521 |
final RemoteConnection connection = this; |
| 1522 |
final Callback callback = record.getCallback(); |
| 1523 |
record.getHandler().post(new Runnable() { |
| 1524 |
@Override |
| 1525 |
public void run() { |
| 1526 |
callback.onAddressChanged(connection, address, presentation); |
| 1527 |
} |
| 1528 |
}); |
| 1529 |
} |
| 1530 |
} |
| 1531 |
|
| 1532 |
|
| 1533 |
void setCallerDisplayName(final String callerDisplayName, final int presentation) { |
| 1534 |
mCallerDisplayName = callerDisplayName; |
| 1535 |
mCallerDisplayNamePresentation = presentation; |
| 1536 |
for (CallbackRecord record : mCallbackRecords) { |
| 1537 |
final RemoteConnection connection = this; |
| 1538 |
final Callback callback = record.getCallback(); |
| 1539 |
record.getHandler().post(new Runnable() { |
| 1540 |
@Override |
| 1541 |
public void run() { |
| 1542 |
callback.onCallerDisplayNameChanged( |
| 1543 |
connection, callerDisplayName, presentation); |
| 1544 |
} |
| 1545 |
}); |
| 1546 |
} |
| 1547 |
} |
| 1548 |
|
| 1549 |
|
| 1550 |
void setConferenceableConnections(final List<RemoteConnection> conferenceableConnections) { |
| 1551 |
mConferenceableConnections.clear(); |
| 1552 |
mConferenceableConnections.addAll(conferenceableConnections); |
| 1553 |
for (CallbackRecord record : mCallbackRecords) { |
| 1554 |
final RemoteConnection connection = this; |
| 1555 |
final Callback callback = record.getCallback(); |
| 1556 |
record.getHandler().post(new Runnable() { |
| 1557 |
@Override |
| 1558 |
public void run() { |
| 1559 |
callback.onConferenceableConnectionsChanged( |
| 1560 |
connection, mUnmodifiableconferenceableConnections); |
| 1561 |
} |
| 1562 |
}); |
| 1563 |
} |
| 1564 |
} |
| 1565 |
|
| 1566 |
|
| 1567 |
void setConference(final RemoteConference conference) { |
| 1568 |
if (mConference != conference) { |
| 1569 |
mConference = conference; |
| 1570 |
for (CallbackRecord record : mCallbackRecords) { |
| 1571 |
final RemoteConnection connection = this; |
| 1572 |
final Callback callback = record.getCallback(); |
| 1573 |
record.getHandler().post(new Runnable() { |
| 1574 |
@Override |
| 1575 |
public void run() { |
| 1576 |
callback.onConferenceChanged(connection, conference); |
| 1577 |
} |
| 1578 |
}); |
| 1579 |
} |
| 1580 |
} |
| 1581 |
} |
| 1582 |
|
| 1583 |
|
| 1584 |
void putExtras(final Bundle extras) { |
| 1585 |
if (extras == null) { |
| 1586 |
return; |
| 1587 |
} |
| 1588 |
if (mExtras == null) { |
| 1589 |
mExtras = new Bundle(); |
| 1590 |
} |
| 1591 |
try { |
| 1592 |
mExtras.putAll(extras); |
| 1593 |
} catch (BadParcelableException bpe) { |
| 1594 |
Log.w(this, "putExtras: could not unmarshal extras; exception = " + bpe); |
| 1595 |
} |
| 1596 |
|
| 1597 |
notifyExtrasChanged(); |
| 1598 |
} |
| 1599 |
|
| 1600 |
|
| 1601 |
void removeExtras(List<String> keys) { |
| 1602 |
if (mExtras == null || keys == null || keys.isEmpty()) { |
| 1603 |
return; |
| 1604 |
} |
| 1605 |
for (String key : keys) { |
| 1606 |
mExtras.remove(key); |
| 1607 |
} |
| 1608 |
|
| 1609 |
notifyExtrasChanged(); |
| 1610 |
} |
| 1611 |
|
| 1612 |
private void notifyExtrasChanged() { |
| 1613 |
for (CallbackRecord record : mCallbackRecords) { |
| 1614 |
final RemoteConnection connection = this; |
| 1615 |
final Callback callback = record.getCallback(); |
| 1616 |
record.getHandler().post(new Runnable() { |
| 1617 |
@Override |
| 1618 |
public void run() { |
| 1619 |
callback.onExtrasChanged(connection, mExtras); |
| 1620 |
} |
| 1621 |
}); |
| 1622 |
} |
| 1623 |
} |
| 1624 |
|
| 1625 |
|
| 1626 |
void onConnectionEvent(final String event, final Bundle extras) { |
| 1627 |
for (CallbackRecord record : mCallbackRecords) { |
| 1628 |
final RemoteConnection connection = this; |
| 1629 |
final Callback callback = record.getCallback(); |
| 1630 |
record.getHandler().post(new Runnable() { |
| 1631 |
@Override |
| 1632 |
public void run() { |
| 1633 |
callback.onConnectionEvent(connection, event, extras); |
| 1634 |
} |
| 1635 |
}); |
| 1636 |
} |
| 1637 |
} |
| 1638 |
|
| 1639 |
|
| 1640 |
void onRttInitiationSuccess() { |
| 1641 |
for (CallbackRecord record : mCallbackRecords) { |
| 1642 |
final RemoteConnection connection = this; |
| 1643 |
final Callback callback = record.getCallback(); |
| 1644 |
record.getHandler().post( |
| 1645 |
() -> callback.onRttInitiationSuccess(connection)); |
| 1646 |
} |
| 1647 |
} |
| 1648 |
|
| 1649 |
|
| 1650 |
void onRttInitiationFailure(int reason) { |
| 1651 |
for (CallbackRecord record : mCallbackRecords) { |
| 1652 |
final RemoteConnection connection = this; |
| 1653 |
final Callback callback = record.getCallback(); |
| 1654 |
record.getHandler().post( |
| 1655 |
() -> callback.onRttInitiationFailure(connection, reason)); |
| 1656 |
} |
| 1657 |
} |
| 1658 |
|
| 1659 |
|
| 1660 |
void onRttSessionRemotelyTerminated() { |
| 1661 |
for (CallbackRecord record : mCallbackRecords) { |
| 1662 |
final RemoteConnection connection = this; |
| 1663 |
final Callback callback = record.getCallback(); |
| 1664 |
record.getHandler().post( |
| 1665 |
() -> callback.onRttSessionRemotelyTerminated(connection)); |
| 1666 |
} |
| 1667 |
} |
| 1668 |
|
| 1669 |
|
| 1670 |
void onRemoteRttRequest() { |
| 1671 |
for (CallbackRecord record : mCallbackRecords) { |
| 1672 |
final RemoteConnection connection = this; |
| 1673 |
final Callback callback = record.getCallback(); |
| 1674 |
record.getHandler().post( |
| 1675 |
() -> callback.onRemoteRttRequest(connection)); |
| 1676 |
} |
| 1677 |
} |
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
public static RemoteConnection failure(DisconnectCause disconnectCause) { |
| 1690 |
return new RemoteConnection(disconnectCause); |
| 1691 |
} |
| 1692 |
|
| 1693 |
private static final class CallbackRecord extends Callback { |
| 1694 |
private final Callback mCallback; |
| 1695 |
private final Handler mHandler; |
| 1696 |
|
| 1697 |
public CallbackRecord(Callback callback, Handler handler) { |
| 1698 |
mCallback = callback; |
| 1699 |
mHandler = handler; |
| 1700 |
} |
| 1701 |
|
| 1702 |
public Callback getCallback() { |
| 1703 |
return mCallback; |
| 1704 |
} |
| 1705 |
|
| 1706 |
public Handler getHandler() { |
| 1707 |
return mHandler; |
| 1708 |
} |
| 1709 |
} |
| 1710 |
} |