1/** Android handoffs report background; deferred work must wait to avoid tearing down active flows. */
2let activeHandoffs = 0;
3
4/** Returns an idempotent end function; call it when the handoff resolves. */
5export function beginForegroundHandoff(): () => void {
6 activeHandoffs += 1;
7 let ended = false;
8 return () => {
9 if (ended) return;
10 ended = true;
11 activeHandoffs -= 1;
12 };
13}
14
15export function isForegroundHandoffActive(): boolean {
16 return activeHandoffs > 0;
17}