| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -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 | * limitations under the License. |
| 15 | */ |
| 16 | |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 18 | |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 19 | import com.android.internal.telecom.IConnectionService; |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 20 | |
| Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 22 | import android.os.RemoteException; |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 23 | |
| Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame^] | 24 | import java.util.ArrayList; |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 25 | import java.util.Collections; |
| 26 | import java.util.List; |
| 27 | import java.util.Set; |
| 28 | import java.util.concurrent.CopyOnWriteArrayList; |
| 29 | import java.util.concurrent.CopyOnWriteArraySet; |
| 30 | |
| 31 | /** |
| 32 | * Represents a conference call which can contain any number of {@link Connection} objects. |
| Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 33 | * @hide |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 34 | */ |
| Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 35 | @SystemApi |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 36 | public final class RemoteConference { |
| 37 | |
| Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 38 | public abstract static class Callback { |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 39 | public void onStateChanged(RemoteConference conference, int oldState, int newState) {} |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 40 | public void onDisconnected(RemoteConference conference, DisconnectCause disconnectCause) {} |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 41 | public void onConnectionAdded(RemoteConference conference, RemoteConnection connection) {} |
| 42 | public void onConnectionRemoved(RemoteConference conference, RemoteConnection connection) {} |
| 43 | public void onCapabilitiesChanged(RemoteConference conference, int capabilities) {} |
| Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame^] | 44 | public void onConferenceableConnectionsChanged( |
| 45 | RemoteConference conference, |
| 46 | List<RemoteConnection> conferenceableConnections) {} |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 47 | public void onDestroyed(RemoteConference conference) {} |
| 48 | } |
| 49 | |
| 50 | private final String mId; |
| 51 | private final IConnectionService mConnectionService; |
| 52 | |
| Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 53 | private final Set<Callback> mCallbacks = new CopyOnWriteArraySet<>(); |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 54 | private final List<RemoteConnection> mChildConnections = new CopyOnWriteArrayList<>(); |
| 55 | private final List<RemoteConnection> mUnmodifiableChildConnections = |
| 56 | Collections.unmodifiableList(mChildConnections); |
| Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame^] | 57 | private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>(); |
| 58 | private final List<RemoteConnection> mUnmodifiableConferenceableConnections = |
| 59 | Collections.unmodifiableList(mConferenceableConnections); |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 60 | |
| 61 | private int mState = Connection.STATE_NEW; |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 62 | private DisconnectCause mDisconnectCause; |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 63 | private int mCallCapabilities; |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 64 | |
| 65 | /** {@hide} */ |
| 66 | RemoteConference(String id, IConnectionService connectionService) { |
| 67 | mId = id; |
| 68 | mConnectionService = connectionService; |
| 69 | } |
| 70 | |
| 71 | /** {@hide} */ |
| 72 | String getId() { |
| 73 | return mId; |
| 74 | } |
| 75 | |
| 76 | /** {@hide} */ |
| 77 | void setDestroyed() { |
| 78 | for (RemoteConnection connection : mChildConnections) { |
| 79 | connection.setConference(null); |
| 80 | } |
| Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 81 | for (Callback c : mCallbacks) { |
| 82 | c.onDestroyed(this); |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
| 86 | /** {@hide} */ |
| 87 | void setState(int newState) { |
| 88 | if (newState != Connection.STATE_ACTIVE && |
| 89 | newState != Connection.STATE_HOLDING && |
| 90 | newState != Connection.STATE_DISCONNECTED) { |
| 91 | Log.w(this, "Unsupported state transition for Conference call.", |
| 92 | Connection.stateToString(newState)); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | if (mState != newState) { |
| 97 | int oldState = mState; |
| 98 | mState = newState; |
| Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 99 | for (Callback c : mCallbacks) { |
| 100 | c.onStateChanged(this, oldState, newState); |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** {@hide} */ |
| 106 | void addConnection(RemoteConnection connection) { |
| 107 | if (!mChildConnections.contains(connection)) { |
| 108 | mChildConnections.add(connection); |
| 109 | connection.setConference(this); |
| Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 110 | for (Callback c : mCallbacks) { |
| 111 | c.onConnectionAdded(this, connection); |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | /** {@hide} */ |
| 117 | void removeConnection(RemoteConnection connection) { |
| 118 | if (mChildConnections.contains(connection)) { |
| 119 | mChildConnections.remove(connection); |
| 120 | connection.setConference(null); |
| Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 121 | for (Callback c : mCallbacks) { |
| 122 | c.onConnectionRemoved(this, connection); |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /** {@hide} */ |
| 128 | void setCallCapabilities(int capabilities) { |
| 129 | if (mCallCapabilities != capabilities) { |
| 130 | mCallCapabilities = capabilities; |
| Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 131 | for (Callback c : mCallbacks) { |
| 132 | c.onCapabilitiesChanged(this, mCallCapabilities); |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame^] | 137 | /** @hide */ |
| 138 | void setConferenceableConnections(List<RemoteConnection> conferenceableConnections) { |
| 139 | mConferenceableConnections.clear(); |
| 140 | mConferenceableConnections.addAll(conferenceableConnections); |
| 141 | for (Callback c : mCallbacks) { |
| 142 | c.onConferenceableConnectionsChanged(this, mUnmodifiableConferenceableConnections); |
| 143 | } |
| 144 | } |
| 145 | |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 146 | /** {@hide} */ |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 147 | void setDisconnected(DisconnectCause disconnectCause) { |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 148 | if (mState != Connection.STATE_DISCONNECTED) { |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 149 | mDisconnectCause = disconnectCause; |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 150 | setState(Connection.STATE_DISCONNECTED); |
| Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 151 | for (Callback c : mCallbacks) { |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 152 | c.onDisconnected(this, disconnectCause); |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | public final List<RemoteConnection> getConnections() { |
| 158 | return mUnmodifiableChildConnections; |
| 159 | } |
| 160 | |
| 161 | public final int getState() { |
| 162 | return mState; |
| 163 | } |
| 164 | |
| 165 | public final int getCallCapabilities() { |
| 166 | return mCallCapabilities; |
| 167 | } |
| 168 | |
| 169 | public void disconnect() { |
| 170 | try { |
| 171 | mConnectionService.disconnect(mId); |
| 172 | } catch (RemoteException e) { |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | public void separate(RemoteConnection connection) { |
| 177 | if (mChildConnections.contains(connection)) { |
| 178 | try { |
| 179 | mConnectionService.splitFromConference(connection.getId()); |
| 180 | } catch (RemoteException e) { |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| mike dooley | 95ea576 | 2014-09-25 14:49:21 -0700 | [diff] [blame] | 185 | public void merge() { |
| 186 | try { |
| 187 | mConnectionService.mergeConference(mId); |
| 188 | } catch (RemoteException e) { |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | public void swap() { |
| 193 | try { |
| 194 | mConnectionService.swapConference(mId); |
| 195 | } catch (RemoteException e) { |
| 196 | } |
| 197 | } |
| 198 | |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 199 | public void hold() { |
| 200 | try { |
| 201 | mConnectionService.hold(mId); |
| 202 | } catch (RemoteException e) { |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | public void unhold() { |
| 207 | try { |
| 208 | mConnectionService.unhold(mId); |
| 209 | } catch (RemoteException e) { |
| 210 | } |
| 211 | } |
| 212 | |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 213 | public DisconnectCause getDisconnectCause() { |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 214 | return mDisconnectCause; |
| 215 | } |
| 216 | |
| Yorke Lee | 58bacc5 | 2014-09-16 10:43:06 -0700 | [diff] [blame] | 217 | public void playDtmfTone(char digit) { |
| 218 | try { |
| 219 | mConnectionService.playDtmfTone(mId, digit); |
| 220 | } catch (RemoteException e) { |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | public void stopDtmfTone() { |
| 225 | try { |
| 226 | mConnectionService.stopDtmfTone(mId); |
| 227 | } catch (RemoteException e) { |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | public void setAudioState(AudioState state) { |
| 232 | try { |
| 233 | mConnectionService.onAudioStateChanged(mId, state); |
| 234 | } catch (RemoteException e) { |
| 235 | } |
| 236 | } |
| 237 | |
| Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame^] | 238 | public List<RemoteConnection> getConferenceableConnections() { |
| 239 | return mUnmodifiableConferenceableConnections; |
| 240 | } |
| 241 | |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 242 | public final void registerCallback(Callback callback) { |
| Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 243 | mCallbacks.add(callback); |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 246 | public final void unregisterCallback(Callback callback) { |
| Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 247 | mCallbacks.remove(callback); |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 248 | } |
| 249 | } |