(quitLoop: () => boolean, timeoutSec: number, shouldThrow: boolean = true)
| 411 | } |
| 412 | |
| 413 | function doModalAndroid(quitLoop: () => boolean, timeoutSec: number, shouldThrow: boolean = true) { |
| 414 | if (!quitLoop) { |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | prepareModal(); |
| 419 | |
| 420 | const queue = android.os.Looper.myQueue(); |
| 421 | |
| 422 | let quit = false; |
| 423 | let timeout = false; |
| 424 | setTimeout(() => { |
| 425 | quit = true; |
| 426 | timeout = true; |
| 427 | }, timeoutSec * 1000); |
| 428 | |
| 429 | let msg; |
| 430 | |
| 431 | while (!quit) { |
| 432 | msg = nextMethod.invoke(queue, null); |
| 433 | if (msg) { |
| 434 | const target = targetField.get(msg); |
| 435 | if (!target) { |
| 436 | quit = true; |
| 437 | } else { |
| 438 | target.dispatchMessage(msg); |
| 439 | } |
| 440 | |
| 441 | if (sdkVersion < 21) { |
| 442 | //https://code.google.com/p/android-test-kit/issues/detail?id=84 |
| 443 | msg.recycle(); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | if (shouldThrow && timeout) { |
| 448 | throw new Error('waitUntilReady Timeout.'); |
| 449 | } |
| 450 | |
| 451 | if (!quit && quitLoop()) { |
| 452 | quit = true; |
| 453 | } |
| 454 | } |
| 455 | } |
no test coverage detected