| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.telecom; |
| 18 |
|
| 19 |
import android.content.ComponentName; |
| 20 |
import android.os.RemoteException; |
| 21 |
|
| 22 |
import com.android.internal.telecom.IConnectionService; |
| 23 |
|
| 24 |
import java.util.HashMap; |
| 25 |
import java.util.Map; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public class RemoteConnectionManager { |
| 31 |
private final Map<ComponentName, RemoteConnectionService> mRemoteConnectionServices = |
| 32 |
new HashMap<>(); |
| 33 |
private final ConnectionService mOurConnectionServiceImpl; |
| 34 |
|
| 35 |
public RemoteConnectionManager(ConnectionService ourConnectionServiceImpl) { |
| 36 |
mOurConnectionServiceImpl = ourConnectionServiceImpl; |
| 37 |
} |
| 38 |
|
| 39 |
void addConnectionService( |
| 40 |
ComponentName componentName, |
| 41 |
IConnectionService outgoingConnectionServiceRpc) { |
| 42 |
if (!mRemoteConnectionServices.containsKey(componentName)) { |
| 43 |
try { |
| 44 |
RemoteConnectionService remoteConnectionService = new RemoteConnectionService( |
| 45 |
outgoingConnectionServiceRpc, |
| 46 |
mOurConnectionServiceImpl); |
| 47 |
mRemoteConnectionServices.put(componentName, remoteConnectionService); |
| 48 |
} catch (RemoteException e) { |
| 49 |
Log.w(RemoteConnectionManager.this, |
| 50 |
"error when addConnectionService of %s: %s", componentName, |
| 51 |
e.toString()); |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
public RemoteConnection createRemoteConnection( |
| 57 |
PhoneAccountHandle connectionManagerPhoneAccount, |
| 58 |
ConnectionRequest request, |
| 59 |
boolean isIncoming) { |
| 60 |
PhoneAccountHandle accountHandle = request.getAccountHandle(); |
| 61 |
if (accountHandle == null) { |
| 62 |
throw new IllegalArgumentException("accountHandle must be specified."); |
| 63 |
} |
| 64 |
|
| 65 |
ComponentName componentName = request.getAccountHandle().getComponentName(); |
| 66 |
if (!mRemoteConnectionServices.containsKey(componentName)) { |
| 67 |
throw new UnsupportedOperationException("accountHandle not supported: " |
| 68 |
+ componentName); |
| 69 |
} |
| 70 |
|
| 71 |
RemoteConnectionService remoteService = mRemoteConnectionServices.get(componentName); |
| 72 |
if (remoteService != null) { |
| 73 |
return remoteService.createRemoteConnection( |
| 74 |
connectionManagerPhoneAccount, request, isIncoming); |
| 75 |
} |
| 76 |
return null; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public RemoteConference createRemoteConference( |
| 88 |
PhoneAccountHandle connectionManagerPhoneAccount, |
| 89 |
ConnectionRequest request, |
| 90 |
boolean isIncoming) { |
| 91 |
PhoneAccountHandle accountHandle = request.getAccountHandle(); |
| 92 |
if (accountHandle == null) { |
| 93 |
throw new IllegalArgumentException("accountHandle must be specified."); |
| 94 |
} |
| 95 |
|
| 96 |
ComponentName componentName = request.getAccountHandle().getComponentName(); |
| 97 |
if (!mRemoteConnectionServices.containsKey(componentName)) { |
| 98 |
throw new UnsupportedOperationException("accountHandle not supported: " |
| 99 |
+ componentName); |
| 100 |
} |
| 101 |
|
| 102 |
RemoteConnectionService remoteService = mRemoteConnectionServices.get(componentName); |
| 103 |
if (remoteService != null) { |
| 104 |
return remoteService.createRemoteConference( |
| 105 |
connectionManagerPhoneAccount, request, isIncoming); |
| 106 |
} |
| 107 |
return null; |
| 108 |
} |
| 109 |
|
| 110 |
public void conferenceRemoteConnections(RemoteConnection a, RemoteConnection b) { |
| 111 |
if (a.getConnectionService() == b.getConnectionService()) { |
| 112 |
try { |
| 113 |
a.getConnectionService().conference(a.getId(), b.getId(), null ); |
| 114 |
} catch (RemoteException e) { |
| 115 |
} |
| 116 |
} else { |
| 117 |
Log.w(this, "Request to conference incompatible remote connections (%s,%s) (%s,%s)", |
| 118 |
a.getConnectionService(), a.getId(), |
| 119 |
b.getConnectionService(), b.getId()); |
| 120 |
} |
| 121 |
} |
| 122 |
} |