blob: f3c7bd83ed4b5f8b7e80de119b67c837b5bdf477 [file] [log] [blame]
Santos Cordon52d8a152014-06-17 19:08:45 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 R* limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Santos Cordon52d8a152014-06-17 19:08:45 -070018
19import android.content.ComponentName;
Santos Cordon52d8a152014-06-17 19:08:45 -070020import android.os.RemoteException;
21
Tyler Gunnef9f6f92014-09-12 22:16:17 -070022import com.android.internal.telecom.IConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -070023
24import java.util.HashMap;
Santos Cordon52d8a152014-06-17 19:08:45 -070025import java.util.Map;
26
27/**
28 * @hide
29 */
30public class RemoteConnectionManager {
Ihab Awadb8e85c72014-08-23 20:34:57 -070031 private final Map<ComponentName, RemoteConnectionService> mRemoteConnectionServices =
32 new HashMap<>();
33 private final ConnectionService mOurConnectionServiceImpl;
Santos Cordon52d8a152014-06-17 19:08:45 -070034
Ihab Awadb8e85c72014-08-23 20:34:57 -070035 public RemoteConnectionManager(ConnectionService ourConnectionServiceImpl) {
36 mOurConnectionServiceImpl = ourConnectionServiceImpl;
37 }
38
39 void addConnectionService(
40 ComponentName componentName,
41 IConnectionService outgoingConnectionServiceRpc) {
Santos Cordon52d8a152014-06-17 19:08:45 -070042 if (!mRemoteConnectionServices.containsKey(componentName)) {
43 try {
Ihab Awadb8e85c72014-08-23 20:34:57 -070044 RemoteConnectionService remoteConnectionService = new RemoteConnectionService(
45 outgoingConnectionServiceRpc,
46 mOurConnectionServiceImpl);
Santos Cordon52d8a152014-06-17 19:08:45 -070047 mRemoteConnectionServices.put(componentName, remoteConnectionService);
48 } catch (RemoteException ignored) {
49 }
50 }
51 }
52
Evan Charltonbf11f982014-07-20 22:06:28 -070053 public RemoteConnection createRemoteConnection(
Ihab Awadf8b69882014-07-25 15:14:01 -070054 PhoneAccountHandle connectionManagerPhoneAccount,
Santos Cordon52d8a152014-06-17 19:08:45 -070055 ConnectionRequest request,
Sailesh Nepalc5b01572014-07-14 16:29:44 -070056 boolean isIncoming) {
Evan Charlton8c8a0622014-07-20 12:31:00 -070057 PhoneAccountHandle accountHandle = request.getAccountHandle();
58 if (accountHandle == null) {
59 throw new IllegalArgumentException("accountHandle must be specified.");
Santos Cordon52d8a152014-06-17 19:08:45 -070060 }
61
Evan Charlton8c8a0622014-07-20 12:31:00 -070062 ComponentName componentName = request.getAccountHandle().getComponentName();
Santos Cordon52d8a152014-06-17 19:08:45 -070063 if (!mRemoteConnectionServices.containsKey(componentName)) {
Evan Charlton8c8a0622014-07-20 12:31:00 -070064 throw new UnsupportedOperationException("accountHandle not supported: "
65 + componentName);
Santos Cordon52d8a152014-06-17 19:08:45 -070066 }
Evan Charltonbf11f982014-07-20 22:06:28 -070067
68 RemoteConnectionService remoteService = mRemoteConnectionServices.get(componentName);
69 if (remoteService != null) {
Ihab Awadf8b69882014-07-25 15:14:01 -070070 return remoteService.createRemoteConnection(
71 connectionManagerPhoneAccount, request, isIncoming);
Evan Charltonbf11f982014-07-20 22:06:28 -070072 }
73 return null;
Santos Cordon52d8a152014-06-17 19:08:45 -070074 }
Ihab Awadb8e85c72014-08-23 20:34:57 -070075
Grace Jia9a09c672020-08-04 12:52:09 -070076 /**
77 * Ask a {@code RemoteConnectionService} to create a {@code RemoteConference}.
78 * @param connectionManagerPhoneAccount See description at
79 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
80 * @param request Details about the incoming conference call.
81 * @param isIncoming {@code true} if it's an incoming conference.
82 * @return
83 */
84 public RemoteConference createRemoteConference(
85 PhoneAccountHandle connectionManagerPhoneAccount,
86 ConnectionRequest request,
87 boolean isIncoming) {
88 PhoneAccountHandle accountHandle = request.getAccountHandle();
89 if (accountHandle == null) {
90 throw new IllegalArgumentException("accountHandle must be specified.");
91 }
92
93 ComponentName componentName = request.getAccountHandle().getComponentName();
94 if (!mRemoteConnectionServices.containsKey(componentName)) {
95 throw new UnsupportedOperationException("accountHandle not supported: "
96 + componentName);
97 }
98
99 RemoteConnectionService remoteService = mRemoteConnectionServices.get(componentName);
100 if (remoteService != null) {
101 return remoteService.createRemoteConference(
102 connectionManagerPhoneAccount, request, isIncoming);
103 }
104 return null;
105 }
106
Ihab Awadb8e85c72014-08-23 20:34:57 -0700107 public void conferenceRemoteConnections(RemoteConnection a, RemoteConnection b) {
108 if (a.getConnectionService() == b.getConnectionService()) {
109 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700110 a.getConnectionService().conference(a.getId(), b.getId(), null /*Session.Info*/);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700111 } catch (RemoteException e) {
112 }
113 } else {
114 Log.w(this, "Request to conference incompatible remote connections (%s,%s) (%s,%s)",
115 a.getConnectionService(), a.getId(),
116 b.getConnectionService(), b.getId());
117 }
118 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700119}