Commit a96df4f
authored
fix: callingx background handling (#2310)
### 💡 Overview
Fixes two Android bugs where callingx calls break when the app is
backgrounded (locked screen cases) — e.g. answering a ringing call on
the lock screen and then tabbing out:
1. Audio and video drop a few seconds after backgrounding with locked
screen.
2. Call drops 2 minutes after backgrounding with locked screen.
Both only affect the **callingx-managed** path (ringing calls, or
non-ringing calls with `enableOngoingCalls`).
### 📝 Implementation notes
Two independent root causes, two fixes:
**1. Background mic/camera behavior**
`CallService` ran as a `phoneCall`-only foreground service, which on
Android 14+ doesn't grant microphone/camera access in the background —
so the mic went silent and the camera was cut shortly after
backgrounding.
Fix: declare and use the `microphone`/`camera` FGS types. Since those
types can't be activated from the background (the service starts from a
push), `CallService` starts as `phoneCall` and is **re-promoted** to
include mic/camera during the foreground answer window; the types then
persist into the background.
**2. JS timers suspended in background**
Telecom + FGS with `phoneCall` keep the process alive, but without a
background keep-alive task, React Native suspended JS timers while
backgrounded. The client's healthcheck pings stopped, and the server
dropped the participant.
Fix: run a headless JS task on callingx's existing `CallService` (no
extra notification) to keep RN/timers alive. It's shared by the
ringing-push handler and the keep-call-alive hook, and stops once the
call ends. `useAndroidKeepCallAliveEffect` and the push flow now use
this instead of bailing out, with guards so only one keep-alive
mechanism runs per call.
🎫 Ticket:
https://linear.app/stream/issue/RN-404/callingx-background-with-locked-screen-issues
📑 Docs: GetStream/docs-content#1396
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
## Summary by CodeRabbit
* **New Features**
* Added Android ref-counted background keep-alive via
`acquireBackgroundTask(owner)` / `releaseBackgroundTask(owner)`.
* Foreground service now declares microphone/camera types when
available, with automatic upgrading when the app returns to the
foreground.
* **Bug Fixes**
* Improved foreground/background transition handling to prevent
unintended call shutdowns.
* Enhanced cleanup for ended calls, including ringing calls triggered
from push events.
* **Documentation**
* Updated public API docs to reflect the new background keep-alive
workflow.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent 23d9f49 commit a96df4f
8 files changed
Lines changed: 457 additions & 252 deletions
File tree
- packages
- react-native-callingx
- android/src/main
- java/io/getstream/rn/callingx
- utils
- src
- react-native-sdk/src
- hooks
- utils/push
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | | - | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
Lines changed: 82 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| |||
108 | 111 | | |
109 | 112 | | |
110 | 113 | | |
111 | | - | |
| 114 | + | |
112 | 115 | | |
113 | 116 | | |
114 | 117 | | |
| |||
143 | 146 | | |
144 | 147 | | |
145 | 148 | | |
| 149 | + | |
146 | 150 | | |
147 | 151 | | |
| 152 | + | |
| 153 | + | |
148 | 154 | | |
149 | 155 | | |
150 | 156 | | |
| |||
227 | 233 | | |
228 | 234 | | |
229 | 235 | | |
| 236 | + | |
| 237 | + | |
230 | 238 | | |
231 | 239 | | |
232 | 240 | | |
233 | 241 | | |
234 | 242 | | |
235 | 243 | | |
| 244 | + | |
| 245 | + | |
236 | 246 | | |
237 | 247 | | |
238 | 248 | | |
| |||
571 | 581 | | |
572 | 582 | | |
573 | 583 | | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
| 584 | + | |
579 | 585 | | |
580 | 586 | | |
581 | 587 | | |
| |||
589 | 595 | | |
590 | 596 | | |
591 | 597 | | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
592 | 668 | | |
593 | 669 | | |
594 | 670 | | |
| |||
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| 11 | + | |
| 12 | + | |
9 | 13 | | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
16 | 30 | | |
17 | 31 | | |
18 | 32 | | |
| |||
30 | 44 | | |
31 | 45 | | |
32 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
33 | 55 | | |
34 | 56 | | |
35 | 57 | | |
| |||
0 commit comments