Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 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 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 18 | |
| 19 | import android.content.ComponentName; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 20 | import android.os.RemoteException; |
| 21 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 22 | import com.android.internal.telecom.IConnectionService; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 23 | |
| 24 | import java.util.HashMap; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 25 | import java.util.Map; |
| 26 | |
| 27 | /** |
| 28 | * @hide |
| 29 | */ |
| 30 | public class RemoteConnectionManager { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 31 | private final Map<ComponentName, RemoteConnectionService> mRemoteConnectionServices = |
| 32 | new HashMap<>(); |
| 33 | private final ConnectionService mOurConnectionServiceImpl; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 34 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 35 | public RemoteConnectionManager(ConnectionService ourConnectionServiceImpl) { |
| 36 | mOurConnectionServiceImpl = ourConnectionServiceImpl; |
| 37 | } |
| 38 | |
| 39 | void addConnectionService( |
| 40 | ComponentName componentName, |
| 41 | IConnectionService outgoingConnectionServiceRpc) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 42 | if (!mRemoteConnectionServices.containsKey(componentName)) { |
| 43 | try { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 44 | RemoteConnectionService remoteConnectionService = new RemoteConnectionService( |
| 45 | outgoingConnectionServiceRpc, |
| 46 | mOurConnectionServiceImpl); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 47 | mRemoteConnectionServices.put(componentName, remoteConnectionService); |
| 48 | } catch (RemoteException ignored) { |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 53 | public RemoteConnection createRemoteConnection( |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 54 | PhoneAccountHandle connectionManagerPhoneAccount, |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 55 | ConnectionRequest request, |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 56 | boolean isIncoming) { |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 57 | PhoneAccountHandle accountHandle = request.getAccountHandle(); |
| 58 | if (accountHandle == null) { |
| 59 | throw new IllegalArgumentException("accountHandle must be specified."); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 62 | ComponentName componentName = request.getAccountHandle().getComponentName(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 63 | if (!mRemoteConnectionServices.containsKey(componentName)) { |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 64 | throw new UnsupportedOperationException("accountHandle not supported: " |
| 65 | + componentName); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 66 | } |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 67 | |
| 68 | RemoteConnectionService remoteService = mRemoteConnectionServices.get(componentName); |
| 69 | if (remoteService != null) { |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 70 | return remoteService.createRemoteConnection( |
| 71 | connectionManagerPhoneAccount, request, isIncoming); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 72 | } |
| 73 | return null; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 74 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 75 | |
| 76 | public void conferenceRemoteConnections(RemoteConnection a, RemoteConnection b) { |
| 77 | if (a.getConnectionService() == b.getConnectionService()) { |
| 78 | try { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 79 | a.getConnectionService().conference(a.getId(), b.getId(), null /*Session.Info*/); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 80 | } catch (RemoteException e) { |
| 81 | } |
| 82 | } else { |
| 83 | Log.w(this, "Request to conference incompatible remote connections (%s,%s) (%s,%s)", |
| 84 | a.getConnectionService(), a.getId(), |
| 85 | b.getConnectionService(), b.getId()); |
| 86 | } |
| 87 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 88 | } |