• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
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  * @hide
29  */
30 public class RemoteConnectionManager {
31     private final Map<ComponentName, RemoteConnectionService> mRemoteConnectionServices =
32             new HashMap<>();
33     private final ConnectionService mOurConnectionServiceImpl;
34 
RemoteConnectionManager(ConnectionService ourConnectionServiceImpl)35     public RemoteConnectionManager(ConnectionService ourConnectionServiceImpl) {
36         mOurConnectionServiceImpl = ourConnectionServiceImpl;
37     }
38 
addConnectionService( ComponentName componentName, IConnectionService outgoingConnectionServiceRpc)39     void addConnectionService(
40             ComponentName componentName,
41             IConnectionService outgoingConnectionServiceRpc) {
42         mRemoteConnectionServices.computeIfAbsent(
43                 componentName,
44                 key -> {
45                     try {
46                         return new RemoteConnectionService(
47                                 outgoingConnectionServiceRpc, mOurConnectionServiceImpl);
48                     } catch (RemoteException e) {
49                         Log.w(
50                                 RemoteConnectionManager.this,
51                                 "error when addConnectionService of %s: %s",
52                                 componentName,
53                                 e.toString());
54                         return null;
55                     }
56                 });
57     }
58 
createRemoteConnection( PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request, boolean isIncoming)59     public RemoteConnection createRemoteConnection(
60             PhoneAccountHandle connectionManagerPhoneAccount,
61             ConnectionRequest request,
62             boolean isIncoming) {
63         PhoneAccountHandle accountHandle = request.getAccountHandle();
64         if (accountHandle == null) {
65             throw new IllegalArgumentException("accountHandle must be specified.");
66         }
67 
68         ComponentName componentName = request.getAccountHandle().getComponentName();
69         RemoteConnectionService remoteService = mRemoteConnectionServices.get(componentName);
70         if (remoteService == null) {
71             throw new UnsupportedOperationException("accountHandle not supported: "
72                     + componentName);
73         }
74 
75         return remoteService.createRemoteConnection(
76                 connectionManagerPhoneAccount, request, isIncoming);
77     }
78 
79     /**
80      * Ask a {@code RemoteConnectionService} to create a {@code RemoteConference}.
81      * @param connectionManagerPhoneAccount See description at
82      * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
83      * @param request Details about the incoming conference call.
84      * @param isIncoming {@code true} if it's an incoming conference.
85      * @return
86      */
createRemoteConference( PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request, boolean isIncoming)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         RemoteConnectionService remoteService = mRemoteConnectionServices.get(componentName);
98         if (remoteService == null) {
99             throw new UnsupportedOperationException("accountHandle not supported: "
100                     + componentName);
101         }
102 
103         return remoteService.createRemoteConference(
104                 connectionManagerPhoneAccount, request, isIncoming);
105     }
106 
conferenceRemoteConnections(RemoteConnection a, RemoteConnection b)107     public void conferenceRemoteConnections(RemoteConnection a, RemoteConnection b) {
108         if (a.getConnectionService() == b.getConnectionService()) {
109             try {
110                 a.getConnectionService().conference(a.getId(), b.getId(), null /*Session.Info*/);
111             } 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     }
119 }
120