Hall Liu | 2afe902 | 2018-01-03 15:38:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.telecom.tests; |
| 18 | |
| 19 | import android.media.AudioManager; |
| 20 | import android.test.suitebuilder.annotation.SmallTest; |
| 21 | |
| 22 | import com.android.server.telecom.CallAudioManager; |
| 23 | import com.android.server.telecom.CallAudioModeStateMachine; |
| 24 | |
| 25 | import org.junit.Before; |
| 26 | import org.junit.Test; |
| 27 | import org.junit.runner.RunWith; |
| 28 | import org.junit.runners.Parameterized; |
| 29 | import org.mockito.Mock; |
| 30 | |
| 31 | import java.util.ArrayList; |
| 32 | import java.util.Collection; |
| 33 | import java.util.List; |
| 34 | |
| 35 | import static org.junit.Assert.assertEquals; |
| 36 | import static org.mockito.ArgumentMatchers.anyInt; |
| 37 | import static org.mockito.ArgumentMatchers.eq; |
| 38 | import static org.mockito.Mockito.never; |
| 39 | import static org.mockito.Mockito.reset; |
| 40 | import static org.mockito.Mockito.verify; |
| 41 | import static org.mockito.Mockito.when; |
| 42 | |
| 43 | @RunWith(Parameterized.class) |
| 44 | public class CallAudioModeTransitionTests extends TelecomTestCase { |
| 45 | private static class ModeTestParameters { |
| 46 | public String name; |
| 47 | public int initialAudioState; // One of the explicit switch focus constants in CAMSM |
| 48 | public int messageType; // Any of the commands from the state machine |
| 49 | public CallAudioModeStateMachine.MessageArgs externalState; |
| 50 | public String expectedFinalStateName; |
| 51 | public int expectedFocus; // one of the FOCUS_* constants below |
| 52 | public int expectedMode; // NO_CHANGE, or an AudioManager.MODE_* constant |
| 53 | public int expectedRingingInteraction; // NO_CHANGE, ON, or OFF |
| 54 | public int expectedCallWaitingInteraction; // NO_CHANGE, ON, or OFF |
| 55 | |
| 56 | public ModeTestParameters(String name, int initialAudioState, int messageType, |
| 57 | CallAudioModeStateMachine.MessageArgs externalState, String |
| 58 | expectedFinalStateName, int expectedFocus, int expectedMode, int |
| 59 | expectedRingingInteraction, int expectedCallWaitingInteraction) { |
| 60 | this.name = name; |
| 61 | this.initialAudioState = initialAudioState; |
| 62 | this.messageType = messageType; |
| 63 | this.externalState = externalState; |
| 64 | this.expectedFinalStateName = expectedFinalStateName; |
| 65 | this.expectedFocus = expectedFocus; |
| 66 | this.expectedMode = expectedMode; |
| 67 | this.expectedRingingInteraction = expectedRingingInteraction; |
| 68 | this.expectedCallWaitingInteraction = expectedCallWaitingInteraction; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public String toString() { |
| 73 | return "ModeTestParameters{" + |
| 74 | "name='" + name + '\'' + |
| 75 | ", initialAudioState=" + initialAudioState + |
| 76 | ", messageType=" + messageType + |
| 77 | ", externalState=" + externalState + |
| 78 | ", expectedFinalStateName='" + expectedFinalStateName + '\'' + |
| 79 | ", expectedFocus=" + expectedFocus + |
| 80 | ", expectedMode=" + expectedMode + |
| 81 | ", expectedRingingInteraction=" + expectedRingingInteraction + |
| 82 | ", expectedCallWaitingInteraction=" + expectedCallWaitingInteraction + |
| 83 | '}'; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | private static final int FOCUS_NO_CHANGE = 0; |
| 88 | private static final int FOCUS_RING = 1; |
| 89 | private static final int FOCUS_VOICE = 2; |
| 90 | private static final int FOCUS_OFF = 3; |
| 91 | |
| 92 | private static final int NO_CHANGE = -1; |
| 93 | private static final int ON = 0; |
| 94 | private static final int OFF = 1; |
| 95 | |
| 96 | private static final int TEST_TIMEOUT = 1000; |
| 97 | |
| 98 | @Mock private AudioManager mAudioManager; |
| 99 | @Mock private CallAudioManager mCallAudioManager; |
| 100 | private final ModeTestParameters mParams; |
| 101 | |
| 102 | @Override |
| 103 | @Before |
| 104 | public void setUp() throws Exception { |
| 105 | super.setUp(); |
| 106 | } |
| 107 | |
| 108 | public CallAudioModeTransitionTests(ModeTestParameters params) { |
| 109 | mParams = params; |
| 110 | } |
| 111 | |
| 112 | @Test |
| 113 | @SmallTest |
| 114 | public void modeTransitionTest() { |
| 115 | CallAudioModeStateMachine sm = new CallAudioModeStateMachine(mAudioManager); |
| 116 | sm.setCallAudioManager(mCallAudioManager); |
| 117 | sm.sendMessage(mParams.initialAudioState); |
| 118 | waitForHandlerAction(sm.getHandler(), TEST_TIMEOUT); |
| 119 | |
| 120 | resetMocks(); |
| 121 | when(mCallAudioManager.startRinging()).thenReturn(true); |
| 122 | |
| 123 | sm.sendMessage(mParams.messageType, mParams.externalState); |
| 124 | waitForHandlerAction(sm.getHandler(), TEST_TIMEOUT); |
| 125 | |
| 126 | assertEquals(mParams.expectedFinalStateName, sm.getCurrentStateName()); |
| 127 | |
| 128 | switch (mParams.expectedFocus) { |
| 129 | case FOCUS_NO_CHANGE: |
| 130 | verify(mAudioManager, never()).requestAudioFocusForCall(anyInt(), anyInt()); |
| 131 | break; |
| 132 | case FOCUS_OFF: |
| 133 | verify(mAudioManager).abandonAudioFocusForCall(); |
| 134 | break; |
| 135 | case FOCUS_RING: |
| 136 | verify(mAudioManager).requestAudioFocusForCall( |
| 137 | eq(AudioManager.STREAM_RING), anyInt()); |
| 138 | break; |
| 139 | case FOCUS_VOICE: |
| 140 | verify(mAudioManager).requestAudioFocusForCall( |
| 141 | eq(AudioManager.STREAM_VOICE_CALL), anyInt()); |
| 142 | break; |
| 143 | } |
| 144 | |
| 145 | if (mParams.expectedMode != NO_CHANGE) { |
| 146 | verify(mAudioManager).setMode(eq(mParams.expectedMode)); |
| 147 | } else { |
| 148 | verify(mAudioManager, never()).setMode(anyInt()); |
| 149 | } |
| 150 | |
| 151 | switch (mParams.expectedRingingInteraction) { |
| 152 | case NO_CHANGE: |
| 153 | verify(mCallAudioManager, never()).startRinging(); |
| 154 | verify(mCallAudioManager, never()).stopRinging(); |
| 155 | break; |
| 156 | case ON: |
| 157 | verify(mCallAudioManager).startRinging(); |
| 158 | break; |
| 159 | case OFF: |
| 160 | verify(mCallAudioManager).stopRinging(); |
| 161 | break; |
| 162 | } |
| 163 | |
| 164 | switch (mParams.expectedCallWaitingInteraction) { |
| 165 | case NO_CHANGE: |
| 166 | verify(mCallAudioManager, never()).startCallWaiting(); |
| 167 | verify(mCallAudioManager, never()).stopCallWaiting(); |
| 168 | break; |
| 169 | case ON: |
| 170 | verify(mCallAudioManager).startCallWaiting(); |
| 171 | break; |
| 172 | case OFF: |
| 173 | verify(mCallAudioManager).stopCallWaiting(); |
| 174 | break; |
| 175 | } |
| 176 | |
| 177 | sm.quitNow(); |
| 178 | } |
| 179 | |
| 180 | @Parameterized.Parameters(name = "{0}") |
| 181 | public static Collection<ModeTestParameters> generateTestCases() { |
| 182 | List<ModeTestParameters> result = new ArrayList<>(); |
| 183 | result.add(new ModeTestParameters( |
| 184 | "New active/dialing call with no other calls when unfocused", |
| 185 | CallAudioModeStateMachine.ABANDON_FOCUS_FOR_TESTING, // initialAudioState |
| 186 | CallAudioModeStateMachine.NEW_ACTIVE_OR_DIALING_CALL, // messageType |
| 187 | new CallAudioModeStateMachine.MessageArgs( |
| 188 | true, // hasActiveOrDialingCalls |
| 189 | false, // hasRingingCalls |
| 190 | false, // hasHoldingCalls |
| 191 | false, // isTonePlaying |
| 192 | false, // foregroundCallIsVoip |
| 193 | null // session |
| 194 | ), |
| 195 | CallAudioModeStateMachine.CALL_STATE_NAME, // expectedFinalStateName |
| 196 | FOCUS_VOICE, // expectedFocus |
| 197 | AudioManager.MODE_IN_CALL, // expectedMode |
| 198 | NO_CHANGE, // expectedRingingInteraction |
| 199 | NO_CHANGE // expectedCallWaitingInteraction |
| 200 | )); |
| 201 | |
| 202 | result.add(new ModeTestParameters( |
| 203 | "New active/dialing voip call with no other calls when unfocused", |
| 204 | CallAudioModeStateMachine.ABANDON_FOCUS_FOR_TESTING, // initialAudioState |
| 205 | CallAudioModeStateMachine.NEW_ACTIVE_OR_DIALING_CALL, // messageType |
| 206 | new CallAudioModeStateMachine.MessageArgs( |
| 207 | true, // hasActiveOrDialingCalls |
| 208 | false, // hasRingingCalls |
| 209 | false, // hasHoldingCalls |
| 210 | false, // isTonePlaying |
| 211 | true, // foregroundCallIsVoip |
| 212 | null // session |
| 213 | ), |
| 214 | CallAudioModeStateMachine.COMMS_STATE_NAME, // expectedFinalStateName |
| 215 | FOCUS_VOICE, // expectedFocus |
| 216 | AudioManager.MODE_IN_COMMUNICATION, // expectedMode |
| 217 | NO_CHANGE, // expectedRingingInteraction |
| 218 | NO_CHANGE // expectedCallWaitingInteraction |
| 219 | )); |
| 220 | |
| 221 | result.add(new ModeTestParameters( |
| 222 | "New ringing call with no other calls when unfocused", |
| 223 | CallAudioModeStateMachine.ABANDON_FOCUS_FOR_TESTING, // initialAudioState |
| 224 | CallAudioModeStateMachine.NEW_RINGING_CALL, // messageType |
| 225 | new CallAudioModeStateMachine.MessageArgs( |
| 226 | false, // hasActiveOrDialingCalls |
| 227 | true, // hasRingingCalls |
| 228 | false, // hasHoldingCalls |
| 229 | false, // isTonePlaying |
| 230 | false, // foregroundCallIsVoip |
| 231 | null // session |
| 232 | ), |
| 233 | CallAudioModeStateMachine.RING_STATE_NAME, // expectedFinalStateName |
| 234 | FOCUS_RING, // expectedFocus |
| 235 | AudioManager.MODE_RINGTONE, // expectedMode |
| 236 | ON, // expectedRingingInteraction |
| 237 | OFF // expectedCallWaitingInteraction |
| 238 | )); |
| 239 | |
| 240 | result.add(new ModeTestParameters( |
| 241 | "New ringing call coming in on top of active/dialing call", |
| 242 | CallAudioModeStateMachine.ENTER_CALL_FOCUS_FOR_TESTING, // initialAudioState |
| 243 | CallAudioModeStateMachine.NEW_RINGING_CALL, // messageType |
| 244 | new CallAudioModeStateMachine.MessageArgs( |
| 245 | true, // hasActiveOrDialingCalls |
| 246 | true, // hasRingingCalls |
| 247 | false, // hasHoldingCalls |
| 248 | false, // isTonePlaying |
| 249 | false, // foregroundCallIsVoip |
| 250 | null // session |
| 251 | ), |
| 252 | CallAudioModeStateMachine.CALL_STATE_NAME, // expectedFinalStateName |
| 253 | NO_CHANGE, // expectedFocus |
| 254 | NO_CHANGE, // expectedMode |
| 255 | NO_CHANGE, // expectedRingingInteraction |
| 256 | ON // expectedCallWaitingInteraction |
| 257 | )); |
| 258 | |
| 259 | result.add(new ModeTestParameters( |
| 260 | "Ringing call becomes active, part 1", |
| 261 | CallAudioModeStateMachine.ENTER_RING_FOCUS_FOR_TESTING, // initialAudioState |
| 262 | CallAudioModeStateMachine.NEW_ACTIVE_OR_DIALING_CALL, // messageType |
| 263 | new CallAudioModeStateMachine.MessageArgs( |
| 264 | true, // hasActiveOrDialingCalls |
| 265 | false, // hasRingingCalls |
| 266 | false, // hasHoldingCalls |
| 267 | false, // isTonePlaying |
| 268 | false, // foregroundCallIsVoip |
| 269 | null // session |
| 270 | ), |
| 271 | CallAudioModeStateMachine.CALL_STATE_NAME, // expectedFinalStateName |
| 272 | FOCUS_VOICE, // expectedFocus |
| 273 | AudioManager.MODE_IN_CALL, // expectedMode |
| 274 | OFF, // expectedRingingInteraction |
| 275 | NO_CHANGE // expectedCallWaitingInteraction |
| 276 | )); |
| 277 | |
| 278 | result.add(new ModeTestParameters( |
| 279 | "Ringing call becomes active, part 2", |
| 280 | CallAudioModeStateMachine.ENTER_CALL_FOCUS_FOR_TESTING, // initialAudioState |
| 281 | CallAudioModeStateMachine.NO_MORE_RINGING_CALLS, // messageType |
| 282 | new CallAudioModeStateMachine.MessageArgs( |
| 283 | true, // hasActiveOrDialingCalls |
| 284 | false, // hasRingingCalls |
| 285 | false, // hasHoldingCalls |
| 286 | false, // isTonePlaying |
| 287 | false, // foregroundCallIsVoip |
| 288 | null // session |
| 289 | ), |
| 290 | CallAudioModeStateMachine.CALL_STATE_NAME, // expectedFinalStateName |
| 291 | NO_CHANGE, // expectedFocus |
| 292 | NO_CHANGE, // expectedMode |
| 293 | NO_CHANGE, // expectedRingingInteraction |
| 294 | NO_CHANGE // expectedCallWaitingInteraction |
| 295 | )); |
| 296 | |
| 297 | result.add(new ModeTestParameters( |
| 298 | "Active call disconnects, but tone is playing", |
| 299 | CallAudioModeStateMachine.ENTER_CALL_FOCUS_FOR_TESTING, // initialAudioState |
| 300 | CallAudioModeStateMachine.NO_MORE_ACTIVE_OR_DIALING_CALLS, // messageType |
| 301 | new CallAudioModeStateMachine.MessageArgs( |
| 302 | false, // hasActiveOrDialingCalls |
| 303 | false, // hasRingingCalls |
| 304 | false, // hasHoldingCalls |
| 305 | true, // isTonePlaying |
| 306 | false, // foregroundCallIsVoip |
| 307 | null // session |
| 308 | ), |
| 309 | CallAudioModeStateMachine.TONE_HOLD_STATE_NAME, // expectedFinalStateName |
| 310 | FOCUS_VOICE, // expectedFocus |
| 311 | AudioManager.MODE_IN_CALL, // expectedMode |
| 312 | NO_CHANGE, // expectedRingingInteraction |
| 313 | NO_CHANGE // expectedCallWaitingInteraction |
| 314 | )); |
| 315 | |
| 316 | result.add(new ModeTestParameters( |
| 317 | "Tone stops playing, with no active calls", |
| 318 | CallAudioModeStateMachine.ENTER_TONE_OR_HOLD_FOCUS_FOR_TESTING, // initialAudioState |
| 319 | CallAudioModeStateMachine.TONE_STOPPED_PLAYING, // messageType |
| 320 | new CallAudioModeStateMachine.MessageArgs( |
| 321 | false, // hasActiveOrDialingCalls |
| 322 | false, // hasRingingCalls |
| 323 | false, // hasHoldingCalls |
| 324 | false, // isTonePlaying |
| 325 | false, // foregroundCallIsVoip |
| 326 | null // session |
| 327 | ), |
| 328 | CallAudioModeStateMachine.UNFOCUSED_STATE_NAME, // expectedFinalStateName |
| 329 | FOCUS_OFF, // expectedFocus |
| 330 | AudioManager.MODE_NORMAL, // expectedMode |
| 331 | NO_CHANGE, // expectedRingingInteraction |
| 332 | NO_CHANGE // expectedCallWaitingInteraction |
| 333 | )); |
| 334 | |
| 335 | result.add(new ModeTestParameters( |
| 336 | "Ringing call disconnects", |
| 337 | CallAudioModeStateMachine.ENTER_RING_FOCUS_FOR_TESTING, // initialAudioState |
| 338 | CallAudioModeStateMachine.NO_MORE_RINGING_CALLS, // messageType |
| 339 | new CallAudioModeStateMachine.MessageArgs( |
| 340 | false, // hasActiveOrDialingCalls |
| 341 | false, // hasRingingCalls |
| 342 | false, // hasHoldingCalls |
| 343 | false, // isTonePlaying |
| 344 | false, // foregroundCallIsVoip |
| 345 | null // session |
| 346 | ), |
| 347 | CallAudioModeStateMachine.UNFOCUSED_STATE_NAME, // expectedFinalStateName |
| 348 | FOCUS_OFF, // expectedFocus |
| 349 | AudioManager.MODE_NORMAL, // expectedMode |
| 350 | OFF, // expectedRingingInteraction |
| 351 | NO_CHANGE // expectedCallWaitingInteraction |
| 352 | )); |
| 353 | |
| 354 | result.add(new ModeTestParameters( |
| 355 | "Call-waiting call disconnects", |
| 356 | CallAudioModeStateMachine.ENTER_CALL_FOCUS_FOR_TESTING, // initialAudioState |
| 357 | CallAudioModeStateMachine.NO_MORE_RINGING_CALLS, // messageType |
| 358 | new CallAudioModeStateMachine.MessageArgs( |
| 359 | true, // hasActiveOrDialingCalls |
| 360 | false, // hasRingingCalls |
| 361 | false, // hasHoldingCalls |
| 362 | true, // isTonePlaying |
| 363 | false, // foregroundCallIsVoip |
| 364 | null // session |
| 365 | ), |
| 366 | CallAudioModeStateMachine.CALL_STATE_NAME, // expectedFinalStateName |
| 367 | FOCUS_NO_CHANGE, // expectedFocus |
| 368 | NO_CHANGE, // expectedMode |
| 369 | NO_CHANGE, // expectedRingingInteraction |
| 370 | OFF // expectedCallWaitingInteraction |
| 371 | )); |
| 372 | |
| 373 | result.add(new ModeTestParameters( |
| 374 | "Call is placed on hold - 1", |
| 375 | CallAudioModeStateMachine.ENTER_CALL_FOCUS_FOR_TESTING, // initialAudioState |
| 376 | CallAudioModeStateMachine.NO_MORE_ACTIVE_OR_DIALING_CALLS, // messageType |
| 377 | new CallAudioModeStateMachine.MessageArgs( |
| 378 | false, // hasActiveOrDialingCalls |
| 379 | false, // hasRingingCalls |
| 380 | true, // hasHoldingCalls |
| 381 | false, // isTonePlaying |
| 382 | false, // foregroundCallIsVoip |
| 383 | null // session |
| 384 | ), |
| 385 | CallAudioModeStateMachine.TONE_HOLD_STATE_NAME, // expectedFinalStateName |
| 386 | FOCUS_VOICE, // expectedFocus |
| 387 | AudioManager.MODE_IN_CALL, // expectedMode |
| 388 | NO_CHANGE, // expectedRingingInteraction |
| 389 | NO_CHANGE // expectedCallWaitingInteraction |
| 390 | )); |
| 391 | |
| 392 | result.add(new ModeTestParameters( |
| 393 | "Call is placed on hold - 2", |
| 394 | CallAudioModeStateMachine.ENTER_TONE_OR_HOLD_FOCUS_FOR_TESTING, // initialAudioState |
| 395 | CallAudioModeStateMachine.NEW_HOLDING_CALL, // messageType |
| 396 | new CallAudioModeStateMachine.MessageArgs( |
| 397 | false, // hasActiveOrDialingCalls |
| 398 | false, // hasRingingCalls |
| 399 | true, // hasHoldingCalls |
| 400 | false, // isTonePlaying |
| 401 | false, // foregroundCallIsVoip |
| 402 | null // session |
| 403 | ), |
| 404 | CallAudioModeStateMachine.TONE_HOLD_STATE_NAME, // expectedFinalStateName |
| 405 | FOCUS_NO_CHANGE, // expectedFocus |
| 406 | NO_CHANGE, // expectedMode |
| 407 | NO_CHANGE, // expectedRingingInteraction |
| 408 | NO_CHANGE // expectedCallWaitingInteraction |
| 409 | )); |
| 410 | |
| 411 | result.add(new ModeTestParameters( |
| 412 | "Call is taken off hold - 1", |
| 413 | CallAudioModeStateMachine.ENTER_TONE_OR_HOLD_FOCUS_FOR_TESTING, // initialAudioState |
| 414 | CallAudioModeStateMachine.NO_MORE_HOLDING_CALLS, // messageType |
| 415 | new CallAudioModeStateMachine.MessageArgs( |
| 416 | true, // hasActiveOrDialingCalls |
| 417 | false, // hasRingingCalls |
| 418 | false, // hasHoldingCalls |
| 419 | false, // isTonePlaying |
| 420 | false, // foregroundCallIsVoip |
| 421 | null // session |
| 422 | ), |
| 423 | CallAudioModeStateMachine.CALL_STATE_NAME, // expectedFinalStateName |
| 424 | FOCUS_VOICE, // expectedFocus |
| 425 | AudioManager.MODE_IN_CALL, // expectedMode |
| 426 | NO_CHANGE, // expectedRingingInteraction |
| 427 | NO_CHANGE // expectedCallWaitingInteraction |
| 428 | )); |
| 429 | |
| 430 | result.add(new ModeTestParameters( |
| 431 | "Call is taken off hold - 2", |
| 432 | CallAudioModeStateMachine.ENTER_CALL_FOCUS_FOR_TESTING, // initialAudioState |
| 433 | CallAudioModeStateMachine.NEW_ACTIVE_OR_DIALING_CALL, // messageType |
| 434 | new CallAudioModeStateMachine.MessageArgs( |
| 435 | true, // hasActiveOrDialingCalls |
| 436 | false, // hasRingingCalls |
| 437 | false, // hasHoldingCalls |
| 438 | false, // isTonePlaying |
| 439 | false, // foregroundCallIsVoip |
| 440 | null // session |
| 441 | ), |
| 442 | CallAudioModeStateMachine.CALL_STATE_NAME, // expectedFinalStateName |
| 443 | FOCUS_NO_CHANGE, // expectedFocus |
| 444 | NO_CHANGE, // expectedMode |
| 445 | NO_CHANGE, // expectedRingingInteraction |
| 446 | NO_CHANGE // expectedCallWaitingInteraction |
| 447 | )); |
| 448 | |
| 449 | result.add(new ModeTestParameters( |
| 450 | "Active call disconnects while there's a call-waiting call", |
| 451 | CallAudioModeStateMachine.ENTER_CALL_FOCUS_FOR_TESTING, // initialAudioState |
| 452 | CallAudioModeStateMachine.NO_MORE_ACTIVE_OR_DIALING_CALLS, // messageType |
| 453 | new CallAudioModeStateMachine.MessageArgs( |
| 454 | false, // hasActiveOrDialingCalls |
| 455 | true, // hasRingingCalls |
| 456 | false, // hasHoldingCalls |
| 457 | true, // isTonePlaying |
| 458 | false, // foregroundCallIsVoip |
| 459 | null // session |
| 460 | ), |
| 461 | CallAudioModeStateMachine.RING_STATE_NAME, // expectedFinalStateName |
| 462 | FOCUS_RING, // expectedFocus |
| 463 | AudioManager.MODE_RINGTONE, // expectedMode |
| 464 | ON, // expectedRingingInteraction |
| 465 | OFF // expectedCallWaitingInteraction |
| 466 | )); |
| 467 | |
| 468 | result.add(new ModeTestParameters( |
| 469 | "New dialing call when there's a call on hold", |
| 470 | CallAudioModeStateMachine.ENTER_TONE_OR_HOLD_FOCUS_FOR_TESTING, // initialAudioState |
| 471 | CallAudioModeStateMachine.NEW_ACTIVE_OR_DIALING_CALL, // messageType |
| 472 | new CallAudioModeStateMachine.MessageArgs( |
| 473 | true, // hasActiveOrDialingCalls |
| 474 | false, // hasRingingCalls |
| 475 | true, // hasHoldingCalls |
| 476 | false, // isTonePlaying |
| 477 | false, // foregroundCallIsVoip |
| 478 | null // session |
| 479 | ), |
| 480 | CallAudioModeStateMachine.CALL_STATE_NAME, // expectedFinalStateName |
| 481 | FOCUS_VOICE, // expectedFocus |
| 482 | AudioManager.MODE_IN_CALL, // expectedMode |
| 483 | NO_CHANGE, // expectedRingingInteraction |
| 484 | NO_CHANGE // expectedCallWaitingInteraction |
| 485 | )); |
| 486 | |
| 487 | result.add(new ModeTestParameters( |
| 488 | "Ringing call disconnects with a holding call in the background", |
| 489 | CallAudioModeStateMachine.ENTER_RING_FOCUS_FOR_TESTING, // initialAudioState |
| 490 | CallAudioModeStateMachine.NO_MORE_RINGING_CALLS, // messageType |
| 491 | new CallAudioModeStateMachine.MessageArgs( |
| 492 | false, // hasActiveOrDialingCalls |
| 493 | false, // hasRingingCalls |
| 494 | true, // hasHoldingCalls |
| 495 | false, // isTonePlaying |
| 496 | false, // foregroundCallIsVoip |
| 497 | null // session |
| 498 | ), |
| 499 | CallAudioModeStateMachine.TONE_HOLD_STATE_NAME, // expectedFinalStateName |
| 500 | FOCUS_VOICE, // expectedFocus |
| 501 | AudioManager.MODE_NORMAL, // expectedMode -- we're expecting this because |
| 502 | // mMostRecentMode hasn't been set properly. |
| 503 | OFF, // expectedRingingInteraction |
| 504 | NO_CHANGE // expectedCallWaitingInteraction |
| 505 | )); |
| 506 | |
| 507 | result.add(new ModeTestParameters( |
| 508 | "Foreground call transitions from sim to voip", |
| 509 | CallAudioModeStateMachine.ENTER_CALL_FOCUS_FOR_TESTING, // initialAudioState |
| 510 | CallAudioModeStateMachine.FOREGROUND_VOIP_MODE_CHANGE, // messageType |
| 511 | new CallAudioModeStateMachine.MessageArgs( |
| 512 | true, // hasActiveOrDialingCalls |
| 513 | false, // hasRingingCalls |
| 514 | false, // hasHoldingCalls |
| 515 | false, // isTonePlaying |
| 516 | true, // foregroundCallIsVoip |
| 517 | null // session |
| 518 | ), |
| 519 | CallAudioModeStateMachine.COMMS_STATE_NAME, // expectedFinalStateName |
| 520 | FOCUS_VOICE, // expectedFocus |
| 521 | AudioManager.MODE_IN_COMMUNICATION, // expectedMode |
| 522 | NO_CHANGE, // expectedRingingInteraction |
| 523 | NO_CHANGE // expectedCallWaitingInteraction |
| 524 | )); |
| 525 | |
| 526 | result.add(new ModeTestParameters( |
| 527 | "Foreground call transitions from voip to sim", |
| 528 | CallAudioModeStateMachine.ENTER_COMMS_FOCUS_FOR_TESTING, // initialAudioState |
| 529 | CallAudioModeStateMachine.FOREGROUND_VOIP_MODE_CHANGE, // messageType |
| 530 | new CallAudioModeStateMachine.MessageArgs( |
| 531 | true, // hasActiveOrDialingCalls |
| 532 | false, // hasRingingCalls |
| 533 | false, // hasHoldingCalls |
| 534 | false, // isTonePlaying |
| 535 | false, // foregroundCallIsVoip |
| 536 | null // session |
| 537 | ), |
| 538 | CallAudioModeStateMachine.CALL_STATE_NAME, // expectedFinalStateName |
| 539 | FOCUS_VOICE, // expectedFocus |
| 540 | AudioManager.MODE_IN_CALL, // expectedMode |
| 541 | NO_CHANGE, // expectedRingingInteraction |
| 542 | NO_CHANGE // expectedCallWaitingInteraction |
| 543 | )); |
| 544 | |
| 545 | result.add(new ModeTestParameters( |
| 546 | "Call-waiting hangs up before being answered, with another sim call in " + |
| 547 | "foreground", |
| 548 | CallAudioModeStateMachine.ENTER_CALL_FOCUS_FOR_TESTING, // initialAudioState |
| 549 | CallAudioModeStateMachine.NO_MORE_RINGING_CALLS, // messageType |
| 550 | new CallAudioModeStateMachine.MessageArgs( |
| 551 | true, // hasActiveOrDialingCalls |
| 552 | false, // hasRingingCalls |
| 553 | false, // hasHoldingCalls |
| 554 | true, // isTonePlaying |
| 555 | false, // foregroundCallIsVoip |
| 556 | null // session |
| 557 | ), |
| 558 | CallAudioModeStateMachine.CALL_STATE_NAME, // expectedFinalStateName |
| 559 | FOCUS_NO_CHANGE, // expectedFocus |
| 560 | NO_CHANGE, // expectedMode |
| 561 | NO_CHANGE, // expectedRingingInteraction |
| 562 | OFF // expectedCallWaitingInteraction |
| 563 | )); |
| 564 | |
| 565 | result.add(new ModeTestParameters( |
| 566 | "Call-waiting hangs up before being answered, with another voip call in " + |
| 567 | "foreground", |
| 568 | CallAudioModeStateMachine.ENTER_COMMS_FOCUS_FOR_TESTING, // initialAudioState |
| 569 | CallAudioModeStateMachine.NO_MORE_RINGING_CALLS, // messageType |
| 570 | new CallAudioModeStateMachine.MessageArgs( |
| 571 | true, // hasActiveOrDialingCalls |
| 572 | false, // hasRingingCalls |
| 573 | false, // hasHoldingCalls |
| 574 | true, // isTonePlaying |
| 575 | true, // foregroundCallIsVoip |
| 576 | null // session |
| 577 | ), |
| 578 | CallAudioModeStateMachine.COMMS_STATE_NAME, // expectedFinalStateName |
| 579 | FOCUS_NO_CHANGE, // expectedFocus |
| 580 | NO_CHANGE, // expectedMode |
| 581 | NO_CHANGE, // expectedRingingInteraction |
| 582 | OFF // expectedCallWaitingInteraction |
| 583 | )); |
| 584 | |
| 585 | return result; |
| 586 | } |
| 587 | |
| 588 | private void resetMocks() { |
| 589 | reset(mCallAudioManager, mAudioManager); |
| 590 | } |
| 591 | } |