Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2023 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 | |
Thomas Stuart | 0982362 | 2023-06-28 16:39:40 -0700 | [diff] [blame^] | 17 | package androidx.core.telecom.test |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 18 | |
| 19 | import android.os.Build.VERSION_CODES |
| 20 | import android.telecom.Call |
Pranav Madapurmath | 9a498a7 | 2023-06-21 21:59:16 +0000 | [diff] [blame] | 21 | import android.telecom.CallAttributes |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 22 | import android.telecom.DisconnectCause |
| 23 | import androidx.annotation.RequiresApi |
| 24 | import androidx.core.telecom.internal.utils.Utils |
Thomas Stuart | 0982362 | 2023-06-28 16:39:40 -0700 | [diff] [blame^] | 25 | import androidx.core.telecom.test.utils.BaseTelecomTest |
| 26 | import androidx.core.telecom.test.utils.TestUtils |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 27 | import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 28 | import androidx.test.filters.LargeTest |
| 29 | import androidx.test.filters.SdkSuppress |
Pranav Madapurmath | 9a498a7 | 2023-06-21 21:59:16 +0000 | [diff] [blame] | 30 | import kotlinx.coroutines.delay |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 31 | import kotlinx.coroutines.launch |
| 32 | import kotlinx.coroutines.runBlocking |
| 33 | import org.junit.After |
Pranav Madapurmath | d212839 | 2023-06-09 22:29:13 +0000 | [diff] [blame] | 34 | import org.junit.Assert.assertFalse |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 35 | import org.junit.Assert.assertNotNull |
| 36 | import org.junit.Assert.assertTrue |
| 37 | import org.junit.Before |
| 38 | import org.junit.Test |
| 39 | import org.junit.runner.RunWith |
| 40 | |
| 41 | /** |
| 42 | * This test class verifies the [CallControlCallback] functionality is working as intended when |
| 43 | * adding a VoIP call. Each test should add a call via [CallsManager.addCall] but should be |
| 44 | * manipulated via the [androidx.core.telecom.utils.MockInCallService]. The MockInCallService will |
| 45 | * create a [CallControlCallback] request before changing the call state. |
| 46 | */ |
Thomas Stuart | 7963dda | 2023-06-15 16:30:59 -0700 | [diff] [blame] | 47 | @SdkSuppress(minSdkVersion = VERSION_CODES.O) |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 48 | @RequiresApi(VERSION_CODES.O) |
Thomas Stuart | 7963dda | 2023-06-15 16:30:59 -0700 | [diff] [blame] | 49 | @RunWith(AndroidJUnit4::class) |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 50 | class BasicCallControlCallbacksTest : BaseTelecomTest() { |
| 51 | |
| 52 | @Before |
| 53 | fun setUp() { |
| 54 | Utils.resetUtils() |
| 55 | } |
| 56 | |
| 57 | @After |
| 58 | fun onDestroy() { |
| 59 | Utils.resetUtils() |
| 60 | } |
| 61 | |
| 62 | /*********************************************************************************************** |
| 63 | * V2 APIs (Android U and above) tests |
| 64 | *********************************************************************************************/ |
| 65 | |
| 66 | /** |
| 67 | * assert [CallsManager.addCall] can successfully add an *INCOMING* call and answer it via |
| 68 | * an InCallService that requires the [CallControlCallback.onAnswer] to accept the request. The |
| 69 | * call should use the *V2 platform APIs* under the hood. |
| 70 | */ |
| 71 | @SdkSuppress(minSdkVersion = VERSION_CODES.UPSIDE_DOWN_CAKE) |
| 72 | @LargeTest |
| 73 | @Test |
Grant Menke | 4549359 | 2023-06-15 14:48:43 +0000 | [diff] [blame] | 74 | fun testBasicCallControlCallbackAnswerCall() { |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 75 | setUpV2Test() |
| 76 | verifyAnswerCall() |
| 77 | } |
| 78 | |
Grant Menke | 4549359 | 2023-06-15 14:48:43 +0000 | [diff] [blame] | 79 | /** |
Pranav Madapurmath | 645a498 | 2023-06-14 23:54:54 +0000 | [diff] [blame] | 80 | * assert that when an *INCOMING* call is answered via [CallsManager.addCall] and the client |
| 81 | * rejects the request in [CallControlCallback.onAnswer], that we disconnect the call. The call |
| 82 | * should go into the active state before being disconnected. The call should use the *V2 |
| 83 | * platform APIs* under the hood. |
| 84 | */ |
| 85 | @SdkSuppress(minSdkVersion = VERSION_CODES.UPSIDE_DOWN_CAKE) |
| 86 | @LargeTest |
| 87 | @Test |
| 88 | fun testRejectCallControlCallbackAnswerCall() { |
| 89 | setUpV2Test() |
| 90 | verifyRejectAnswerCall(Call.STATE_ACTIVE) |
| 91 | } |
| 92 | |
| 93 | /** |
Pranav Madapurmath | 9a498a7 | 2023-06-21 21:59:16 +0000 | [diff] [blame] | 94 | * assert that when a client rejects a CallControlCallback.onSetInactive, that we disregard the |
| 95 | * request to hold the call. The call should use the *V2 platform APIs* under the hood. |
| 96 | */ |
| 97 | @SdkSuppress(minSdkVersion = VERSION_CODES.UPSIDE_DOWN_CAKE) |
| 98 | @LargeTest |
| 99 | @Test |
| 100 | fun testRejectCallControlCallbackHoldCall() { |
| 101 | setUpV2Test() |
| 102 | verifyRejectHoldCall() |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * assert that when a client rejects a CallControlCallback.onSetActive, that we disregard the |
| 107 | * request to unhold the call. The call should use the *V2 platform APIs* under the hood. |
| 108 | */ |
| 109 | @SdkSuppress(minSdkVersion = VERSION_CODES.UPSIDE_DOWN_CAKE) |
| 110 | @LargeTest |
| 111 | @Test |
| 112 | fun testRejectCallControlCallbackUnholdCall() { |
| 113 | setUpV2Test() |
| 114 | verifyRejectUnholdCall() |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * assert that when a client rejects a CallControlCallback.onDisconnect, that the call is still |
| 119 | * disconnected. The call should use the *V2 platform APIs* under the hood. |
| 120 | */ |
| 121 | @SdkSuppress(minSdkVersion = VERSION_CODES.UPSIDE_DOWN_CAKE) |
| 122 | @LargeTest |
| 123 | @Test |
| 124 | fun testRejectCallControlCallbackDisconnectCall() { |
| 125 | setUpV2Test() |
| 126 | verifyRejectDisconnectCall(true) |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * assert that when a client rejects a CallControlCallback.onDisconnect, that the call is still |
| 131 | * disconnected via Call.reject. The call should use the *V2 platform APIs* under the hood. |
| 132 | */ |
| 133 | @SdkSuppress(minSdkVersion = VERSION_CODES.UPSIDE_DOWN_CAKE) |
| 134 | @LargeTest |
| 135 | @Test |
| 136 | fun testRejectCallControlCallbackRejectCall() { |
| 137 | setUpV2Test() |
| 138 | verifyRejectDisconnectCall(false) |
| 139 | } |
| 140 | |
| 141 | /** |
Grant Menke | 4549359 | 2023-06-15 14:48:43 +0000 | [diff] [blame] | 142 | * assert [CallsManager.addCall] can successfully add an *INCOMING* call and disconnect it via |
| 143 | * an InCallService that requires the [CallControlCallback.onDisconnect] to accept the request. |
| 144 | * The call should use the *V2 platform APIs* under the hood. |
| 145 | */ |
| 146 | @SdkSuppress(minSdkVersion = VERSION_CODES.UPSIDE_DOWN_CAKE) |
| 147 | @LargeTest |
| 148 | @Test |
| 149 | fun testBasicCallControlCallbackDisconnectCall() { |
| 150 | setUpV2Test() |
| 151 | verifyDisconnectCall() |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * assert [CallsManager.addCall] can successfully add an *INCOMING* call and hold it via |
| 156 | * an InCallService that requires the [CallControlCallback.onSetInactive] to accept the request. |
| 157 | * The call should use the *V2 platform APIs* under the hood. |
| 158 | */ |
| 159 | @SdkSuppress(minSdkVersion = VERSION_CODES.UPSIDE_DOWN_CAKE) |
| 160 | @LargeTest |
| 161 | @Test |
| 162 | fun testBasicCallControlCallbackHoldCall() { |
| 163 | setUpV2Test() |
| 164 | verifyHoldCall() |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * assert [CallsManager.addCall] can successfully add an *INCOMING* call and un-hold it via |
| 169 | * an InCallService that requires the [CallControlCallback.onSetActive] to accept the request. |
| 170 | * The call should use the *V2 platform APIs* under the hood. |
| 171 | */ |
| 172 | @SdkSuppress(minSdkVersion = VERSION_CODES.UPSIDE_DOWN_CAKE) |
| 173 | @LargeTest |
| 174 | @Test |
| 175 | fun testBasicCallControlCallbackUnholdCall() { |
| 176 | setUpV2Test() |
| 177 | verifyUnholdCall() |
| 178 | } |
| 179 | |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 180 | /*********************************************************************************************** |
| 181 | * Backwards Compatibility Layer tests |
| 182 | *********************************************************************************************/ |
| 183 | |
| 184 | /** |
| 185 | * assert [CallsManager.addCall] can successfully add an *INCOMING* call and answer it via |
| 186 | * an InCallService that requires the [CallControlCallback.onAnswer] to accept the request. |
| 187 | * The call should use the *[android.telecom.ConnectionService] and [android.telecom.Connection] |
| 188 | * APIs* under the hood. |
| 189 | */ |
| 190 | @SdkSuppress(minSdkVersion = VERSION_CODES.O) |
| 191 | @LargeTest |
| 192 | @Test |
Grant Menke | 4549359 | 2023-06-15 14:48:43 +0000 | [diff] [blame] | 193 | fun testBasicCallControlCallbackAnswerCall_BackwardsCompat() { |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 194 | setUpBackwardsCompatTest() |
| 195 | verifyAnswerCall() |
| 196 | } |
| 197 | |
Grant Menke | 4549359 | 2023-06-15 14:48:43 +0000 | [diff] [blame] | 198 | /** |
Pranav Madapurmath | 645a498 | 2023-06-14 23:54:54 +0000 | [diff] [blame] | 199 | * assert that when an *INCOMING* call is answered via [CallsManager.addCall] and the client |
| 200 | * rejects the request in [CallControlCallback.onAnswer], that we disconnect the call. The call |
| 201 | * should never go active and simply be disconnected when it is in the ringing state. The call |
| 202 | * should use the *[android.telecom.ConnectionService] and [android.telecom.Connection] APIs* |
| 203 | * under the hood. |
| 204 | */ |
| 205 | @SdkSuppress(minSdkVersion = VERSION_CODES.O) |
| 206 | @LargeTest |
| 207 | @Test |
| 208 | fun testRejectCallControlCallbackAnswerCall_BackwardsCompat() { |
| 209 | setUpBackwardsCompatTest() |
| 210 | verifyRejectAnswerCall(Call.STATE_DISCONNECTED) |
| 211 | } |
| 212 | |
| 213 | /** |
Pranav Madapurmath | 9a498a7 | 2023-06-21 21:59:16 +0000 | [diff] [blame] | 214 | * assert that when a client rejects a CallControlCallback.onSetInactive, that we disregard the |
| 215 | * request to hold the call. The call should use the *[android.telecom.ConnectionService] and |
| 216 | * [android.telecom.Connection] APIs* under the hood. |
| 217 | */ |
| 218 | @SdkSuppress(minSdkVersion = VERSION_CODES.O) |
| 219 | @LargeTest |
| 220 | @Test |
| 221 | fun testRejectCallControlCallbackHoldCall_BackwardsCompat() { |
| 222 | setUpBackwardsCompatTest() |
| 223 | verifyRejectHoldCall() |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * assert that when a client rejects a CallControlCallback.onSetActive, that we disregard the |
| 228 | * request to unhold the call. The call should use the *[android.telecom.ConnectionService] and |
| 229 | * [android.telecom.Connection] APIs* under the hood. |
| 230 | */ |
| 231 | @SdkSuppress(minSdkVersion = VERSION_CODES.O) |
| 232 | @LargeTest |
| 233 | @Test |
| 234 | fun testRejectCallControlCallbackUnholdCall_BackwardsCompat() { |
| 235 | setUpBackwardsCompatTest() |
| 236 | verifyRejectUnholdCall() |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * assert that when a client rejects a CallControlCallback.onDisconnect, that we still |
| 241 | * disconnect the call. The call should use the *[android.telecom.ConnectionService] and |
| 242 | * [android.telecom.Connection] APIs* under the hood. |
| 243 | */ |
| 244 | @SdkSuppress(minSdkVersion = VERSION_CODES.O) |
| 245 | @LargeTest |
| 246 | @Test |
| 247 | fun testRejectCallControlCallbackDisconnectCall_BackwardsCompat() { |
| 248 | setUpBackwardsCompatTest() |
| 249 | verifyRejectDisconnectCall(true) |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * assert that when a client rejects a CallControlCallback.onDisconnect via call.reject, that we |
| 254 | * still disconnect the call via Call.reject. The call should use the |
| 255 | * *[android.telecom.ConnectionService] and [android.telecom.Connection] APIs* under the hood. |
| 256 | */ |
| 257 | @SdkSuppress(minSdkVersion = VERSION_CODES.O) |
| 258 | @LargeTest |
| 259 | @Test |
| 260 | fun testRejectCallControlCallbackRejectCall_BackwardsCompat() { |
| 261 | setUpBackwardsCompatTest() |
| 262 | verifyRejectDisconnectCall(false) |
| 263 | } |
| 264 | |
| 265 | /** |
Grant Menke | 4549359 | 2023-06-15 14:48:43 +0000 | [diff] [blame] | 266 | * assert [CallsManager.addCall] can successfully add an *INCOMING* call and disconnect it via |
| 267 | * an InCallService that requires the [CallControlCallback.onDisconnect] to accept the request. |
| 268 | * The call should use the *[android.telecom.ConnectionService] and [android.telecom.Connection] |
| 269 | * APIs* under the hood. |
| 270 | */ |
| 271 | @SdkSuppress(minSdkVersion = VERSION_CODES.O) |
| 272 | @LargeTest |
| 273 | @Test |
| 274 | fun testBasicCallControlCallbackDisconnectCall_BackwardsCompat() { |
| 275 | setUpBackwardsCompatTest() |
| 276 | verifyDisconnectCall() |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * assert [CallsManager.addCall] can successfully add an *INCOMING* call and hold it via |
| 281 | * an InCallService that requires the [CallControlCallback.onSetInactive] to accept the request. |
| 282 | * The call should use the *[android.telecom.ConnectionService] and [android.telecom.Connection] |
| 283 | * APIs* under the hood. |
| 284 | */ |
| 285 | @SdkSuppress(minSdkVersion = VERSION_CODES.O) |
| 286 | @LargeTest |
| 287 | @Test |
| 288 | fun testBasicCallControlCallbackHoldCall_BackwardsCompat() { |
| 289 | setUpBackwardsCompatTest() |
| 290 | verifyHoldCall() |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * assert [CallsManager.addCall] can successfully add an *INCOMING* call and un-hold it via |
| 295 | * an InCallService that requires the [CallControlCallback.onSetActive] to accept the request. |
| 296 | * The call should use the *[android.telecom.ConnectionService] and [android.telecom.Connection] |
| 297 | * APIs* under the hood. |
| 298 | */ |
| 299 | @SdkSuppress(minSdkVersion = VERSION_CODES.O) |
| 300 | @LargeTest |
| 301 | @Test |
| 302 | fun testBasicCallControlCallbackUnholdCall_BackwardsCompat() { |
| 303 | setUpBackwardsCompatTest() |
| 304 | verifyUnholdCall() |
| 305 | } |
| 306 | |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 307 | /*********************************************************************************************** |
| 308 | * Helpers |
| 309 | *********************************************************************************************/ |
| 310 | |
| 311 | @Suppress("deprecation") |
| 312 | private fun verifyAnswerCall() { |
Pranav Madapurmath | 0abafcc | 2023-06-13 20:18:57 +0000 | [diff] [blame] | 313 | assertFalse(TestUtils.mOnAnswerCallbackCalled) |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 314 | runBlocking { |
| 315 | mCallsManager.addCall(TestUtils.INCOMING_CALL_ATTRIBUTES) { |
Pranav Madapurmath | 645a498 | 2023-06-14 23:54:54 +0000 | [diff] [blame] | 316 | setCallback(TestUtils.mCallControlCallbacksImpl) |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 317 | launch { |
| 318 | val call = TestUtils.waitOnInCallServiceToReachXCalls(1) |
| 319 | assertNotNull("The returned Call object is <NULL>", call) |
| 320 | call!!.answer(0) // API under test |
| 321 | TestUtils.waitOnCallState(call, Call.STATE_ACTIVE) |
Grant Menke | 4549359 | 2023-06-15 14:48:43 +0000 | [diff] [blame] | 322 | // Always send the disconnect signal if possible: |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 323 | assertTrue(disconnect(DisconnectCause(DisconnectCause.LOCAL))) |
| 324 | } |
| 325 | } |
| 326 | } |
Grant Menke | 4549359 | 2023-06-15 14:48:43 +0000 | [diff] [blame] | 327 | // Assert that the correct callback was invoked |
Pranav Madapurmath | 0abafcc | 2023-06-13 20:18:57 +0000 | [diff] [blame] | 328 | assertTrue(TestUtils.mOnAnswerCallbackCalled) |
Thomas Stuart | d626512 | 2023-05-04 11:08:37 -0700 | [diff] [blame] | 329 | } |
Grant Menke | 4549359 | 2023-06-15 14:48:43 +0000 | [diff] [blame] | 330 | |
| 331 | @Suppress("deprecation") |
| 332 | private fun verifyDisconnectCall() { |
| 333 | assertFalse(TestUtils.mOnDisconnectCallbackCalled) |
| 334 | runBlocking { |
| 335 | mCallsManager.addCall(TestUtils.INCOMING_CALL_ATTRIBUTES) { |
Pranav Madapurmath | 645a498 | 2023-06-14 23:54:54 +0000 | [diff] [blame] | 336 | setCallback(TestUtils.mCallControlCallbacksImpl) |
Grant Menke | 4549359 | 2023-06-15 14:48:43 +0000 | [diff] [blame] | 337 | launch { |
| 338 | val call = TestUtils.waitOnInCallServiceToReachXCalls(1) |
| 339 | assertNotNull("The returned Call object is <NULL>", call) |
| 340 | // Disconnect the call and ensure the disconnect callback is received: |
| 341 | call!!.disconnect() |
| 342 | TestUtils.waitOnCallState(call, Call.STATE_DISCONNECTED) |
Pranav Madapurmath | 9a498a7 | 2023-06-21 21:59:16 +0000 | [diff] [blame] | 343 | // always send the disconnect signal if possible |
| 344 | disconnect(DisconnectCause(DisconnectCause.LOCAL)) |
Grant Menke | 4549359 | 2023-06-15 14:48:43 +0000 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | } |
| 348 | // Assert that the correct callback was invoked |
| 349 | assertTrue(TestUtils.mOnDisconnectCallbackCalled) |
| 350 | } |
| 351 | |
| 352 | @Suppress("deprecation") |
| 353 | private fun verifyHoldCall() { |
| 354 | assertFalse(TestUtils.mOnSetInactiveCallbackCalled) |
| 355 | runBlocking { |
| 356 | mCallsManager.addCall(TestUtils.INCOMING_CALL_ATTRIBUTES) { |
Pranav Madapurmath | 645a498 | 2023-06-14 23:54:54 +0000 | [diff] [blame] | 357 | setCallback(TestUtils.mCallControlCallbacksImpl) |
Grant Menke | 4549359 | 2023-06-15 14:48:43 +0000 | [diff] [blame] | 358 | launch { |
| 359 | val call = TestUtils.waitOnInCallServiceToReachXCalls(1) |
| 360 | assertNotNull("The returned Call object is <NULL>", call) |
| 361 | assertTrue(setActive()) |
| 362 | // Wait for the call to be set to ACTIVE: |
| 363 | TestUtils.waitOnCallState(call!!, Call.STATE_ACTIVE) |
| 364 | // Place the call on hold and ensure the onSetInactive callback is received: |
| 365 | call.hold() |
| 366 | TestUtils.waitOnCallState(call, Call.STATE_HOLDING) |
| 367 | // Always send the disconnect signal if possible: |
| 368 | assertTrue(disconnect(DisconnectCause(DisconnectCause.LOCAL))) |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | // Assert that the correct callback was invoked |
| 373 | assertTrue(TestUtils.mOnSetInactiveCallbackCalled) |
| 374 | } |
| 375 | |
| 376 | @Suppress("deprecation") |
| 377 | private fun verifyUnholdCall() { |
| 378 | assertFalse(TestUtils.mOnSetActiveCallbackCalled) |
| 379 | runBlocking { |
| 380 | mCallsManager.addCall(TestUtils.INCOMING_CALL_ATTRIBUTES) { |
Pranav Madapurmath | 645a498 | 2023-06-14 23:54:54 +0000 | [diff] [blame] | 381 | setCallback(TestUtils.mCallControlCallbacksImpl) |
Grant Menke | 4549359 | 2023-06-15 14:48:43 +0000 | [diff] [blame] | 382 | launch { |
| 383 | val call = TestUtils.waitOnInCallServiceToReachXCalls(1) |
| 384 | assertNotNull("The returned Call object is <NULL>", call) |
| 385 | assertTrue(setActive()) |
| 386 | // Wait for the call to be set to ACTIVE: |
| 387 | TestUtils.waitOnCallState(call!!, Call.STATE_ACTIVE) |
| 388 | assertTrue(setInactive()) |
| 389 | // Wait for the call to be set to HOLDING (aka inactive): |
| 390 | TestUtils.waitOnCallState(call, Call.STATE_HOLDING) |
| 391 | // Request to un-hold the call and ensure the onSetActive callback is received: |
| 392 | call.unhold() |
| 393 | TestUtils.waitOnCallState(call, Call.STATE_ACTIVE) |
| 394 | // Always send the disconnect signal if possible: |
| 395 | assertTrue(disconnect(DisconnectCause(DisconnectCause.LOCAL))) |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | // Assert that the correct callback was invoked |
| 400 | assertTrue(TestUtils.mOnSetActiveCallbackCalled) |
| 401 | } |
Pranav Madapurmath | 645a498 | 2023-06-14 23:54:54 +0000 | [diff] [blame] | 402 | |
| 403 | @Suppress("deprecation") |
| 404 | private fun verifyRejectAnswerCall(callState: Int) { |
| 405 | assertFalse(TestUtils.mOnAnswerCallbackCalled) |
| 406 | runBlocking { |
| 407 | mCallsManager.addCall(TestUtils.INCOMING_CALL_ATTRIBUTES) { |
| 408 | setCallback(TestUtils.mCallControlCallbacksImpl) |
| 409 | // Note that this is reset in BaseTelecomTest in setUp/destroy |
| 410 | TestUtils.mCompleteOnAnswer = false |
| 411 | launch { |
| 412 | val call = TestUtils.waitOnInCallServiceToReachXCalls(1) |
| 413 | assertNotNull("The returned Call object is <NULL>", call) |
| 414 | call!!.answer(0) // API under test |
| 415 | // Ensure that call has moved to the expected state |
| 416 | TestUtils.waitOnCallState(call, callState) |
| 417 | // Ensure that call is automatically disconnected. |
| 418 | TestUtils.waitOnCallState(call, Call.STATE_DISCONNECTED) |
Pranav Madapurmath | 9a498a7 | 2023-06-21 21:59:16 +0000 | [diff] [blame] | 419 | // always send the disconnect signal if possible |
| 420 | disconnect(DisconnectCause(DisconnectCause.LOCAL)) |
Pranav Madapurmath | 645a498 | 2023-06-14 23:54:54 +0000 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | } |
| 424 | // Assert that the correct callback was invoked |
| 425 | assertTrue(TestUtils.mOnAnswerCallbackCalled) |
| 426 | } |
Pranav Madapurmath | 9a498a7 | 2023-06-21 21:59:16 +0000 | [diff] [blame] | 427 | |
| 428 | @Suppress("deprecation") |
| 429 | private fun verifyRejectHoldCall() { |
| 430 | assertFalse(TestUtils.mOnSetInactiveCallbackCalled) |
| 431 | runBlocking { |
| 432 | mCallsManager.addCall(TestUtils.INCOMING_CALL_ATTRIBUTES) { |
| 433 | setCallback(TestUtils.mCallControlCallbacksImpl) |
| 434 | TestUtils.mCompleteOnSetInactive = false |
| 435 | launch { |
| 436 | val call = TestUtils.waitOnInCallServiceToReachXCalls(1) |
| 437 | assertNotNull("The returned Call object is <NULL>", call) |
| 438 | answer(CallAttributes.AUDIO_CALL) |
| 439 | TestUtils.waitOnCallState(call!!, Call.STATE_ACTIVE) |
| 440 | call.hold() |
| 441 | delay(TestUtils.WAIT_ON_CALL_STATE_TIMEOUT) |
| 442 | // Request to hold call should be disregarded |
| 443 | assertTrue(call.state == Call.STATE_ACTIVE) |
| 444 | // always send the disconnect signal if possible |
| 445 | assertTrue(disconnect(DisconnectCause(DisconnectCause.LOCAL))) |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | // Assert that the correct callback was invoked |
| 450 | assertTrue(TestUtils.mOnSetInactiveCallbackCalled) |
| 451 | } |
| 452 | |
| 453 | @Suppress("deprecation") |
| 454 | private fun verifyRejectUnholdCall() { |
| 455 | assertFalse(TestUtils.mOnSetActiveCallbackCalled) |
| 456 | runBlocking { |
| 457 | mCallsManager.addCall(TestUtils.INCOMING_CALL_ATTRIBUTES) { |
| 458 | setCallback(TestUtils.mCallControlCallbacksImpl) |
| 459 | launch { |
| 460 | val call = TestUtils.waitOnInCallServiceToReachXCalls(1) |
| 461 | assertNotNull("The returned Call object is <NULL>", call) |
| 462 | answer(CallAttributes.AUDIO_CALL) // API under test |
| 463 | TestUtils.waitOnCallState(call!!, Call.STATE_ACTIVE) |
| 464 | // Fail #onSetActive after call has successfully moved to the active state |
| 465 | TestUtils.mCompleteOnSetActive = false |
| 466 | setInactive() |
| 467 | TestUtils.waitOnCallState(call, Call.STATE_HOLDING) |
| 468 | call.unhold() |
| 469 | delay(TestUtils.WAIT_ON_CALL_STATE_TIMEOUT) |
| 470 | // Request to unhold call should be disregarded |
| 471 | assertTrue(call.state == Call.STATE_HOLDING) |
| 472 | // always send the disconnect signal if possible |
| 473 | assertTrue(disconnect(DisconnectCause(DisconnectCause.LOCAL))) |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | // Assert that the correct callback was invoked |
| 478 | assertTrue(TestUtils.mOnSetActiveCallbackCalled) |
| 479 | } |
| 480 | |
| 481 | @Suppress("deprecation") |
| 482 | private fun verifyRejectDisconnectCall(invokeDisconnect: Boolean) { |
| 483 | assertFalse(TestUtils.mOnDisconnectCallbackCalled) |
| 484 | runBlocking { |
| 485 | mCallsManager.addCall(TestUtils.INCOMING_CALL_ATTRIBUTES) { |
| 486 | setCallback(TestUtils.mCallControlCallbacksImpl) |
| 487 | TestUtils.mCompleteOnDisconnect = false |
| 488 | launch { |
| 489 | val call = TestUtils.waitOnInCallServiceToReachXCalls(1) |
| 490 | assertNotNull("The returned Call object is <NULL>", call) |
| 491 | if (invokeDisconnect) { |
| 492 | answer(CallAttributes.AUDIO_CALL) // API under test |
| 493 | TestUtils.waitOnCallState(call!!, Call.STATE_ACTIVE) |
| 494 | call.disconnect() |
| 495 | } else { |
| 496 | call!!.reject(true, "REJECT_REASON_DECLINED") |
| 497 | } |
| 498 | delay(TestUtils.WAIT_ON_CALL_STATE_TIMEOUT) |
| 499 | // Rejecting the onDisconnect callback should still result in a disconnect. |
| 500 | TestUtils.waitOnCallState(call, Call.STATE_DISCONNECTED) |
| 501 | // always send the disconnect signal if possible |
| 502 | disconnect(DisconnectCause(DisconnectCause.LOCAL)) |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | // Assert that the correct callback was invoked |
| 507 | assertTrue(TestUtils.mOnDisconnectCallbackCalled) |
| 508 | } |
Aurimas Liutikas | 4d53400 | 2023-07-06 15:51:33 -0700 | [diff] [blame] | 509 | } |