| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.telecom; |
| 18 |
|
| 19 |
import android.annotation.Nullable; |
| 20 |
import android.annotation.SystemApi; |
| 21 |
import android.os.Bundle; |
| 22 |
import android.os.Handler; |
| 23 |
import android.os.RemoteException; |
| 24 |
|
| 25 |
import com.android.internal.telecom.IConnectionService; |
| 26 |
|
| 27 |
import java.util.ArrayList; |
| 28 |
import java.util.Collections; |
| 29 |
import java.util.List; |
| 30 |
import java.util.Set; |
| 31 |
import java.util.concurrent.CopyOnWriteArrayList; |
| 32 |
import java.util.concurrent.CopyOnWriteArraySet; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public final class RemoteConference { |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public abstract static class Callback { |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public void onStateChanged(RemoteConference conference, int oldState, int newState) {} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public void onDisconnected(RemoteConference conference, DisconnectCause disconnectCause) {} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public void onConnectionAdded(RemoteConference conference, RemoteConnection connection) {} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public void onConnectionRemoved(RemoteConference conference, RemoteConnection connection) {} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public void onConnectionCapabilitiesChanged( |
| 91 |
RemoteConference conference, |
| 92 |
int connectionCapabilities) {} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public void onConnectionPropertiesChanged( |
| 102 |
RemoteConference conference, |
| 103 |
int connectionProperties) {} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
public void onConferenceableConnectionsChanged( |
| 114 |
RemoteConference conference, |
| 115 |
List<RemoteConnection> conferenceableConnections) {} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
public void onDestroyed(RemoteConference conference) {} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
public void onExtrasChanged(RemoteConference conference, @Nullable Bundle extras) {} |
| 132 |
} |
| 133 |
|
| 134 |
private final String mId; |
| 135 |
private final IConnectionService mConnectionService; |
| 136 |
|
| 137 |
private final Set<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArraySet<>(); |
| 138 |
private final List<RemoteConnection> mChildConnections = new CopyOnWriteArrayList<>(); |
| 139 |
private final List<RemoteConnection> mUnmodifiableChildConnections = |
| 140 |
Collections.unmodifiableList(mChildConnections); |
| 141 |
private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>(); |
| 142 |
private final List<RemoteConnection> mUnmodifiableConferenceableConnections = |
| 143 |
Collections.unmodifiableList(mConferenceableConnections); |
| 144 |
|
| 145 |
private int mState = Connection.STATE_NEW; |
| 146 |
private DisconnectCause mDisconnectCause; |
| 147 |
private int mConnectionCapabilities; |
| 148 |
private int mConnectionProperties; |
| 149 |
private Bundle mExtras; |
| 150 |
|
| 151 |
|
| 152 |
RemoteConference(String id, IConnectionService connectionService) { |
| 153 |
mId = id; |
| 154 |
mConnectionService = connectionService; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
RemoteConference(DisconnectCause disconnectCause) { |
| 159 |
mId = "NULL"; |
| 160 |
mConnectionService = null; |
| 161 |
mState = Connection.STATE_DISCONNECTED; |
| 162 |
mDisconnectCause = disconnectCause; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
String getId() { |
| 167 |
return mId; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
void setDestroyed() { |
| 172 |
for (RemoteConnection connection : mChildConnections) { |
| 173 |
connection.setConference(null); |
| 174 |
} |
| 175 |
for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 176 |
final RemoteConference conference = this; |
| 177 |
final Callback callback = record.getCallback(); |
| 178 |
record.getHandler().post(new Runnable() { |
| 179 |
@Override |
| 180 |
public void run() { |
| 181 |
callback.onDestroyed(conference); |
| 182 |
} |
| 183 |
}); |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
void setState(final int newState) { |
| 189 |
if (newState != Connection.STATE_ACTIVE && |
| 190 |
newState != Connection.STATE_HOLDING && |
| 191 |
newState != Connection.STATE_DISCONNECTED) { |
| 192 |
Log.w(this, "Unsupported state transition for Conference call.", |
| 193 |
Connection.stateToString(newState)); |
| 194 |
return; |
| 195 |
} |
| 196 |
|
| 197 |
if (mState != newState) { |
| 198 |
final int oldState = mState; |
| 199 |
mState = newState; |
| 200 |
for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 201 |
final RemoteConference conference = this; |
| 202 |
final Callback callback = record.getCallback(); |
| 203 |
record.getHandler().post(new Runnable() { |
| 204 |
@Override |
| 205 |
public void run() { |
| 206 |
callback.onStateChanged(conference, oldState, newState); |
| 207 |
} |
| 208 |
}); |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
void addConnection(final RemoteConnection connection) { |
| 215 |
if (!mChildConnections.contains(connection)) { |
| 216 |
mChildConnections.add(connection); |
| 217 |
connection.setConference(this); |
| 218 |
for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 219 |
final RemoteConference conference = this; |
| 220 |
final Callback callback = record.getCallback(); |
| 221 |
record.getHandler().post(new Runnable() { |
| 222 |
@Override |
| 223 |
public void run() { |
| 224 |
callback.onConnectionAdded(conference, connection); |
| 225 |
} |
| 226 |
}); |
| 227 |
} |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
void removeConnection(final RemoteConnection connection) { |
| 233 |
if (mChildConnections.contains(connection)) { |
| 234 |
mChildConnections.remove(connection); |
| 235 |
connection.setConference(null); |
| 236 |
for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 237 |
final RemoteConference conference = this; |
| 238 |
final Callback callback = record.getCallback(); |
| 239 |
record.getHandler().post(new Runnable() { |
| 240 |
@Override |
| 241 |
public void run() { |
| 242 |
callback.onConnectionRemoved(conference, connection); |
| 243 |
} |
| 244 |
}); |
| 245 |
} |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
void setConnectionCapabilities(final int connectionCapabilities) { |
| 251 |
if (mConnectionCapabilities != connectionCapabilities) { |
| 252 |
mConnectionCapabilities = connectionCapabilities; |
| 253 |
for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 254 |
final RemoteConference conference = this; |
| 255 |
final Callback callback = record.getCallback(); |
| 256 |
record.getHandler().post(new Runnable() { |
| 257 |
@Override |
| 258 |
public void run() { |
| 259 |
callback.onConnectionCapabilitiesChanged( |
| 260 |
conference, mConnectionCapabilities); |
| 261 |
} |
| 262 |
}); |
| 263 |
} |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
void setConnectionProperties(final int connectionProperties) { |
| 269 |
if (mConnectionProperties != connectionProperties) { |
| 270 |
mConnectionProperties = connectionProperties; |
| 271 |
for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 272 |
final RemoteConference conference = this; |
| 273 |
final Callback callback = record.getCallback(); |
| 274 |
record.getHandler().post(new Runnable() { |
| 275 |
@Override |
| 276 |
public void run() { |
| 277 |
callback.onConnectionPropertiesChanged( |
| 278 |
conference, mConnectionProperties); |
| 279 |
} |
| 280 |
}); |
| 281 |
} |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
void setConferenceableConnections(List<RemoteConnection> conferenceableConnections) { |
| 287 |
mConferenceableConnections.clear(); |
| 288 |
mConferenceableConnections.addAll(conferenceableConnections); |
| 289 |
for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 290 |
final RemoteConference conference = this; |
| 291 |
final Callback callback = record.getCallback(); |
| 292 |
record.getHandler().post(new Runnable() { |
| 293 |
@Override |
| 294 |
public void run() { |
| 295 |
callback.onConferenceableConnectionsChanged( |
| 296 |
conference, mUnmodifiableConferenceableConnections); |
| 297 |
} |
| 298 |
}); |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
void setDisconnected(final DisconnectCause disconnectCause) { |
| 304 |
if (mState != Connection.STATE_DISCONNECTED) { |
| 305 |
mDisconnectCause = disconnectCause; |
| 306 |
setState(Connection.STATE_DISCONNECTED); |
| 307 |
for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 308 |
final RemoteConference conference = this; |
| 309 |
final Callback callback = record.getCallback(); |
| 310 |
record.getHandler().post(new Runnable() { |
| 311 |
@Override |
| 312 |
public void run() { |
| 313 |
callback.onDisconnected(conference, disconnectCause); |
| 314 |
} |
| 315 |
}); |
| 316 |
} |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
void putExtras(final Bundle extras) { |
| 322 |
if (extras == null) { |
| 323 |
return; |
| 324 |
} |
| 325 |
if (mExtras == null) { |
| 326 |
mExtras = new Bundle(); |
| 327 |
} |
| 328 |
mExtras.putAll(extras); |
| 329 |
|
| 330 |
notifyExtrasChanged(); |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
void removeExtras(List<String> keys) { |
| 335 |
if (mExtras == null || keys == null || keys.isEmpty()) { |
| 336 |
return; |
| 337 |
} |
| 338 |
for (String key : keys) { |
| 339 |
mExtras.remove(key); |
| 340 |
} |
| 341 |
|
| 342 |
notifyExtrasChanged(); |
| 343 |
} |
| 344 |
|
| 345 |
private void notifyExtrasChanged() { |
| 346 |
for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 347 |
final RemoteConference conference = this; |
| 348 |
final Callback callback = record.getCallback(); |
| 349 |
record.getHandler().post(new Runnable() { |
| 350 |
@Override |
| 351 |
public void run() { |
| 352 |
callback.onExtrasChanged(conference, mExtras); |
| 353 |
} |
| 354 |
}); |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
public final List<RemoteConnection> getConnections() { |
| 364 |
return mUnmodifiableChildConnections; |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
public final int getState() { |
| 373 |
return mState; |
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
public final int getConnectionCapabilities() { |
| 383 |
return mConnectionCapabilities; |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
public final int getConnectionProperties() { |
| 393 |
return mConnectionProperties; |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
public final Bundle getExtras() { |
| 402 |
return mExtras; |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
public void disconnect() { |
| 409 |
try { |
| 410 |
mConnectionService.disconnect(mId, null ); |
| 411 |
} catch (RemoteException e) { |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
public void separate(RemoteConnection connection) { |
| 423 |
if (mChildConnections.contains(connection)) { |
| 424 |
try { |
| 425 |
mConnectionService.splitFromConference(connection.getId(), null ); |
| 426 |
} catch (RemoteException e) { |
| 427 |
} |
| 428 |
} |
| 429 |
} |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
public void merge() { |
| 442 |
try { |
| 443 |
mConnectionService.mergeConference(mId, null ); |
| 444 |
} catch (RemoteException e) { |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
public void swap() { |
| 458 |
try { |
| 459 |
mConnectionService.swapConference(mId, null ); |
| 460 |
} catch (RemoteException e) { |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
public void hold() { |
| 468 |
try { |
| 469 |
mConnectionService.hold(mId, null ); |
| 470 |
} catch (RemoteException e) { |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
public void unhold() { |
| 478 |
try { |
| 479 |
mConnectionService.unhold(mId, null ); |
| 480 |
} catch (RemoteException e) { |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
public DisconnectCause getDisconnectCause() { |
| 492 |
return mDisconnectCause; |
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
public void playDtmfTone(char digit) { |
| 501 |
try { |
| 502 |
mConnectionService.playDtmfTone(mId, digit, null ); |
| 503 |
} catch (RemoteException e) { |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
public void stopDtmfTone() { |
| 513 |
try { |
| 514 |
mConnectionService.stopDtmfTone(mId, null ); |
| 515 |
} catch (RemoteException e) { |
| 516 |
} |
| 517 |
} |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
@SystemApi |
| 528 |
@Deprecated |
| 529 |
public void setAudioState(AudioState state) { |
| 530 |
setCallAudioState(new CallAudioState(state)); |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
public void setCallAudioState(CallAudioState state) { |
| 538 |
try { |
| 539 |
mConnectionService.onCallAudioStateChanged(mId, state, null ); |
| 540 |
} catch (RemoteException e) { |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
public List<RemoteConnection> getConferenceableConnections() { |
| 551 |
return mUnmodifiableConferenceableConnections; |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
public final void registerCallback(Callback callback) { |
| 560 |
registerCallback(callback, new Handler()); |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
public final void registerCallback(Callback callback, Handler handler) { |
| 571 |
unregisterCallback(callback); |
| 572 |
if (callback != null && handler != null) { |
| 573 |
mCallbackRecords.add(new CallbackRecord(callback, handler)); |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
public final void unregisterCallback(Callback callback) { |
| 585 |
if (callback != null) { |
| 586 |
for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 587 |
if (record.getCallback() == callback) { |
| 588 |
mCallbackRecords.remove(record); |
| 589 |
break; |
| 590 |
} |
| 591 |
} |
| 592 |
} |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
public static RemoteConference failure(DisconnectCause disconnectCause) { |
| 604 |
return new RemoteConference(disconnectCause); |
| 605 |
} |
| 606 |
} |