Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
| 17 | package com.android.server.telecom.tests; |
| 18 | |
| 19 | import com.android.internal.telecom.IConnectionService; |
| 20 | import com.android.internal.telecom.IConnectionServiceAdapter; |
| 21 | import com.android.internal.telecom.IVideoProvider; |
| 22 | import com.android.internal.telecom.RemoteServiceCallback; |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 23 | import com.android.server.telecom.Log; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 24 | |
| 25 | import junit.framework.TestCase; |
| 26 | |
| 27 | import org.mockito.Mockito; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 28 | |
| 29 | import android.content.ComponentName; |
Abhijith Shastry | b7853c0 | 2016-02-03 12:56:59 -0800 | [diff] [blame] | 30 | import android.net.Uri; |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 31 | import android.os.Bundle; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 32 | import android.os.IBinder; |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 33 | import android.os.IInterface; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 34 | import android.os.RemoteException; |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 35 | import android.telecom.CallAudioState; |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 36 | import android.telecom.Conference; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 37 | import android.telecom.Connection; |
| 38 | import android.telecom.ConnectionRequest; |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 39 | import android.telecom.ConnectionService; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 40 | import android.telecom.DisconnectCause; |
| 41 | import android.telecom.ParcelableConference; |
| 42 | import android.telecom.ParcelableConnection; |
| 43 | import android.telecom.PhoneAccountHandle; |
| 44 | import android.telecom.StatusHints; |
Abhijith Shastry | b7853c0 | 2016-02-03 12:56:59 -0800 | [diff] [blame] | 45 | import android.telecom.TelecomManager; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 46 | |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 47 | import com.google.android.collect.Lists; |
| 48 | |
Bryce Lee | 6d96252 | 2015-11-30 10:28:37 -0800 | [diff] [blame] | 49 | import java.lang.Override; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 50 | import java.util.ArrayList; |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 51 | import java.util.Collection; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 52 | import java.util.HashMap; |
| 53 | import java.util.HashSet; |
| 54 | import java.util.List; |
| 55 | import java.util.Map; |
| 56 | import java.util.Set; |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 57 | import java.util.concurrent.CountDownLatch; |
| 58 | import java.util.concurrent.TimeUnit; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 59 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 60 | /** |
| 61 | * Controls a test {@link IConnectionService} as would be provided by a source of connectivity |
| 62 | * to the Telecom framework. |
| 63 | */ |
| 64 | public class ConnectionServiceFixture implements TestFixture<IConnectionService> { |
Abhijith Shastry | b7853c0 | 2016-02-03 12:56:59 -0800 | [diff] [blame] | 65 | static int INVALID_VIDEO_STATE = -1; |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 66 | public CountDownLatch mExtrasLock = new CountDownLatch(1); |
Tyler Gunn | 571d5e6 | 2016-03-15 15:55:18 -0700 | [diff] [blame] | 67 | static int NOT_SPECIFIED = 0; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 68 | |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 69 | /** |
| 70 | * Implementation of ConnectionService that performs no-ops for tasks normally meant for |
| 71 | * Telephony and reports success back to Telecom |
| 72 | */ |
| 73 | public class FakeConnectionServiceDelegate extends ConnectionService { |
Abhijith Shastry | b7853c0 | 2016-02-03 12:56:59 -0800 | [diff] [blame] | 74 | int mVideoState = INVALID_VIDEO_STATE; |
Tyler Gunn | 571d5e6 | 2016-03-15 15:55:18 -0700 | [diff] [blame] | 75 | int mCapabilities = NOT_SPECIFIED; |
| 76 | int mProperties = NOT_SPECIFIED; |
Abhijith Shastry | b7853c0 | 2016-02-03 12:56:59 -0800 | [diff] [blame] | 77 | |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 78 | @Override |
| 79 | public Connection onCreateUnknownConnection( |
| 80 | PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) { |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 81 | mLatestConnection = new FakeConnection(request.getVideoState(), request.getAddress()); |
| 82 | return mLatestConnection; |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public Connection onCreateIncomingConnection( |
| 87 | PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) { |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 88 | FakeConnection fakeConnection = new FakeConnection( |
Abhijith Shastry | b7853c0 | 2016-02-03 12:56:59 -0800 | [diff] [blame] | 89 | mVideoState == INVALID_VIDEO_STATE ? request.getVideoState() : mVideoState, |
| 90 | request.getAddress()); |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 91 | mLatestConnection = fakeConnection; |
Tyler Gunn | 571d5e6 | 2016-03-15 15:55:18 -0700 | [diff] [blame] | 92 | if (mCapabilities != NOT_SPECIFIED) { |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 93 | fakeConnection.setConnectionCapabilities(mCapabilities); |
| 94 | } |
Tyler Gunn | 571d5e6 | 2016-03-15 15:55:18 -0700 | [diff] [blame] | 95 | if (mProperties != NOT_SPECIFIED) { |
| 96 | fakeConnection.setConnectionProperties(mProperties); |
| 97 | } |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 98 | |
| 99 | return fakeConnection; |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public Connection onCreateOutgoingConnection( |
| 104 | PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) { |
Brad Ebinger | 84771f8 | 2016-05-18 16:57:30 -0700 | [diff] [blame] | 105 | FakeConnection fakeConnection = new FakeConnection(request.getVideoState(), |
| 106 | request.getAddress()); |
| 107 | mLatestConnection = fakeConnection; |
| 108 | if (mCapabilities != NOT_SPECIFIED) { |
| 109 | fakeConnection.setConnectionCapabilities(mCapabilities); |
| 110 | } |
| 111 | if (mProperties != NOT_SPECIFIED) { |
| 112 | fakeConnection.setConnectionProperties(mProperties); |
| 113 | } |
| 114 | return fakeConnection; |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public void onConference(Connection cxn1, Connection cxn2) { |
Brad Ebinger | 0d40255 | 2016-05-27 16:02:53 -0700 | [diff] [blame] | 119 | if (((FakeConnection) cxn1).getIsConferenceCreated()) { |
| 120 | // Usually, this is implemented by something in Telephony, which does a bunch of |
| 121 | // radio work to conference the two connections together. Here we just short-cut |
| 122 | // that and declare them conferenced. |
| 123 | Conference fakeConference = new FakeConference(); |
| 124 | fakeConference.addConnection(cxn1); |
| 125 | fakeConference.addConnection(cxn2); |
| 126 | mLatestConference = fakeConference; |
| 127 | addConference(fakeConference); |
| 128 | } else { |
| 129 | try { |
| 130 | sendSetConferenceMergeFailed(cxn1.getTelecomCallId()); |
| 131 | } catch (Exception e) { |
| 132 | Log.w(this, "Exception on sendSetConferenceMergeFailed: " + e.getMessage()); |
| 133 | } |
| 134 | } |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
| 138 | public class FakeConnection extends Connection { |
Brad Ebinger | 0d40255 | 2016-05-27 16:02:53 -0700 | [diff] [blame] | 139 | // Set to false if you wish the Conference merge to fail. |
| 140 | boolean mIsConferenceCreated = true; |
| 141 | |
Abhijith Shastry | b7853c0 | 2016-02-03 12:56:59 -0800 | [diff] [blame] | 142 | public FakeConnection(int videoState, Uri address) { |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 143 | super(); |
| 144 | int capabilities = getConnectionCapabilities(); |
| 145 | capabilities |= CAPABILITY_MUTE; |
| 146 | capabilities |= CAPABILITY_SUPPORT_HOLD; |
| 147 | capabilities |= CAPABILITY_HOLD; |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 148 | setVideoState(videoState); |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 149 | setConnectionCapabilities(capabilities); |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 150 | setDialing(); |
Abhijith Shastry | b7853c0 | 2016-02-03 12:56:59 -0800 | [diff] [blame] | 151 | setAddress(address, TelecomManager.PRESENTATION_ALLOWED); |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 152 | } |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 153 | |
| 154 | @Override |
| 155 | public void onExtrasChanged(Bundle extras) { |
| 156 | mExtrasLock.countDown(); |
| 157 | } |
Brad Ebinger | 0d40255 | 2016-05-27 16:02:53 -0700 | [diff] [blame] | 158 | |
| 159 | public boolean getIsConferenceCreated() { |
| 160 | return mIsConferenceCreated; |
| 161 | } |
| 162 | |
| 163 | public void setIsConferenceCreated(boolean isConferenceCreated) { |
| 164 | mIsConferenceCreated = isConferenceCreated; |
| 165 | } |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | public class FakeConference extends Conference { |
| 169 | public FakeConference() { |
| 170 | super(null); |
| 171 | setConnectionCapabilities( |
| 172 | Connection.CAPABILITY_SUPPORT_HOLD |
| 173 | | Connection.CAPABILITY_HOLD |
| 174 | | Connection.CAPABILITY_MUTE |
| 175 | | Connection.CAPABILITY_MANAGE_CONFERENCE); |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public void onMerge(Connection connection) { |
| 180 | // Do nothing besides inform the connection that it was merged into this conference. |
| 181 | connection.setConference(this); |
| 182 | } |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 183 | |
| 184 | @Override |
| 185 | public void onExtrasChanged(Bundle extras) { |
| 186 | Log.w(this, "FakeConference onExtrasChanged"); |
| 187 | mExtrasLock.countDown(); |
| 188 | } |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 191 | public class FakeConnectionService extends IConnectionService.Stub { |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 192 | List<String> rejectedCallIds = Lists.newArrayList(); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 193 | |
| 194 | @Override |
| 195 | public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter) |
| 196 | throws RemoteException { |
| 197 | if (!mConnectionServiceAdapters.add(adapter)) { |
| 198 | throw new RuntimeException("Adapter already added: " + adapter); |
| 199 | } |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 200 | mConnectionServiceDelegateAdapter.addConnectionServiceAdapter(adapter); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter) |
| 205 | throws RemoteException { |
| 206 | if (!mConnectionServiceAdapters.remove(adapter)) { |
| 207 | throw new RuntimeException("Adapter never added: " + adapter); |
| 208 | } |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 209 | mConnectionServiceDelegateAdapter.removeConnectionServiceAdapter(adapter); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | @Override |
| 213 | public void createConnection(PhoneAccountHandle connectionManagerPhoneAccount, |
| 214 | String id, |
| 215 | ConnectionRequest request, boolean isIncoming, boolean isUnknown) |
| 216 | throws RemoteException { |
| 217 | Log.i(ConnectionServiceFixture.this, "xoxox createConnection --> " + id); |
| 218 | |
| 219 | if (mConnectionById.containsKey(id)) { |
| 220 | throw new RuntimeException("Connection already exists: " + id); |
| 221 | } |
| 222 | mLatestConnectionId = id; |
| 223 | ConnectionInfo c = new ConnectionInfo(); |
| 224 | c.connectionManagerPhoneAccount = connectionManagerPhoneAccount; |
| 225 | c.id = id; |
| 226 | c.request = request; |
| 227 | c.isIncoming = isIncoming; |
| 228 | c.isUnknown = isUnknown; |
Ihab Awad | 32dd7c3 | 2015-05-28 10:52:20 -0700 | [diff] [blame] | 229 | c.capabilities |= Connection.CAPABILITY_HOLD | Connection.CAPABILITY_SUPPORT_HOLD; |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 230 | c.videoState = request.getVideoState(); |
| 231 | c.mockVideoProvider = new MockVideoProvider(); |
| 232 | c.videoProvider = c.mockVideoProvider.getInterface(); |
Brad Ebinger | 0d40255 | 2016-05-27 16:02:53 -0700 | [diff] [blame] | 233 | c.isConferenceCreated = true; |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 234 | mConnectionById.put(id, c); |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 235 | mConnectionServiceDelegateAdapter.createConnection(connectionManagerPhoneAccount, |
| 236 | id, request, isIncoming, isUnknown); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public void abort(String callId) throws RemoteException { } |
| 241 | |
| 242 | @Override |
| 243 | public void answerVideo(String callId, int videoState) throws RemoteException { } |
| 244 | |
| 245 | @Override |
| 246 | public void answer(String callId) throws RemoteException { } |
| 247 | |
| 248 | @Override |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 249 | public void reject(String callId) throws RemoteException { |
| 250 | rejectedCallIds.add(callId); |
| 251 | } |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 252 | |
| 253 | @Override |
Bryce Lee | ddd966e | 2015-08-28 16:33:50 -0700 | [diff] [blame] | 254 | public void rejectWithMessage(String callId, String message) throws RemoteException { } |
| 255 | |
| 256 | @Override |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 257 | public void disconnect(String callId) throws RemoteException { } |
| 258 | |
| 259 | @Override |
Bryce Lee | 6d96252 | 2015-11-30 10:28:37 -0800 | [diff] [blame] | 260 | public void silence(String callId) throws RemoteException { } |
| 261 | |
| 262 | @Override |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 263 | public void hold(String callId) throws RemoteException { } |
| 264 | |
| 265 | @Override |
| 266 | public void unhold(String callId) throws RemoteException { } |
| 267 | |
| 268 | @Override |
| 269 | public void onCallAudioStateChanged(String activeCallId, CallAudioState audioState) |
| 270 | throws RemoteException { } |
| 271 | |
| 272 | @Override |
| 273 | public void playDtmfTone(String callId, char digit) throws RemoteException { } |
| 274 | |
| 275 | @Override |
| 276 | public void stopDtmfTone(String callId) throws RemoteException { } |
| 277 | |
| 278 | @Override |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 279 | public void conference(String conferenceCallId, String callId) throws RemoteException { |
| 280 | mConnectionServiceDelegateAdapter.conference(conferenceCallId, callId); |
| 281 | } |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 282 | |
| 283 | @Override |
| 284 | public void splitFromConference(String callId) throws RemoteException { } |
| 285 | |
| 286 | @Override |
| 287 | public void mergeConference(String conferenceCallId) throws RemoteException { } |
| 288 | |
| 289 | @Override |
| 290 | public void swapConference(String conferenceCallId) throws RemoteException { } |
| 291 | |
| 292 | @Override |
| 293 | public void onPostDialContinue(String callId, boolean proceed) throws RemoteException { } |
| 294 | |
| 295 | @Override |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 296 | public void pullExternalCall(String callId) throws RemoteException { } |
| 297 | |
| 298 | @Override |
| 299 | public void sendCallEvent(String callId, String event, Bundle extras) throws RemoteException |
| 300 | {} |
| 301 | |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 302 | public void onExtrasChanged(String callId, Bundle extras) throws RemoteException { |
| 303 | mConnectionServiceDelegateAdapter.onExtrasChanged(callId, extras); |
| 304 | } |
| 305 | |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 306 | @Override |
Suchand Ghosh | 47b2f42 | 2014-09-22 12:13:47 +0530 | [diff] [blame] | 307 | public void addParticipantWithConference(String callId, String recipients) {} |
| 308 | |
| 309 | @Override |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 310 | public IBinder asBinder() { |
| 311 | return this; |
| 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public IInterface queryLocalInterface(String descriptor) { |
| 316 | return this; |
| 317 | } |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Abhijith Shastry | b7853c0 | 2016-02-03 12:56:59 -0800 | [diff] [blame] | 320 | FakeConnectionServiceDelegate mConnectionServiceDelegate = |
Hall Liu | f7783fb | 2015-11-23 18:45:48 -0800 | [diff] [blame] | 321 | new FakeConnectionServiceDelegate(); |
| 322 | private IConnectionService mConnectionServiceDelegateAdapter = |
| 323 | IConnectionService.Stub.asInterface(mConnectionServiceDelegate.onBind(null)); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 324 | |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 325 | FakeConnectionService mConnectionService = new FakeConnectionService(); |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 326 | private IConnectionService.Stub mConnectionServiceSpy = Mockito.spy(mConnectionService); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 327 | |
| 328 | public class ConnectionInfo { |
| 329 | PhoneAccountHandle connectionManagerPhoneAccount; |
| 330 | String id; |
| 331 | boolean ringing; |
| 332 | ConnectionRequest request; |
| 333 | boolean isIncoming; |
| 334 | boolean isUnknown; |
| 335 | int state; |
| 336 | int addressPresentation; |
| 337 | int capabilities; |
Tyler Gunn | 571d5e6 | 2016-03-15 15:55:18 -0700 | [diff] [blame] | 338 | int properties; |
Christine Hallstrom | 96a0be6 | 2016-11-30 16:05:13 -0800 | [diff] [blame] | 339 | int supportedAudioRoutes; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 340 | StatusHints statusHints; |
| 341 | DisconnectCause disconnectCause; |
| 342 | String conferenceId; |
| 343 | String callerDisplayName; |
| 344 | int callerDisplayNamePresentation; |
| 345 | final List<String> conferenceableConnectionIds = new ArrayList<>(); |
| 346 | IVideoProvider videoProvider; |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 347 | Connection.VideoProvider videoProviderImpl; |
| 348 | MockVideoProvider mockVideoProvider; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 349 | int videoState; |
| 350 | boolean isVoipAudioMode; |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 351 | Bundle extras; |
Brad Ebinger | 0d40255 | 2016-05-27 16:02:53 -0700 | [diff] [blame] | 352 | boolean isConferenceCreated; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | public class ConferenceInfo { |
| 356 | PhoneAccountHandle phoneAccount; |
| 357 | int state; |
| 358 | int capabilities; |
Tyler Gunn | 571d5e6 | 2016-03-15 15:55:18 -0700 | [diff] [blame] | 359 | int properties; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 360 | final List<String> connectionIds = new ArrayList<>(); |
Rekha Kumar | d240fe8 | 2015-04-01 21:45:57 -0700 | [diff] [blame] | 361 | IVideoProvider videoProvider; |
| 362 | int videoState; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 363 | long connectTimeMillis; |
Andrew Lee | 569b54e | 2015-04-16 13:57:49 -0700 | [diff] [blame] | 364 | StatusHints statusHints; |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 365 | Bundle extras; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | public String mLatestConnectionId; |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 369 | public Connection mLatestConnection; |
| 370 | public Conference mLatestConference; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 371 | public final Set<IConnectionServiceAdapter> mConnectionServiceAdapters = new HashSet<>(); |
| 372 | public final Map<String, ConnectionInfo> mConnectionById = new HashMap<>(); |
| 373 | public final Map<String, ConferenceInfo> mConferenceById = new HashMap<>(); |
| 374 | public final List<ComponentName> mRemoteConnectionServiceNames = new ArrayList<>(); |
| 375 | public final List<IBinder> mRemoteConnectionServices = new ArrayList<>(); |
| 376 | |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 377 | public ConnectionServiceFixture() throws Exception { } |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 378 | |
| 379 | @Override |
| 380 | public IConnectionService getTestDouble() { |
Ihab Awad | 1b5490a | 2015-05-12 13:13:48 -0700 | [diff] [blame] | 381 | return mConnectionServiceSpy; |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | public void sendHandleCreateConnectionComplete(String id) throws Exception { |
| 385 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 386 | a.handleCreateConnectionComplete( |
| 387 | id, |
| 388 | mConnectionById.get(id).request, |
| 389 | parcelable(mConnectionById.get(id))); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | public void sendSetActive(String id) throws Exception { |
| 394 | mConnectionById.get(id).state = Connection.STATE_ACTIVE; |
| 395 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 396 | a.setActive(id); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | public void sendSetRinging(String id) throws Exception { |
| 401 | mConnectionById.get(id).state = Connection.STATE_RINGING; |
| 402 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 403 | a.setRinging(id); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | public void sendSetDialing(String id) throws Exception { |
| 408 | mConnectionById.get(id).state = Connection.STATE_DIALING; |
| 409 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 410 | a.setDialing(id); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | public void sendSetDisconnected(String id, int disconnectCause) throws Exception { |
| 415 | mConnectionById.get(id).state = Connection.STATE_DISCONNECTED; |
| 416 | mConnectionById.get(id).disconnectCause = new DisconnectCause(disconnectCause); |
| 417 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 418 | a.setDisconnected(id, mConnectionById.get(id).disconnectCause); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | public void sendSetOnHold(String id) throws Exception { |
| 423 | mConnectionById.get(id).state = Connection.STATE_HOLDING; |
| 424 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 425 | a.setOnHold(id); |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | public void sendSetRingbackRequested(String id) throws Exception { |
| 430 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 431 | a.setRingbackRequested(id, mConnectionById.get(id).ringing); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | public void sendSetConnectionCapabilities(String id) throws Exception { |
| 436 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 437 | a.setConnectionCapabilities(id, mConnectionById.get(id).capabilities); |
| 438 | } |
| 439 | } |
| 440 | |
Hall Liu | d7fe686 | 2016-09-09 16:36:14 -0700 | [diff] [blame] | 441 | public void sendSetConnectionProperties(String id) throws Exception { |
| 442 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 443 | a.setConnectionProperties(id, mConnectionById.get(id).properties); |
| 444 | } |
| 445 | } |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 446 | public void sendSetIsConferenced(String id) throws Exception { |
| 447 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 448 | a.setIsConferenced(id, mConnectionById.get(id).conferenceId); |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | public void sendAddConferenceCall(String id) throws Exception { |
| 453 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 454 | a.addConferenceCall(id, parcelable(mConferenceById.get(id))); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | public void sendRemoveCall(String id) throws Exception { |
| 459 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 460 | a.removeCall(id); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | public void sendOnPostDialWait(String id, String remaining) throws Exception { |
| 465 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 466 | a.onPostDialWait(id, remaining); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | public void sendOnPostDialChar(String id, char nextChar) throws Exception { |
| 471 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 472 | a.onPostDialChar(id, nextChar); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | public void sendQueryRemoteConnectionServices() throws Exception { |
| 477 | mRemoteConnectionServices.clear(); |
| 478 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 479 | a.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() { |
| 480 | @Override |
| 481 | public void onError() throws RemoteException { |
| 482 | throw new RuntimeException(); |
| 483 | } |
| 484 | |
| 485 | @Override |
| 486 | public void onResult( |
| 487 | List<ComponentName> names, |
| 488 | List<IBinder> services) |
| 489 | throws RemoteException { |
| 490 | TestCase.assertEquals(names.size(), services.size()); |
| 491 | mRemoteConnectionServiceNames.addAll(names); |
| 492 | mRemoteConnectionServices.addAll(services); |
| 493 | } |
| 494 | |
| 495 | @Override |
| 496 | public IBinder asBinder() { |
| 497 | return this; |
| 498 | } |
| 499 | }); |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | public void sendSetVideoProvider(String id) throws Exception { |
| 504 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 505 | a.setVideoProvider(id, mConnectionById.get(id).videoProvider); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | public void sendSetVideoState(String id) throws Exception { |
| 510 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 511 | a.setVideoState(id, mConnectionById.get(id).videoState); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | public void sendSetIsVoipAudioMode(String id) throws Exception { |
| 516 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 517 | a.setIsVoipAudioMode(id, mConnectionById.get(id).isVoipAudioMode); |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | public void sendSetStatusHints(String id) throws Exception { |
| 522 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 523 | a.setStatusHints(id, mConnectionById.get(id).statusHints); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | public void sendSetAddress(String id) throws Exception { |
| 528 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 529 | a.setAddress( |
| 530 | id, |
| 531 | mConnectionById.get(id).request.getAddress(), |
| 532 | mConnectionById.get(id).addressPresentation); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | public void sendSetCallerDisplayName(String id) throws Exception { |
| 537 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 538 | a.setCallerDisplayName( |
| 539 | id, |
| 540 | mConnectionById.get(id).callerDisplayName, |
| 541 | mConnectionById.get(id).callerDisplayNamePresentation); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | public void sendSetConferenceableConnections(String id) throws Exception { |
| 546 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 547 | a.setConferenceableConnections(id, mConnectionById.get(id).conferenceableConnectionIds); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | public void sendAddExistingConnection(String id) throws Exception { |
| 552 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 553 | a.addExistingConnection(id, parcelable(mConnectionById.get(id))); |
| 554 | } |
| 555 | } |
| 556 | |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 557 | public void sendConnectionEvent(String id, String event, Bundle extras) throws Exception { |
| 558 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 559 | a.onConnectionEvent(id, event, extras); |
| 560 | } |
| 561 | } |
| 562 | |
Brad Ebinger | 0d40255 | 2016-05-27 16:02:53 -0700 | [diff] [blame] | 563 | public void sendSetConferenceMergeFailed(String id) throws Exception { |
| 564 | for (IConnectionServiceAdapter a : mConnectionServiceAdapters) { |
| 565 | a.setConferenceMergeFailed(id); |
| 566 | } |
| 567 | } |
| 568 | |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 569 | /** |
| 570 | * Waits until the {@link Connection#onExtrasChanged(Bundle)} API has been called on a |
| 571 | * {@link Connection} or {@link Conference}. |
| 572 | */ |
| 573 | public void waitForExtras() { |
| 574 | try { |
| 575 | mExtrasLock.await(TelecomSystemTest.TEST_TIMEOUT, TimeUnit.MILLISECONDS); |
| 576 | } catch (InterruptedException ie) { |
| 577 | } |
| 578 | mExtrasLock = new CountDownLatch(1); |
| 579 | } |
| 580 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 581 | private ParcelableConference parcelable(ConferenceInfo c) { |
| 582 | return new ParcelableConference( |
| 583 | c.phoneAccount, |
| 584 | c.state, |
| 585 | c.capabilities, |
Tyler Gunn | 571d5e6 | 2016-03-15 15:55:18 -0700 | [diff] [blame] | 586 | c.properties, |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 587 | c.connectionIds, |
Rekha Kumar | d240fe8 | 2015-04-01 21:45:57 -0700 | [diff] [blame] | 588 | c.videoProvider, |
| 589 | c.videoState, |
Andrew Lee | 569b54e | 2015-04-16 13:57:49 -0700 | [diff] [blame] | 590 | c.connectTimeMillis, |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 591 | c.statusHints, |
| 592 | c.extras); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | private ParcelableConnection parcelable(ConnectionInfo c) { |
| 596 | return new ParcelableConnection( |
| 597 | c.request.getAccountHandle(), |
| 598 | c.state, |
| 599 | c.capabilities, |
Tyler Gunn | 571d5e6 | 2016-03-15 15:55:18 -0700 | [diff] [blame] | 600 | c.properties, |
Christine Hallstrom | 96a0be6 | 2016-11-30 16:05:13 -0800 | [diff] [blame] | 601 | c.supportedAudioRoutes, |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 602 | c.request.getAddress(), |
| 603 | c.addressPresentation, |
| 604 | c.callerDisplayName, |
| 605 | c.callerDisplayNamePresentation, |
| 606 | c.videoProvider, |
| 607 | c.videoState, |
| 608 | false, /* ringback requested */ |
| 609 | false, /* voip audio mode */ |
Roshan Pius | 084ab08 | 2015-07-15 12:17:04 -0700 | [diff] [blame] | 610 | 0, /* Connect Time for conf call on this connection */ |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 611 | c.statusHints, |
| 612 | c.disconnectCause, |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 613 | c.conferenceableConnectionIds, |
| 614 | c.extras); |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 615 | } |
| 616 | } |