Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [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 | |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 19 | import static org.junit.Assert.assertEquals; |
| 20 | import static org.junit.Assert.assertFalse; |
| 21 | import static org.junit.Assert.assertNull; |
| 22 | import static org.junit.Assert.assertTrue; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 23 | import static org.mockito.Matchers.any; |
| 24 | import static org.mockito.Matchers.anyInt; |
| 25 | import static org.mockito.Matchers.anyString; |
| 26 | import static org.mockito.Matchers.eq; |
| 27 | import static org.mockito.Matchers.isNull; |
| 28 | import static org.mockito.Mockito.never; |
| 29 | import static org.mockito.Mockito.timeout; |
Omata Shou | 6bc865c | 2017-07-26 13:39:27 +0900 | [diff] [blame] | 30 | import static org.mockito.Mockito.times; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 31 | import static org.mockito.Mockito.verify; |
| 32 | import static org.mockito.Mockito.verifyZeroInteractions; |
| 33 | import static org.mockito.Mockito.when; |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 34 | |
| 35 | import android.content.Context; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 36 | import android.content.IContentProvider; |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 37 | import android.media.AudioManager; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.Bundle; |
Hall Liu | 6d4b66d | 2016-04-01 16:31:13 -0700 | [diff] [blame] | 40 | import android.os.Handler; |
| 41 | import android.os.Looper; |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 42 | import android.os.Process; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 43 | import android.provider.BlockedNumberContract; |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 44 | import android.telecom.Call; |
| 45 | import android.telecom.CallAudioState; |
| 46 | import android.telecom.Connection; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 47 | import android.telecom.ConnectionRequest; |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 48 | import android.telecom.DisconnectCause; |
Brad Ebinger | a3eccfe | 2016-10-05 15:45:22 -0700 | [diff] [blame] | 49 | import android.telecom.Log; |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 50 | import android.telecom.ParcelableCall; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 51 | import android.telecom.PhoneAccount; |
| 52 | import android.telecom.PhoneAccountHandle; |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 53 | import android.telecom.TelecomManager; |
| 54 | import android.telecom.VideoProfile; |
Brad Ebinger | 68d17c6 | 2017-04-11 17:14:11 -0700 | [diff] [blame] | 55 | import android.support.test.filters.FlakyTest; |
Santos Cordon | 2ce9f71 | 2016-01-28 11:53:57 -0800 | [diff] [blame] | 56 | import android.test.suitebuilder.annotation.LargeTest; |
| 57 | import android.test.suitebuilder.annotation.MediumTest; |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 58 | |
| 59 | import com.android.internal.telecom.IInCallAdapter; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 60 | import com.android.internal.telephony.CallerInfo; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 61 | |
| 62 | import com.google.common.base.Predicate; |
| 63 | |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 64 | import org.junit.After; |
| 65 | import org.junit.Before; |
| 66 | import org.junit.Test; |
| 67 | import org.junit.runner.RunWith; |
| 68 | import org.junit.runners.JUnit4; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 69 | import org.mockito.invocation.InvocationOnMock; |
| 70 | import org.mockito.stubbing.Answer; |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 71 | |
Omata Shou | 6bc865c | 2017-07-26 13:39:27 +0900 | [diff] [blame] | 72 | import java.util.List; |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 73 | import java.util.concurrent.BrokenBarrierException; |
| 74 | import java.util.concurrent.CountDownLatch; |
| 75 | import java.util.concurrent.CyclicBarrier; |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 76 | import java.util.concurrent.TimeUnit; |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 77 | |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 78 | import org.mockito.ArgumentCaptor; |
| 79 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 80 | /** |
| 81 | * Performs various basic call tests in Telecom. |
| 82 | */ |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 83 | @RunWith(JUnit4.class) |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 84 | public class BasicCallTests extends TelecomSystemTest { |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 85 | private static final String TEST_BUNDLE_KEY = "android.telecom.extra.TEST"; |
| 86 | private static final String TEST_EVENT = "android.telecom.event.TEST"; |
| 87 | |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 88 | @Override |
| 89 | @Before |
| 90 | public void setUp() throws Exception { |
| 91 | super.setUp(); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | @After |
| 96 | public void tearDown() throws Exception { |
| 97 | super.tearDown(); |
| 98 | } |
| 99 | |
Santos Cordon | 2ce9f71 | 2016-01-28 11:53:57 -0800 | [diff] [blame] | 100 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 101 | @Test |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 102 | public void testSingleOutgoingCallLocalDisconnect() throws Exception { |
| 103 | IdPair ids = startAndMakeActiveOutgoingCall("650-555-1212", |
| 104 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 105 | |
| 106 | mInCallServiceFixtureX.mInCallAdapter.disconnectCall(ids.mCallId); |
| 107 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 108 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 109 | |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 110 | when(mClockProxy.currentTimeMillis()).thenReturn(TEST_DISCONNECT_TIME); |
| 111 | when(mClockProxy.elapsedRealtime()).thenReturn(TEST_DISCONNECT_ELAPSED_TIME); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 112 | mConnectionServiceFixtureA.sendSetDisconnected(ids.mConnectionId, DisconnectCause.LOCAL); |
| 113 | assertEquals(Call.STATE_DISCONNECTED, |
| 114 | mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 115 | assertEquals(Call.STATE_DISCONNECTED, |
| 116 | mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 117 | assertEquals(TEST_CONNECT_TIME, |
| 118 | mInCallServiceFixtureX.getCall(ids.mCallId).getConnectTimeMillis()); |
| 119 | assertEquals(TEST_CONNECT_TIME, |
| 120 | mInCallServiceFixtureY.getCall(ids.mCallId).getConnectTimeMillis()); |
| 121 | assertEquals(TEST_CREATE_TIME, |
| 122 | mInCallServiceFixtureX.getCall(ids.mCallId).getCreationTimeMillis()); |
| 123 | assertEquals(TEST_CREATE_TIME, |
| 124 | mInCallServiceFixtureY.getCall(ids.mCallId).getCreationTimeMillis()); |
| 125 | |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 126 | verifyNoBlockChecks(); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 127 | } |
| 128 | |
Santos Cordon | 2ce9f71 | 2016-01-28 11:53:57 -0800 | [diff] [blame] | 129 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 130 | @Test |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 131 | public void testSingleOutgoingCallRemoteDisconnect() throws Exception { |
| 132 | IdPair ids = startAndMakeActiveOutgoingCall("650-555-1212", |
| 133 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 134 | |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 135 | when(mClockProxy.currentTimeMillis()).thenReturn(TEST_DISCONNECT_TIME); |
| 136 | when(mClockProxy.elapsedRealtime()).thenReturn(TEST_DISCONNECT_ELAPSED_TIME); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 137 | mConnectionServiceFixtureA.sendSetDisconnected(ids.mConnectionId, DisconnectCause.LOCAL); |
| 138 | assertEquals(Call.STATE_DISCONNECTED, |
| 139 | mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 140 | assertEquals(Call.STATE_DISCONNECTED, |
| 141 | mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 142 | verifyNoBlockChecks(); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Tests the {@link TelecomManager#acceptRingingCall()} API. Tests simple case of an incoming |
| 147 | * audio-only call. |
| 148 | * |
| 149 | * @throws Exception |
| 150 | */ |
Santos Cordon | 2ce9f71 | 2016-01-28 11:53:57 -0800 | [diff] [blame] | 151 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 152 | @Test |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 153 | public void testTelecomManagerAcceptRingingCall() throws Exception { |
| 154 | IdPair ids = startIncomingPhoneCall("650-555-1212", mPhoneAccountA0.getAccountHandle(), |
| 155 | mConnectionServiceFixtureA); |
| 156 | |
| 157 | assertEquals(Call.STATE_RINGING, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 158 | assertEquals(Call.STATE_RINGING, mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 159 | |
| 160 | // Use TelecomManager API to answer the ringing call. |
| 161 | TelecomManager telecomManager = (TelecomManager) mComponentContextFixture.getTestDouble() |
| 162 | .getApplicationContext().getSystemService(Context.TELECOM_SERVICE); |
| 163 | telecomManager.acceptRingingCall(); |
| 164 | |
| 165 | verify(mConnectionServiceFixtureA.getTestDouble(), timeout(TEST_TIMEOUT)) |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 166 | .answer(eq(ids.mConnectionId), any()); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 167 | mConnectionServiceFixtureA.sendSetActive(ids.mConnectionId); |
| 168 | |
| 169 | mInCallServiceFixtureX.mInCallAdapter.disconnectCall(ids.mCallId); |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Tests the {@link TelecomManager#acceptRingingCall()} API. Tests simple case of an incoming |
| 174 | * video call, which should be answered as video. |
| 175 | * |
| 176 | * @throws Exception |
| 177 | */ |
Santos Cordon | 2ce9f71 | 2016-01-28 11:53:57 -0800 | [diff] [blame] | 178 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 179 | @Test |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 180 | public void testTelecomManagerAcceptRingingVideoCall() throws Exception { |
| 181 | IdPair ids = startIncomingPhoneCall("650-555-1212", mPhoneAccountA0.getAccountHandle(), |
| 182 | VideoProfile.STATE_BIDIRECTIONAL, mConnectionServiceFixtureA); |
| 183 | |
| 184 | assertEquals(Call.STATE_RINGING, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 185 | assertEquals(Call.STATE_RINGING, mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 186 | |
| 187 | // Use TelecomManager API to answer the ringing call; the default expected behavior is to |
| 188 | // answer using whatever video state the ringing call requests. |
| 189 | TelecomManager telecomManager = (TelecomManager) mComponentContextFixture.getTestDouble() |
| 190 | .getApplicationContext().getSystemService(Context.TELECOM_SERVICE); |
| 191 | telecomManager.acceptRingingCall(); |
| 192 | |
| 193 | // Answer video API should be called |
| 194 | verify(mConnectionServiceFixtureA.getTestDouble(), timeout(TEST_TIMEOUT)) |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 195 | .answerVideo(eq(ids.mConnectionId), eq(VideoProfile.STATE_BIDIRECTIONAL), any()); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 196 | mConnectionServiceFixtureA.sendSetActive(ids.mConnectionId); |
| 197 | |
| 198 | mInCallServiceFixtureX.mInCallAdapter.disconnectCall(ids.mCallId); |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Tests the {@link TelecomManager#acceptRingingCall(int)} API. Tests answering a video call |
| 203 | * as an audio call. |
| 204 | * |
| 205 | * @throws Exception |
| 206 | */ |
Santos Cordon | 2ce9f71 | 2016-01-28 11:53:57 -0800 | [diff] [blame] | 207 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 208 | @Test |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 209 | public void testTelecomManagerAcceptRingingVideoCallAsAudio() throws Exception { |
| 210 | IdPair ids = startIncomingPhoneCall("650-555-1212", mPhoneAccountA0.getAccountHandle(), |
| 211 | VideoProfile.STATE_BIDIRECTIONAL, mConnectionServiceFixtureA); |
| 212 | |
| 213 | assertEquals(Call.STATE_RINGING, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 214 | assertEquals(Call.STATE_RINGING, mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 215 | |
| 216 | // Use TelecomManager API to answer the ringing call. |
| 217 | TelecomManager telecomManager = (TelecomManager) mComponentContextFixture.getTestDouble() |
| 218 | .getApplicationContext().getSystemService(Context.TELECOM_SERVICE); |
| 219 | telecomManager.acceptRingingCall(VideoProfile.STATE_AUDIO_ONLY); |
| 220 | |
| 221 | // The generic answer method on the ConnectionService is used to answer audio-only calls. |
| 222 | verify(mConnectionServiceFixtureA.getTestDouble(), timeout(TEST_TIMEOUT)) |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 223 | .answer(eq(ids.mConnectionId), any()); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 224 | mConnectionServiceFixtureA.sendSetActive(ids.mConnectionId); |
| 225 | |
| 226 | mInCallServiceFixtureX.mInCallAdapter.disconnectCall(ids.mCallId); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Tests the {@link TelecomManager#acceptRingingCall()} API. Tests simple case of an incoming |
| 231 | * video call, where an attempt is made to answer with an invalid video state. |
| 232 | * |
| 233 | * @throws Exception |
| 234 | */ |
Santos Cordon | 2ce9f71 | 2016-01-28 11:53:57 -0800 | [diff] [blame] | 235 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 236 | @Test |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 237 | public void testTelecomManagerAcceptRingingInvalidVideoState() throws Exception { |
| 238 | IdPair ids = startIncomingPhoneCall("650-555-1212", mPhoneAccountA0.getAccountHandle(), |
| 239 | VideoProfile.STATE_BIDIRECTIONAL, mConnectionServiceFixtureA); |
| 240 | |
| 241 | assertEquals(Call.STATE_RINGING, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 242 | assertEquals(Call.STATE_RINGING, mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 243 | |
| 244 | // Use TelecomManager API to answer the ringing call; the default expected behavior is to |
| 245 | // answer using whatever video state the ringing call requests. |
| 246 | TelecomManager telecomManager = (TelecomManager) mComponentContextFixture.getTestDouble() |
| 247 | .getApplicationContext().getSystemService(Context.TELECOM_SERVICE); |
| 248 | telecomManager.acceptRingingCall(999 /* invalid videostate */); |
| 249 | |
| 250 | // Answer video API should be called |
| 251 | verify(mConnectionServiceFixtureA.getTestDouble(), timeout(TEST_TIMEOUT)) |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 252 | .answerVideo(eq(ids.mConnectionId), eq(VideoProfile.STATE_BIDIRECTIONAL), any()); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 253 | mConnectionServiceFixtureA.sendSetActive(ids.mConnectionId); |
| 254 | mInCallServiceFixtureX.mInCallAdapter.disconnectCall(ids.mCallId); |
| 255 | } |
| 256 | |
Santos Cordon | 2ce9f71 | 2016-01-28 11:53:57 -0800 | [diff] [blame] | 257 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 258 | @Test |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 259 | public void testSingleIncomingCallLocalDisconnect() throws Exception { |
| 260 | IdPair ids = startAndMakeActiveIncomingCall("650-555-1212", |
| 261 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 262 | mInCallServiceFixtureX.mInCallAdapter.disconnectCall(ids.mCallId); |
| 263 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 264 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 265 | |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 266 | when(mClockProxy.currentTimeMillis()).thenReturn(TEST_DISCONNECT_TIME); |
| 267 | when(mClockProxy.elapsedRealtime()).thenReturn(TEST_DISCONNECT_ELAPSED_TIME); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 268 | mConnectionServiceFixtureA.sendSetDisconnected(ids.mConnectionId, DisconnectCause.LOCAL); |
| 269 | assertEquals(Call.STATE_DISCONNECTED, |
| 270 | mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 271 | assertEquals(Call.STATE_DISCONNECTED, |
| 272 | mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 273 | } |
| 274 | |
Santos Cordon | 2ce9f71 | 2016-01-28 11:53:57 -0800 | [diff] [blame] | 275 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 276 | @Test |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 277 | public void testSingleIncomingCallRemoteDisconnect() throws Exception { |
| 278 | IdPair ids = startAndMakeActiveIncomingCall("650-555-1212", |
| 279 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 280 | |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 281 | when(mClockProxy.currentTimeMillis()).thenReturn(TEST_DISCONNECT_TIME); |
| 282 | when(mClockProxy.elapsedRealtime()).thenReturn(TEST_DISCONNECT_ELAPSED_TIME); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 283 | mConnectionServiceFixtureA.sendSetDisconnected(ids.mConnectionId, DisconnectCause.LOCAL); |
| 284 | assertEquals(Call.STATE_DISCONNECTED, |
| 285 | mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 286 | assertEquals(Call.STATE_DISCONNECTED, |
| 287 | mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 288 | } |
| 289 | |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 290 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 291 | @Test |
mike dooley | 66f26d1 | 2016-12-19 13:25:47 -0800 | [diff] [blame] | 292 | public void testIncomingEmergencyCallback() throws Exception { |
| 293 | // Make an outgoing emergency call |
| 294 | String phoneNumber = "650-555-1212"; |
| 295 | IdPair ids = startAndMakeDialingEmergencyCall(phoneNumber, |
| 296 | mPhoneAccountE0.getAccountHandle(), mConnectionServiceFixtureA); |
| 297 | mInCallServiceFixtureX.mInCallAdapter.disconnectCall(ids.mCallId); |
| 298 | mConnectionServiceFixtureA.sendSetDisconnected(ids.mConnectionId, DisconnectCause.LOCAL); |
| 299 | |
| 300 | // Incoming call should be marked as a potential emergency callback |
| 301 | Bundle extras = new Bundle(); |
| 302 | extras.putParcelable( |
| 303 | TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, |
| 304 | Uri.fromParts(PhoneAccount.SCHEME_TEL, phoneNumber, null)); |
| 305 | mTelecomSystem.getTelecomServiceImpl().getBinder() |
| 306 | .addNewIncomingCall(mPhoneAccountA0.getAccountHandle(), extras); |
| 307 | |
| 308 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
| 309 | ArgumentCaptor<ConnectionRequest> connectionRequestCaptor |
| 310 | = ArgumentCaptor.forClass(ConnectionRequest.class); |
| 311 | verify(mConnectionServiceFixtureA.getTestDouble()) |
| 312 | .createConnection(any(PhoneAccountHandle.class), anyString(), |
| 313 | connectionRequestCaptor.capture(), eq(true), eq(false), any()); |
| 314 | |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 315 | assertTrue(connectionRequestCaptor.getValue().getExtras().containsKey( |
mike dooley | 66f26d1 | 2016-12-19 13:25:47 -0800 | [diff] [blame] | 316 | android.telecom.Call.EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS)); |
| 317 | assertTrue(connectionRequestCaptor.getValue().getExtras().getLong( |
| 318 | android.telecom.Call.EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS, 0) > 0); |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 319 | assertTrue(connectionRequestCaptor.getValue().getExtras().containsKey( |
mike dooley | a2b067e | 2017-02-13 19:41:10 -0800 | [diff] [blame] | 320 | TelecomManager.EXTRA_INCOMING_CALL_ADDRESS)); |
mike dooley | 66f26d1 | 2016-12-19 13:25:47 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 324 | @Test |
Brad Ebinger | c301b51 | 2016-03-16 18:27:57 -0700 | [diff] [blame] | 325 | public void testOutgoingCallAndSelectPhoneAccount() throws Exception { |
| 326 | // Remove default PhoneAccount so that the Call moves into the correct |
| 327 | // SELECT_PHONE_ACCOUNT state. |
| 328 | mTelecomSystem.getPhoneAccountRegistrar().setUserSelectedOutgoingPhoneAccount( |
| 329 | null, Process.myUserHandle()); |
| 330 | int startingNumConnections = mConnectionServiceFixtureA.mConnectionById.size(); |
| 331 | int startingNumCalls = mInCallServiceFixtureX.mCallById.size(); |
| 332 | String callId = startOutgoingPhoneCallWithNoPhoneAccount("650-555-1212", |
| 333 | mConnectionServiceFixtureA); |
| 334 | assertEquals(Call.STATE_SELECT_PHONE_ACCOUNT, |
| 335 | mInCallServiceFixtureX.getCall(callId).getState()); |
| 336 | assertEquals(Call.STATE_SELECT_PHONE_ACCOUNT, |
| 337 | mInCallServiceFixtureY.getCall(callId).getState()); |
| 338 | mInCallServiceFixtureX.mInCallAdapter.phoneAccountSelected(callId, |
| 339 | mPhoneAccountA0.getAccountHandle(), false); |
| 340 | |
| 341 | IdPair ids = outgoingCallPhoneAccountSelected(mPhoneAccountA0.getAccountHandle(), |
| 342 | startingNumConnections, startingNumCalls, mConnectionServiceFixtureA); |
| 343 | |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 344 | when(mClockProxy.currentTimeMillis()).thenReturn(TEST_DISCONNECT_TIME); |
| 345 | when(mClockProxy.elapsedRealtime()).thenReturn(TEST_DISCONNECT_ELAPSED_TIME); |
Brad Ebinger | c301b51 | 2016-03-16 18:27:57 -0700 | [diff] [blame] | 346 | mConnectionServiceFixtureA.sendSetDisconnected(ids.mConnectionId, DisconnectCause.LOCAL); |
| 347 | assertEquals(Call.STATE_DISCONNECTED, |
| 348 | mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 349 | assertEquals(Call.STATE_DISCONNECTED, |
| 350 | mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 351 | } |
| 352 | |
| 353 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 354 | @Test |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 355 | public void testIncomingCallFromContactWithSendToVoicemailIsRejected() throws Exception { |
| 356 | Bundle extras = new Bundle(); |
| 357 | extras.putParcelable( |
| 358 | TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, |
| 359 | Uri.fromParts(PhoneAccount.SCHEME_TEL, "650-555-1212", null)); |
| 360 | mTelecomSystem.getTelecomServiceImpl().getBinder() |
| 361 | .addNewIncomingCall(mPhoneAccountA0.getAccountHandle(), extras); |
| 362 | |
Hall Liu | 6d4b66d | 2016-04-01 16:31:13 -0700 | [diff] [blame] | 363 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 364 | verify(mConnectionServiceFixtureA.getTestDouble()) |
| 365 | .createConnection(any(PhoneAccountHandle.class), anyString(), |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 366 | any(ConnectionRequest.class), eq(true), eq(false), any()); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 367 | |
Hall Liu | 609992b | 2016-08-31 15:48:51 -0700 | [diff] [blame] | 368 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 369 | assertEquals(1, mCallerInfoAsyncQueryFactoryFixture.mRequests.size()); |
| 370 | for (CallerInfoAsyncQueryFactoryFixture.Request request : |
| 371 | mCallerInfoAsyncQueryFactoryFixture.mRequests) { |
| 372 | CallerInfo sendToVoicemailCallerInfo = new CallerInfo(); |
| 373 | sendToVoicemailCallerInfo.shouldSendToVoicemail = true; |
| 374 | request.replyWithCallerInfo(sendToVoicemailCallerInfo); |
| 375 | } |
| 376 | |
| 377 | assertTrueWithTimeout(new Predicate<Void>() { |
| 378 | @Override |
| 379 | public boolean apply(Void aVoid) { |
| 380 | return mConnectionServiceFixtureA.mConnectionService.rejectedCallIds.size() == 1; |
| 381 | } |
| 382 | }); |
| 383 | assertTrueWithTimeout(new Predicate<Void>() { |
| 384 | @Override |
| 385 | public boolean apply(Void aVoid) { |
| 386 | return mMissedCallNotifier.missedCallsNotified.size() == 1; |
| 387 | } |
| 388 | }); |
| 389 | |
| 390 | verify(mInCallServiceFixtureX.getTestDouble(), never()) |
| 391 | .setInCallAdapter(any(IInCallAdapter.class)); |
| 392 | verify(mInCallServiceFixtureY.getTestDouble(), never()) |
| 393 | .setInCallAdapter(any(IInCallAdapter.class)); |
| 394 | } |
| 395 | |
| 396 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 397 | @Test |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 398 | public void testIncomingCallCallerInfoLookupTimesOutIsAllowed() throws Exception { |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 399 | when(mClockProxy.currentTimeMillis()).thenReturn(TEST_CREATE_TIME); |
| 400 | when(mClockProxy.elapsedRealtime()).thenReturn(TEST_CREATE_ELAPSED_TIME); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 401 | Bundle extras = new Bundle(); |
| 402 | extras.putParcelable( |
| 403 | TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, |
| 404 | Uri.fromParts(PhoneAccount.SCHEME_TEL, "650-555-1212", null)); |
| 405 | mTelecomSystem.getTelecomServiceImpl().getBinder() |
| 406 | .addNewIncomingCall(mPhoneAccountA0.getAccountHandle(), extras); |
| 407 | |
Hall Liu | 609992b | 2016-08-31 15:48:51 -0700 | [diff] [blame] | 408 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 409 | verify(mConnectionServiceFixtureA.getTestDouble()) |
| 410 | .createConnection(any(PhoneAccountHandle.class), anyString(), |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 411 | any(ConnectionRequest.class), eq(true), eq(false), any()); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 412 | |
Hall Liu | 609992b | 2016-08-31 15:48:51 -0700 | [diff] [blame] | 413 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 414 | // Never reply to the caller info lookup. |
| 415 | assertEquals(1, mCallerInfoAsyncQueryFactoryFixture.mRequests.size()); |
| 416 | |
| 417 | verify(mInCallServiceFixtureX.getTestDouble(), timeout(TEST_TIMEOUT)) |
| 418 | .setInCallAdapter(any(IInCallAdapter.class)); |
Hall Liu | 805c453 | 2016-03-17 13:39:26 -0700 | [diff] [blame] | 419 | verify(mInCallServiceFixtureY.getTestDouble(), timeout(TEST_TIMEOUT)) |
| 420 | .setInCallAdapter(any(IInCallAdapter.class)); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 421 | |
| 422 | assertEquals(0, mConnectionServiceFixtureA.mConnectionService.rejectedCallIds.size()); |
| 423 | assertEquals(0, mMissedCallNotifier.missedCallsNotified.size()); |
| 424 | |
| 425 | assertTrueWithTimeout(new Predicate<Void>() { |
| 426 | @Override |
| 427 | public boolean apply(Void v) { |
| 428 | return mInCallServiceFixtureX.mInCallAdapter != null; |
| 429 | } |
| 430 | }); |
| 431 | |
| 432 | verify(mInCallServiceFixtureX.getTestDouble(), timeout(TEST_TIMEOUT)) |
| 433 | .addCall(any(ParcelableCall.class)); |
Hall Liu | 805c453 | 2016-03-17 13:39:26 -0700 | [diff] [blame] | 434 | verify(mInCallServiceFixtureY.getTestDouble(), timeout(TEST_TIMEOUT)) |
| 435 | .addCall(any(ParcelableCall.class)); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 436 | |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 437 | when(mClockProxy.currentTimeMillis()).thenReturn(TEST_CONNECT_TIME); |
| 438 | when(mClockProxy.elapsedRealtime()).thenReturn(TEST_CONNECT_ELAPSED_TIME); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 439 | disconnectCall(mInCallServiceFixtureX.mLatestCallId, |
| 440 | mConnectionServiceFixtureA.mLatestConnectionId); |
| 441 | } |
| 442 | |
| 443 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 444 | @Test |
Tyler Gunn | b652dad | 2018-03-27 18:49:49 +0000 | [diff] [blame] | 445 | @FlakyTest |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 446 | public void testIncomingCallFromBlockedNumberIsRejected() throws Exception { |
| 447 | String phoneNumber = "650-555-1212"; |
| 448 | blockNumber(phoneNumber); |
| 449 | |
| 450 | Bundle extras = new Bundle(); |
| 451 | extras.putParcelable( |
| 452 | TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, |
| 453 | Uri.fromParts(PhoneAccount.SCHEME_TEL, phoneNumber, null)); |
| 454 | mTelecomSystem.getTelecomServiceImpl().getBinder() |
| 455 | .addNewIncomingCall(mPhoneAccountA0.getAccountHandle(), extras); |
| 456 | |
Hall Liu | 609992b | 2016-08-31 15:48:51 -0700 | [diff] [blame] | 457 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 458 | verify(mConnectionServiceFixtureA.getTestDouble()) |
| 459 | .createConnection(any(PhoneAccountHandle.class), anyString(), |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 460 | any(ConnectionRequest.class), eq(true), eq(false), any()); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 461 | |
Hall Liu | 609992b | 2016-08-31 15:48:51 -0700 | [diff] [blame] | 462 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 463 | assertEquals(1, mCallerInfoAsyncQueryFactoryFixture.mRequests.size()); |
| 464 | for (CallerInfoAsyncQueryFactoryFixture.Request request : |
| 465 | mCallerInfoAsyncQueryFactoryFixture.mRequests) { |
| 466 | request.reply(); |
| 467 | } |
| 468 | |
| 469 | assertTrueWithTimeout(new Predicate<Void>() { |
| 470 | @Override |
| 471 | public boolean apply(Void aVoid) { |
| 472 | return mConnectionServiceFixtureA.mConnectionService.rejectedCallIds.size() == 1; |
| 473 | } |
| 474 | }); |
| 475 | assertEquals(0, mMissedCallNotifier.missedCallsNotified.size()); |
| 476 | |
| 477 | verify(mInCallServiceFixtureX.getTestDouble(), never()) |
| 478 | .setInCallAdapter(any(IInCallAdapter.class)); |
| 479 | verify(mInCallServiceFixtureY.getTestDouble(), never()) |
| 480 | .setInCallAdapter(any(IInCallAdapter.class)); |
| 481 | } |
| 482 | |
| 483 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 484 | @Test |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 485 | public void testIncomingCallBlockCheckTimesoutIsAllowed() throws Exception { |
| 486 | final CountDownLatch latch = new CountDownLatch(1); |
| 487 | String phoneNumber = "650-555-1212"; |
| 488 | blockNumberWithAnswer(phoneNumber, new Answer<Bundle>() { |
| 489 | @Override |
| 490 | public Bundle answer(InvocationOnMock invocation) throws Throwable { |
| 491 | latch.await(TEST_TIMEOUT * 2, TimeUnit.MILLISECONDS); |
| 492 | Bundle bundle = new Bundle(); |
| 493 | bundle.putBoolean(BlockedNumberContract.RES_NUMBER_IS_BLOCKED, true); |
| 494 | return bundle; |
| 495 | } |
| 496 | }); |
| 497 | |
| 498 | IdPair ids = startAndMakeActiveIncomingCall( |
| 499 | phoneNumber, mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 500 | latch.countDown(); |
| 501 | |
| 502 | assertEquals(0, mConnectionServiceFixtureA.mConnectionService.rejectedCallIds.size()); |
| 503 | assertEquals(0, mMissedCallNotifier.missedCallsNotified.size()); |
| 504 | disconnectCall(ids.mCallId, ids.mConnectionId); |
| 505 | } |
| 506 | |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 507 | public void do_testDeadlockOnOutgoingCall() throws Exception { |
| 508 | final IdPair ids = startOutgoingPhoneCall("650-555-1212", |
| 509 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA, |
| 510 | Process.myUserHandle()); |
| 511 | rapidFire( |
| 512 | new Runnable() { |
| 513 | @Override |
| 514 | public void run() { |
| 515 | while (mCallerInfoAsyncQueryFactoryFixture.mRequests.size() > 0) { |
| 516 | mCallerInfoAsyncQueryFactoryFixture.mRequests.remove(0).reply(); |
| 517 | } |
| 518 | } |
| 519 | }, |
| 520 | new Runnable() { |
| 521 | @Override |
| 522 | public void run() { |
| 523 | try { |
| 524 | mConnectionServiceFixtureA.sendSetActive(ids.mConnectionId); |
| 525 | } catch (Exception e) { |
| 526 | Log.e(this, e, ""); |
| 527 | } |
| 528 | } |
| 529 | }); |
| 530 | } |
| 531 | |
Santos Cordon | 2ce9f71 | 2016-01-28 11:53:57 -0800 | [diff] [blame] | 532 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 533 | @Test |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 534 | public void testIncomingThenOutgoingCalls() throws Exception { |
| 535 | // TODO: We have to use the same PhoneAccount for both; see http://b/18461539 |
| 536 | IdPair incoming = startAndMakeActiveIncomingCall("650-555-2323", |
| 537 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 538 | IdPair outgoing = startAndMakeActiveOutgoingCall("650-555-1212", |
Hall Liu | ecd74a5 | 2016-01-12 15:26:36 -0800 | [diff] [blame] | 539 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 540 | |
| 541 | mInCallServiceFixtureX.mInCallAdapter.disconnectCall(incoming.mCallId); |
| 542 | mInCallServiceFixtureX.mInCallAdapter.disconnectCall(outgoing.mCallId); |
| 543 | } |
| 544 | |
Santos Cordon | 2ce9f71 | 2016-01-28 11:53:57 -0800 | [diff] [blame] | 545 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 546 | @Test |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 547 | public void testOutgoingThenIncomingCalls() throws Exception { |
| 548 | // TODO: We have to use the same PhoneAccount for both; see http://b/18461539 |
| 549 | IdPair outgoing = startAndMakeActiveOutgoingCall("650-555-1212", |
| 550 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 551 | IdPair incoming = startAndMakeActiveIncomingCall("650-555-2323", |
| 552 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 553 | verify(mConnectionServiceFixtureA.getTestDouble()) |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 554 | .hold(eq(outgoing.mConnectionId), any()); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 555 | mConnectionServiceFixtureA.mConnectionById.get(outgoing.mConnectionId).state = |
| 556 | Connection.STATE_HOLDING; |
| 557 | mConnectionServiceFixtureA.sendSetOnHold(outgoing.mConnectionId); |
| 558 | assertEquals(Call.STATE_HOLDING, |
| 559 | mInCallServiceFixtureX.getCall(outgoing.mCallId).getState()); |
| 560 | assertEquals(Call.STATE_HOLDING, |
| 561 | mInCallServiceFixtureY.getCall(outgoing.mCallId).getState()); |
| 562 | |
| 563 | mInCallServiceFixtureX.mInCallAdapter.disconnectCall(incoming.mCallId); |
| 564 | mInCallServiceFixtureX.mInCallAdapter.disconnectCall(outgoing.mCallId); |
| 565 | } |
| 566 | |
Hall Liu | a3799ae | 2016-03-16 11:37:51 -0700 | [diff] [blame] | 567 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 568 | @Test |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 569 | public void testAudioManagerOperations() throws Exception { |
| 570 | AudioManager audioManager = (AudioManager) mComponentContextFixture.getTestDouble() |
| 571 | .getApplicationContext().getSystemService(Context.AUDIO_SERVICE); |
| 572 | |
| 573 | IdPair outgoing = startAndMakeActiveOutgoingCall("650-555-1212", |
| 574 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 575 | |
| 576 | verify(audioManager, timeout(TEST_TIMEOUT)).requestAudioFocusForCall(anyInt(), anyInt()); |
| 577 | verify(audioManager, timeout(TEST_TIMEOUT).atLeastOnce()) |
| 578 | .setMode(AudioManager.MODE_IN_CALL); |
| 579 | |
| 580 | mInCallServiceFixtureX.mInCallAdapter.mute(true); |
| 581 | verify(mAudioService, timeout(TEST_TIMEOUT)) |
| 582 | .setMicrophoneMute(eq(true), any(String.class), any(Integer.class)); |
| 583 | mInCallServiceFixtureX.mInCallAdapter.mute(false); |
| 584 | verify(mAudioService, timeout(TEST_TIMEOUT)) |
| 585 | .setMicrophoneMute(eq(false), any(String.class), any(Integer.class)); |
| 586 | |
Hall Liu | 9086fb1 | 2017-11-07 18:01:53 -0800 | [diff] [blame] | 587 | mInCallServiceFixtureX.mInCallAdapter.setAudioRoute(CallAudioState.ROUTE_SPEAKER, null); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 588 | verify(audioManager, timeout(TEST_TIMEOUT)) |
| 589 | .setSpeakerphoneOn(true); |
Hall Liu | 9086fb1 | 2017-11-07 18:01:53 -0800 | [diff] [blame] | 590 | mInCallServiceFixtureX.mInCallAdapter.setAudioRoute(CallAudioState.ROUTE_EARPIECE, null); |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 591 | verify(audioManager, timeout(TEST_TIMEOUT)) |
| 592 | .setSpeakerphoneOn(false); |
| 593 | |
| 594 | mConnectionServiceFixtureA. |
| 595 | sendSetDisconnected(outgoing.mConnectionId, DisconnectCause.REMOTE); |
| 596 | |
| 597 | verify(audioManager, timeout(TEST_TIMEOUT)) |
| 598 | .abandonAudioFocusForCall(); |
| 599 | verify(audioManager, timeout(TEST_TIMEOUT).atLeastOnce()) |
| 600 | .setMode(AudioManager.MODE_NORMAL); |
| 601 | } |
| 602 | |
| 603 | private void rapidFire(Runnable... tasks) { |
| 604 | final CyclicBarrier barrier = new CyclicBarrier(tasks.length); |
| 605 | final CountDownLatch latch = new CountDownLatch(tasks.length); |
| 606 | for (int i = 0; i < tasks.length; i++) { |
| 607 | final Runnable task = tasks[i]; |
| 608 | new Thread(new Runnable() { |
| 609 | @Override |
| 610 | public void run() { |
| 611 | try { |
| 612 | barrier.await(); |
| 613 | task.run(); |
| 614 | } catch (InterruptedException | BrokenBarrierException e){ |
| 615 | Log.e(BasicCallTests.this, e, "Unexpectedly interrupted"); |
| 616 | } finally { |
| 617 | latch.countDown(); |
| 618 | } |
| 619 | } |
| 620 | }).start(); |
| 621 | } |
| 622 | try { |
| 623 | latch.await(); |
| 624 | } catch (InterruptedException e) { |
| 625 | Log.e(BasicCallTests.this, e, "Unexpectedly interrupted"); |
| 626 | } |
| 627 | } |
| 628 | |
Santos Cordon | 2ce9f71 | 2016-01-28 11:53:57 -0800 | [diff] [blame] | 629 | @MediumTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 630 | @Test |
Hall Liu | ecd74a5 | 2016-01-12 15:26:36 -0800 | [diff] [blame] | 631 | public void testBasicConferenceCall() throws Exception { |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 632 | makeConferenceCall(); |
| 633 | } |
| 634 | |
Santos Cordon | 2ce9f71 | 2016-01-28 11:53:57 -0800 | [diff] [blame] | 635 | @MediumTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 636 | @Test |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 637 | public void testAddCallToConference1() throws Exception { |
| 638 | ParcelableCall conferenceCall = makeConferenceCall(); |
| 639 | IdPair callId3 = startAndMakeActiveOutgoingCall("650-555-1214", |
| 640 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 641 | // testAddCallToConference{1,2} differ in the order of arguments to InCallAdapter#conference |
| 642 | mInCallServiceFixtureX.getInCallAdapter().conference( |
| 643 | conferenceCall.getId(), callId3.mCallId); |
| 644 | Thread.sleep(200); |
| 645 | |
| 646 | ParcelableCall call3 = mInCallServiceFixtureX.getCall(callId3.mCallId); |
| 647 | ParcelableCall updatedConference = mInCallServiceFixtureX.getCall(conferenceCall.getId()); |
| 648 | assertEquals(conferenceCall.getId(), call3.getParentCallId()); |
| 649 | assertEquals(3, updatedConference.getChildCallIds().size()); |
| 650 | assertTrue(updatedConference.getChildCallIds().contains(callId3.mCallId)); |
| 651 | } |
| 652 | |
Santos Cordon | 2ce9f71 | 2016-01-28 11:53:57 -0800 | [diff] [blame] | 653 | @MediumTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 654 | @Test |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 655 | public void testAddCallToConference2() throws Exception { |
| 656 | ParcelableCall conferenceCall = makeConferenceCall(); |
| 657 | IdPair callId3 = startAndMakeActiveOutgoingCall("650-555-1214", |
| 658 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 659 | mInCallServiceFixtureX.getInCallAdapter() |
| 660 | .conference(callId3.mCallId, conferenceCall.getId()); |
| 661 | Thread.sleep(200); |
| 662 | |
| 663 | ParcelableCall call3 = mInCallServiceFixtureX.getCall(callId3.mCallId); |
| 664 | ParcelableCall updatedConference = mInCallServiceFixtureX.getCall(conferenceCall.getId()); |
| 665 | assertEquals(conferenceCall.getId(), call3.getParentCallId()); |
| 666 | assertEquals(3, updatedConference.getChildCallIds().size()); |
| 667 | assertTrue(updatedConference.getChildCallIds().contains(callId3.mCallId)); |
| 668 | } |
| 669 | |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 670 | /** |
| 671 | * Tests the {@link Call#pullExternalCall()} API. Verifies that if a call is not an external |
| 672 | * call, no pull call request is made to the connection service. |
| 673 | * |
| 674 | * @throws Exception |
| 675 | */ |
| 676 | @MediumTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 677 | @Test |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 678 | public void testPullNonExternalCall() throws Exception { |
| 679 | // TODO: Revisit this unit test once telecom support for filtering external calls from |
| 680 | // InCall services is implemented. |
| 681 | IdPair ids = startAndMakeActiveIncomingCall("650-555-1212", |
| 682 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 683 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 684 | |
| 685 | // Attempt to pull the call and verify the API call makes it through |
| 686 | mInCallServiceFixtureX.mInCallAdapter.pullExternalCall(ids.mCallId); |
Hall Liu | 3037ac6 | 2016-09-22 14:40:03 -0700 | [diff] [blame] | 687 | Thread.sleep(TEST_TIMEOUT); |
| 688 | verify(mConnectionServiceFixtureA.getTestDouble(), never()) |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 689 | .pullExternalCall(eq(ids.mCallId), any()); |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | /** |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 693 | * Tests the {@link Connection#sendConnectionEvent(String, Bundle)} API. |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 694 | * |
| 695 | * @throws Exception |
| 696 | */ |
| 697 | @MediumTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 698 | @Test |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 699 | public void testSendConnectionEventNull() throws Exception { |
| 700 | IdPair ids = startAndMakeActiveIncomingCall("650-555-1212", |
| 701 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 702 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 703 | mConnectionServiceFixtureA.sendConnectionEvent(ids.mConnectionId, TEST_EVENT, null); |
| 704 | verify(mInCallServiceFixtureX.getTestDouble(), timeout(TEST_TIMEOUT)) |
| 705 | .onConnectionEvent(ids.mCallId, TEST_EVENT, null); |
| 706 | } |
| 707 | |
| 708 | /** |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 709 | * Tests the {@link Connection#sendConnectionEvent(String, Bundle)} API. |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 710 | * |
| 711 | * @throws Exception |
| 712 | */ |
| 713 | @MediumTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 714 | @Test |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 715 | public void testSendConnectionEventNotNull() throws Exception { |
| 716 | IdPair ids = startAndMakeActiveIncomingCall("650-555-1212", |
| 717 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 718 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 719 | |
| 720 | Bundle testBundle = new Bundle(); |
| 721 | testBundle.putString(TEST_BUNDLE_KEY, "TEST"); |
| 722 | |
| 723 | ArgumentCaptor<Bundle> bundleArgumentCaptor = ArgumentCaptor.forClass(Bundle.class); |
| 724 | mConnectionServiceFixtureA.sendConnectionEvent(ids.mConnectionId, TEST_EVENT, testBundle); |
| 725 | verify(mInCallServiceFixtureX.getTestDouble(), timeout(TEST_TIMEOUT)) |
| 726 | .onConnectionEvent(eq(ids.mCallId), eq(TEST_EVENT), bundleArgumentCaptor.capture()); |
| 727 | assert (bundleArgumentCaptor.getValue().containsKey(TEST_BUNDLE_KEY)); |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * Tests the {@link Call#sendCallEvent(String, Bundle)} API. |
| 732 | * |
| 733 | * @throws Exception |
| 734 | */ |
| 735 | @MediumTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 736 | @Test |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 737 | public void testSendCallEventNull() throws Exception { |
| 738 | IdPair ids = startAndMakeActiveIncomingCall("650-555-1212", |
| 739 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 740 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 741 | |
Sanket Padawe | b5de1cd | 2018-01-05 14:27:30 -0800 | [diff] [blame] | 742 | mInCallServiceFixtureX.mInCallAdapter.sendCallEvent(ids.mCallId, TEST_EVENT, 26, null); |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 743 | verify(mConnectionServiceFixtureA.getTestDouble(), timeout(TEST_TIMEOUT)) |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 744 | .sendCallEvent(eq(ids.mConnectionId), eq(TEST_EVENT), isNull(Bundle.class), any()); |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | /** |
| 748 | * Tests the {@link Call#sendCallEvent(String, Bundle)} API. |
| 749 | * |
| 750 | * @throws Exception |
| 751 | */ |
| 752 | @MediumTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 753 | @Test |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 754 | public void testSendCallEventNonNull() throws Exception { |
| 755 | IdPair ids = startAndMakeActiveIncomingCall("650-555-1212", |
| 756 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 757 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 758 | |
| 759 | Bundle testBundle = new Bundle(); |
| 760 | testBundle.putString(TEST_BUNDLE_KEY, "TEST"); |
| 761 | |
| 762 | ArgumentCaptor<Bundle> bundleArgumentCaptor = ArgumentCaptor.forClass(Bundle.class); |
Sanket Padawe | b5de1cd | 2018-01-05 14:27:30 -0800 | [diff] [blame] | 763 | mInCallServiceFixtureX.mInCallAdapter.sendCallEvent(ids.mCallId, TEST_EVENT, 26, |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 764 | testBundle); |
| 765 | verify(mConnectionServiceFixtureA.getTestDouble(), timeout(TEST_TIMEOUT)) |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 766 | .sendCallEvent(eq(ids.mConnectionId), eq(TEST_EVENT), |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 767 | bundleArgumentCaptor.capture(), any()); |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 768 | assert (bundleArgumentCaptor.getValue().containsKey(TEST_BUNDLE_KEY)); |
| 769 | } |
| 770 | |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 771 | private void blockNumber(String phoneNumber) throws Exception { |
| 772 | blockNumberWithAnswer(phoneNumber, new Answer<Bundle>() { |
| 773 | @Override |
| 774 | public Bundle answer(InvocationOnMock invocation) throws Throwable { |
| 775 | Bundle bundle = new Bundle(); |
| 776 | bundle.putBoolean(BlockedNumberContract.RES_NUMBER_IS_BLOCKED, true); |
| 777 | return bundle; |
| 778 | } |
| 779 | }); |
| 780 | } |
| 781 | |
| 782 | private void blockNumberWithAnswer(String phoneNumber, Answer answer) throws Exception { |
| 783 | when(getBlockedNumberProvider().call( |
| 784 | anyString(), |
| 785 | eq(BlockedNumberContract.SystemContract.METHOD_SHOULD_SYSTEM_BLOCK_NUMBER), |
| 786 | eq(phoneNumber), |
| 787 | isNull(Bundle.class))).thenAnswer(answer); |
| 788 | } |
| 789 | |
| 790 | private void verifyNoBlockChecks() { |
| 791 | verifyZeroInteractions(getBlockedNumberProvider()); |
| 792 | } |
| 793 | |
| 794 | private IContentProvider getBlockedNumberProvider() { |
| 795 | return mSpyContext.getContentResolver().acquireProvider(BlockedNumberContract.AUTHORITY); |
| 796 | } |
| 797 | |
| 798 | private void disconnectCall(String callId, String connectionId) throws Exception { |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 799 | when(mClockProxy.currentTimeMillis()).thenReturn(TEST_DISCONNECT_TIME); |
| 800 | when(mClockProxy.elapsedRealtime()).thenReturn(TEST_DISCONNECT_ELAPSED_TIME); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 801 | mConnectionServiceFixtureA.sendSetDisconnected(connectionId, DisconnectCause.LOCAL); |
| 802 | assertEquals(Call.STATE_DISCONNECTED, mInCallServiceFixtureX.getCall(callId).getState()); |
| 803 | assertEquals(Call.STATE_DISCONNECTED, mInCallServiceFixtureY.getCall(callId).getState()); |
Tyler Gunn | 8bb2b01 | 2017-08-04 09:28:59 -0700 | [diff] [blame] | 804 | assertEquals(TEST_CREATE_TIME, |
| 805 | mInCallServiceFixtureX.getCall(callId).getCreationTimeMillis()); |
| 806 | assertEquals(TEST_CREATE_TIME, |
| 807 | mInCallServiceFixtureY.getCall(callId).getCreationTimeMillis()); |
Abhijith Shastry | c6e42ef | 2016-02-19 18:26:44 -0800 | [diff] [blame] | 808 | } |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 809 | |
| 810 | /** |
Brad Ebinger | 84771f8 | 2016-05-18 16:57:30 -0700 | [diff] [blame] | 811 | * Tests to make sure that the Call.Details.PROPERTY_HAS_CDMA_VOICE_PRIVACY property is set on a |
| 812 | * Call that is based on a Connection with the Connection.PROPERTY_HAS_CDMA_VOICE_PRIVACY |
| 813 | * property set. |
| 814 | */ |
| 815 | @MediumTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 816 | @Test |
Brad Ebinger | 84771f8 | 2016-05-18 16:57:30 -0700 | [diff] [blame] | 817 | public void testCdmaEnhancedPrivacyVoiceCall() throws Exception { |
| 818 | mConnectionServiceFixtureA.mConnectionServiceDelegate.mProperties = |
| 819 | Connection.PROPERTY_HAS_CDMA_VOICE_PRIVACY; |
| 820 | |
| 821 | IdPair ids = startAndMakeActiveOutgoingCall("650-555-1212", |
| 822 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 823 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 824 | |
| 825 | assertTrue(Call.Details.hasProperty( |
| 826 | mInCallServiceFixtureX.getCall(ids.mCallId).getProperties(), |
| 827 | Call.Details.PROPERTY_HAS_CDMA_VOICE_PRIVACY)); |
| 828 | } |
| 829 | |
| 830 | /** |
| 831 | * Tests to make sure that Call.Details.PROPERTY_HAS_CDMA_VOICE_PRIVACY is dropped |
| 832 | * when the Connection.PROPERTY_HAS_CDMA_VOICE_PRIVACY property is removed from the Connection. |
| 833 | */ |
| 834 | @MediumTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 835 | @Test |
Brad Ebinger | 84771f8 | 2016-05-18 16:57:30 -0700 | [diff] [blame] | 836 | public void testDropCdmaEnhancedPrivacyVoiceCall() throws Exception { |
| 837 | mConnectionServiceFixtureA.mConnectionServiceDelegate.mProperties = |
| 838 | Connection.PROPERTY_HAS_CDMA_VOICE_PRIVACY; |
| 839 | |
| 840 | IdPair ids = startAndMakeActiveOutgoingCall("650-555-1212", |
| 841 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 842 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 843 | mConnectionServiceFixtureA.mLatestConnection.setConnectionProperties(0); |
| 844 | |
| 845 | assertFalse(Call.Details.hasProperty( |
| 846 | mInCallServiceFixtureX.getCall(ids.mCallId).getProperties(), |
| 847 | Call.Details.PROPERTY_HAS_CDMA_VOICE_PRIVACY)); |
| 848 | } |
| 849 | |
| 850 | /** |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 851 | * Tests the {@link Call#pullExternalCall()} API. Ensures that an external call which is |
| 852 | * pullable can be pulled. |
| 853 | * |
| 854 | * @throws Exception |
| 855 | */ |
| 856 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 857 | @Test |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 858 | public void testPullExternalCall() throws Exception { |
| 859 | // TODO: Revisit this unit test once telecom support for filtering external calls from |
| 860 | // InCall services is implemented. |
| 861 | mConnectionServiceFixtureA.mConnectionServiceDelegate.mCapabilities = |
Tyler Gunn | 571d5e6 | 2016-03-15 15:55:18 -0700 | [diff] [blame] | 862 | Connection.CAPABILITY_CAN_PULL_CALL; |
| 863 | mConnectionServiceFixtureA.mConnectionServiceDelegate.mProperties = |
| 864 | Connection.PROPERTY_IS_EXTERNAL_CALL; |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 865 | |
| 866 | IdPair ids = startAndMakeActiveIncomingCall("650-555-1212", |
| 867 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 868 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 869 | |
| 870 | // Attempt to pull the call and verify the API call makes it through |
| 871 | mInCallServiceFixtureX.mInCallAdapter.pullExternalCall(ids.mCallId); |
| 872 | verify(mConnectionServiceFixtureA.getTestDouble(), timeout(TEST_TIMEOUT)) |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 873 | .pullExternalCall(eq(ids.mConnectionId), any()); |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | /** |
| 877 | * Tests the {@link Call#pullExternalCall()} API. Verifies that if an external call is not |
| 878 | * marked as pullable that the connection service does not get an API call to pull the external |
| 879 | * call. |
| 880 | * |
| 881 | * @throws Exception |
| 882 | */ |
| 883 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 884 | @Test |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 885 | public void testPullNonPullableExternalCall() throws Exception { |
| 886 | // TODO: Revisit this unit test once telecom support for filtering external calls from |
| 887 | // InCall services is implemented. |
Tyler Gunn | 571d5e6 | 2016-03-15 15:55:18 -0700 | [diff] [blame] | 888 | mConnectionServiceFixtureA.mConnectionServiceDelegate.mProperties = |
| 889 | Connection.PROPERTY_IS_EXTERNAL_CALL; |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 890 | |
| 891 | IdPair ids = startAndMakeActiveIncomingCall("650-555-1212", |
| 892 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 893 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 894 | |
| 895 | // Attempt to pull the call and verify the API call makes it through |
| 896 | mInCallServiceFixtureX.mInCallAdapter.pullExternalCall(ids.mCallId); |
Hall Liu | 3037ac6 | 2016-09-22 14:40:03 -0700 | [diff] [blame] | 897 | Thread.sleep(TEST_TIMEOUT); |
| 898 | verify(mConnectionServiceFixtureA.getTestDouble(), never()) |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 899 | .pullExternalCall(eq(ids.mConnectionId), any()); |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 900 | } |
Brad Ebinger | 0d40255 | 2016-05-27 16:02:53 -0700 | [diff] [blame] | 901 | |
Tyler Gunn | ddec589 | 2016-09-28 10:26:13 -0700 | [diff] [blame] | 902 | /** |
| 903 | * Test scenario where the user starts an outgoing video call with no selected PhoneAccount, and |
| 904 | * then subsequently selects a PhoneAccount which supports video calling. |
| 905 | * @throws Exception |
| 906 | */ |
| 907 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 908 | @Test |
Tyler Gunn | ddec589 | 2016-09-28 10:26:13 -0700 | [diff] [blame] | 909 | public void testOutgoingCallSelectPhoneAccountVideo() throws Exception { |
| 910 | startOutgoingPhoneCallPendingCreateConnection("650-555-1212", |
| 911 | null, mConnectionServiceFixtureA, |
| 912 | Process.myUserHandle(), VideoProfile.STATE_BIDIRECTIONAL); |
| 913 | com.android.server.telecom.Call call = mTelecomSystem.getCallsManager().getCalls() |
| 914 | .iterator().next(); |
| 915 | assert(call.isVideoCallingSupported()); |
| 916 | assertEquals(VideoProfile.STATE_BIDIRECTIONAL, call.getVideoState()); |
| 917 | |
| 918 | // Change the phone account to one which supports video calling. |
| 919 | call.setTargetPhoneAccount(mPhoneAccountA1.getAccountHandle()); |
| 920 | assert(call.isVideoCallingSupported()); |
| 921 | assertEquals(VideoProfile.STATE_BIDIRECTIONAL, call.getVideoState()); |
| 922 | } |
| 923 | |
| 924 | /** |
| 925 | * Test scenario where the user starts an outgoing video call with no selected PhoneAccount, and |
| 926 | * then subsequently selects a PhoneAccount which does not support video calling. |
| 927 | * @throws Exception |
| 928 | */ |
Brad Ebinger | 68d17c6 | 2017-04-11 17:14:11 -0700 | [diff] [blame] | 929 | @FlakyTest |
Tyler Gunn | ddec589 | 2016-09-28 10:26:13 -0700 | [diff] [blame] | 930 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 931 | @Test |
Tyler Gunn | ddec589 | 2016-09-28 10:26:13 -0700 | [diff] [blame] | 932 | public void testOutgoingCallSelectPhoneAccountNoVideo() throws Exception { |
| 933 | startOutgoingPhoneCallPendingCreateConnection("650-555-1212", |
| 934 | null, mConnectionServiceFixtureA, |
| 935 | Process.myUserHandle(), VideoProfile.STATE_BIDIRECTIONAL); |
| 936 | com.android.server.telecom.Call call = mTelecomSystem.getCallsManager().getCalls() |
| 937 | .iterator().next(); |
| 938 | assert(call.isVideoCallingSupported()); |
| 939 | assertEquals(VideoProfile.STATE_BIDIRECTIONAL, call.getVideoState()); |
| 940 | |
| 941 | // Change the phone account to one which does not support video calling. |
| 942 | call.setTargetPhoneAccount(mPhoneAccountA2.getAccountHandle()); |
| 943 | assert(!call.isVideoCallingSupported()); |
| 944 | assertEquals(VideoProfile.STATE_AUDIO_ONLY, call.getVideoState()); |
| 945 | } |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 946 | |
| 947 | /** |
| 948 | * Basic test to ensure that a self-managed ConnectionService can place a call. |
| 949 | * @throws Exception |
| 950 | */ |
| 951 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 952 | @Test |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 953 | public void testSelfManagedOutgoing() throws Exception { |
| 954 | PhoneAccountHandle phoneAccountHandle = mPhoneAccountSelfManaged.getAccountHandle(); |
| 955 | IdPair ids = startAndMakeActiveOutgoingCall("650-555-1212", phoneAccountHandle, |
| 956 | mConnectionServiceFixtureA); |
| 957 | |
| 958 | // The InCallService should not know about the call since its self-managed. |
| 959 | assertNull(mInCallServiceFixtureX.getCall(ids.mCallId)); |
| 960 | } |
| 961 | |
| 962 | /** |
| 963 | * Basic test to ensure that a self-managed ConnectionService can add an incoming call. |
| 964 | * @throws Exception |
| 965 | */ |
| 966 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 967 | @Test |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 968 | public void testSelfManagedIncoming() throws Exception { |
| 969 | PhoneAccountHandle phoneAccountHandle = mPhoneAccountSelfManaged.getAccountHandle(); |
| 970 | IdPair ids = startAndMakeActiveIncomingCall("650-555-1212", phoneAccountHandle, |
| 971 | mConnectionServiceFixtureA); |
| 972 | |
| 973 | // The InCallService should not know about the call since its self-managed. |
| 974 | assertNull(mInCallServiceFixtureX.getCall(ids.mCallId)); |
| 975 | } |
| 976 | |
| 977 | /** |
| 978 | * Basic test to ensure that when there are no calls, we permit outgoing calls by a self managed |
| 979 | * CS. |
| 980 | * @throws Exception |
| 981 | */ |
| 982 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 983 | @Test |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 984 | public void testIsOutgoingCallPermitted() throws Exception { |
| 985 | assertTrue(mTelecomSystem.getTelecomServiceImpl().getBinder() |
| 986 | .isOutgoingCallPermitted(mPhoneAccountSelfManaged.getAccountHandle())); |
| 987 | } |
| 988 | |
| 989 | /** |
Tyler Gunn | b652dad | 2018-03-27 18:49:49 +0000 | [diff] [blame] | 990 | * Ensure if there is a holdable call ongoing we'll be able to place another call. |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 991 | * @throws Exception |
| 992 | */ |
| 993 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 994 | @Test |
Tyler Gunn | b652dad | 2018-03-27 18:49:49 +0000 | [diff] [blame] | 995 | public void testIsOutgoingCallPermittedOngoingHoldable() throws Exception { |
| 996 | // Start a regular call; the self-managed CS can make a call now since ongoing call can be |
| 997 | // held |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 998 | IdPair ids = startAndMakeActiveIncomingCall("650-555-1212", |
| 999 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 1000 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 1001 | |
Tyler Gunn | b652dad | 2018-03-27 18:49:49 +0000 | [diff] [blame] | 1002 | assertTrue(mTelecomSystem.getTelecomServiceImpl().getBinder() |
| 1003 | .isOutgoingCallPermitted(mPhoneAccountSelfManaged.getAccountHandle())); |
| 1004 | } |
| 1005 | |
| 1006 | /** |
| 1007 | * Ensure if there is an unholdable call we can't place another call. |
| 1008 | * @throws Exception |
| 1009 | */ |
| 1010 | @LargeTest |
| 1011 | @Test |
| 1012 | public void testIsOutgoingCallPermittedOngoingUnHoldable() throws Exception { |
| 1013 | // Start a regular call; the self-managed CS can't make a call now because the ongoing call |
| 1014 | // can't be held. |
| 1015 | mConnectionServiceFixtureA.mConnectionServiceDelegate.mCapabilities = 0; |
| 1016 | IdPair ids = startAndMakeActiveIncomingCall("650-555-1212", |
| 1017 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 1018 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 1019 | |
| 1020 | assertTrue(mTelecomSystem.getTelecomServiceImpl().getBinder() |
Tyler Gunn | 153aafa | 2017-10-06 10:08:18 -0700 | [diff] [blame] | 1021 | .isOutgoingCallPermitted(mPhoneAccountSelfManaged.getAccountHandle())); |
| 1022 | } |
Tyler Gunn | 911d4de | 2017-12-19 08:11:35 -0800 | [diff] [blame] | 1023 | |
| 1024 | /** |
| 1025 | * Basic to verify audio route gets reset to baseline when emergency call placed while a |
| 1026 | * self-managed call is underway. |
| 1027 | * @throws Exception |
| 1028 | */ |
| 1029 | @LargeTest |
Hall Liu | 74bb635 | 2017-12-27 18:23:28 -0800 | [diff] [blame] | 1030 | @Test |
Tyler Gunn | b652dad | 2018-03-27 18:49:49 +0000 | [diff] [blame] | 1031 | @FlakyTest |
Tyler Gunn | 911d4de | 2017-12-19 08:11:35 -0800 | [diff] [blame] | 1032 | public void testDisconnectSelfManaged() throws Exception { |
| 1033 | // Add a self-managed call. |
| 1034 | PhoneAccountHandle phoneAccountHandle = mPhoneAccountSelfManaged.getAccountHandle(); |
| 1035 | startAndMakeActiveIncomingCall("650-555-1212", phoneAccountHandle, |
| 1036 | mConnectionServiceFixtureA); |
| 1037 | Connection connection = mConnectionServiceFixtureA.mLatestConnection; |
| 1038 | |
| 1039 | // Route self-managed call to speaker. |
| 1040 | connection.setAudioRoute(CallAudioState.ROUTE_SPEAKER); |
| 1041 | waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT); |
| 1042 | |
| 1043 | // Place an emergency call. |
| 1044 | startAndMakeDialingEmergencyCall("650-555-1212", mPhoneAccountE0.getAccountHandle(), |
| 1045 | mConnectionServiceFixtureA); |
| 1046 | |
| 1047 | // Should have reverted back to earpiece. |
| 1048 | assertEquals(CallAudioState.ROUTE_EARPIECE, |
| 1049 | mInCallServiceFixtureX.mCallAudioState.getRoute()); |
| 1050 | } |
Pooja Jain | ad4ebc0 | 2017-12-28 14:23:13 +0530 | [diff] [blame] | 1051 | |
| 1052 | /** |
| 1053 | * Tests the {@link Call#deflect} API. Verifies that if a call is incoming, |
| 1054 | * and deflect API is called, then request is made to the connection service. |
| 1055 | * |
| 1056 | * @throws Exception |
| 1057 | */ |
| 1058 | @LargeTest |
| 1059 | @Test |
| 1060 | public void testDeflectCallWhenIncoming() throws Exception { |
| 1061 | Uri deflectAddress = Uri.parse("tel:650-555-1214"); |
| 1062 | IdPair ids = startIncomingPhoneCall("650-555-1212", mPhoneAccountA0.getAccountHandle(), |
| 1063 | mConnectionServiceFixtureA); |
| 1064 | |
| 1065 | assertEquals(Call.STATE_RINGING, mInCallServiceFixtureX.getCall(ids.mCallId).getState()); |
| 1066 | assertEquals(Call.STATE_RINGING, mInCallServiceFixtureY.getCall(ids.mCallId).getState()); |
| 1067 | // Attempt to deflect the call and verify the API call makes it through |
| 1068 | mInCallServiceFixtureX.mInCallAdapter.deflectCall(ids.mCallId, deflectAddress); |
| 1069 | verify(mConnectionServiceFixtureA.getTestDouble(), timeout(TEST_TIMEOUT)) |
| 1070 | .deflect(eq(ids.mConnectionId), eq(deflectAddress), any()); |
| 1071 | mInCallServiceFixtureX.mInCallAdapter.disconnectCall(ids.mCallId); |
| 1072 | } |
| 1073 | |
| 1074 | /** |
| 1075 | * Tests the {@link Call#deflect} API. Verifies that if a call is outgoing, |
| 1076 | * and deflect API is called, then request is not made to the connection service. |
| 1077 | * Ideally, deflect option should be displayed only if call is incoming/waiting. |
| 1078 | * |
| 1079 | * @throws Exception |
| 1080 | */ |
| 1081 | @LargeTest |
| 1082 | @Test |
| 1083 | public void testDeflectCallWhenOutgoing() throws Exception { |
| 1084 | Uri deflectAddress = Uri.parse("tel:650-555-1214"); |
| 1085 | IdPair ids = startOutgoingPhoneCall("650-555-1212", mPhoneAccountA0.getAccountHandle(), |
| 1086 | mConnectionServiceFixtureA, Process.myUserHandle()); |
| 1087 | // Attempt to deflect the call and verify the API call does not make it through |
| 1088 | mInCallServiceFixtureX.mInCallAdapter.deflectCall(ids.mCallId, deflectAddress); |
| 1089 | verify(mConnectionServiceFixtureA.getTestDouble(), never()) |
| 1090 | .deflect(eq(ids.mConnectionId), eq(deflectAddress), any()); |
| 1091 | mInCallServiceFixtureX.mInCallAdapter.disconnectCall(ids.mCallId); |
| 1092 | } |
Omata Shou | 6bc865c | 2017-07-26 13:39:27 +0900 | [diff] [blame] | 1093 | |
| 1094 | /** |
| 1095 | * Test to make sure to unmute automatically when making an emergency call and keep unmute |
| 1096 | * during the emergency call. |
| 1097 | * @throws Exception |
| 1098 | */ |
| 1099 | @LargeTest |
| 1100 | @Test |
| 1101 | public void testUnmuteDuringEmergencyCall() throws Exception { |
| 1102 | // Make an outgoing call and turn ON mute. |
| 1103 | IdPair outgoingCall = startAndMakeActiveOutgoingCall("650-555-1212", |
| 1104 | mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA); |
| 1105 | assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(outgoingCall.mCallId) |
| 1106 | .getState()); |
| 1107 | mInCallServiceFixtureX.mInCallAdapter.mute(true); |
| 1108 | waitForHandlerAction(mTelecomSystem.getCallsManager().getCallAudioManager() |
| 1109 | .getCallAudioRouteStateMachine().getHandler(), TEST_TIMEOUT); |
| 1110 | assertTrue(mTelecomSystem.getCallsManager().getAudioState().isMuted()); |
| 1111 | |
| 1112 | // Make an emergency call. |
| 1113 | IdPair emergencyCall = startAndMakeDialingEmergencyCall("650-555-1213", |
| 1114 | mPhoneAccountE0.getAccountHandle(), mConnectionServiceFixtureA); |
| 1115 | assertEquals(Call.STATE_DIALING, mInCallServiceFixtureX.getCall(emergencyCall.mCallId) |
| 1116 | .getState()); |
| 1117 | waitForHandlerAction(mTelecomSystem.getCallsManager().getCallAudioManager() |
| 1118 | .getCallAudioRouteStateMachine().getHandler(), TEST_TIMEOUT); |
| 1119 | // Should be unmute automatically. |
| 1120 | assertFalse(mTelecomSystem.getCallsManager().getAudioState().isMuted()); |
| 1121 | |
| 1122 | // Toggle mute during an emergency call. |
| 1123 | mTelecomSystem.getCallsManager().getCallAudioManager().toggleMute(); |
| 1124 | waitForHandlerAction(mTelecomSystem.getCallsManager().getCallAudioManager() |
| 1125 | .getCallAudioRouteStateMachine().getHandler(), TEST_TIMEOUT); |
| 1126 | // Should keep unmute. |
| 1127 | assertFalse(mTelecomSystem.getCallsManager().getAudioState().isMuted()); |
| 1128 | |
| 1129 | ArgumentCaptor<Boolean> muteValueCaptor = ArgumentCaptor.forClass(Boolean.class); |
| 1130 | verify(mAudioService, times(2)).setMicrophoneMute(muteValueCaptor.capture(), |
| 1131 | any(String.class), any(Integer.class)); |
| 1132 | List<Boolean> muteValues = muteValueCaptor.getAllValues(); |
| 1133 | // Check mute status was changed twice with true and false. |
| 1134 | assertTrue(muteValues.get(0)); |
| 1135 | assertFalse(muteValues.get(1)); |
| 1136 | } |
Tyler Gunn | b492f4c | 2015-12-15 08:15:43 -0800 | [diff] [blame] | 1137 | } |