Skip to content

fix(android): process lifecycle, foreground pushes and quick replies - #29676

Merged
chrisnojima merged 7 commits into
nojima/HOTPOT-js-05-sessionfrom
nojima/HOTPOT-js-06-android
Sep 23, 2026
Merged

chrisnojima merged 7 commits into
nojima/HOTPOT-js-05-sessionfrom
nojima/HOTPOT-js-06-android

Conversation

@chrisnojima

Copy link
Copy Markdown
Contributor

Stack 4/7 on #29650.

Why

  • A reply typed in the notification shade while the app is on screen is dropped. Master's whileActive returns early in the foreground, yet the notification says "Replied".
  • A foreground push never reaches Go, so it is not unboxed or acked. With background now reported about 700 ms after the last activity stops, that also covers a push arriving just after Home.
  • Quick reply runs on the main thread. Go sends before checking login or message id, and swallows the send error (test(bind): failing tests for quick reply error handling #29667).
  • Push work that throws leaves Go in BACKGROUNDACTIVE until the next lifecycle event.
  • Other problems: background sync jobs pile up as duplicates, the seen-push set is unbounded, and share intents wait on a 500 ms poll.

What this changes

  • AppLifecycleReporter replaces the previous PR's forwarder, behind a testable LifecycleBind seam. appWillExit runs only on a real finish, not on a configuration change.
  • withBackgroundActive:
    • A loud push always reaches Go, and its notifier skips display while in the foreground.
    • In the background it reports BACKGROUNDACTIVE, runs the work, then in finally calls appDidEnterBackground and starts a background task if one is needed.
    • A silent push in the foreground skips Go, as on master.
  • Quick reply runs via goAsync on a worker thread. It refuses when:
    • the uid can't be read
    • the uid is empty
    • the uid differs from the notification's uid
    • the message id is negative
  • Housekeeping:
    • share intents are parked until JS asks
    • background sync is one unique periodic job
    • the seen-push set is capped at 100

Judgment calls

  • Foreground quick replies now send. Master showed "Replied" without sending. "Replied" can still show for a failed send, because Go swallows the error (test(bind): failing tests for quick reply error handling #29667).
  • A reply from a notification shown before this update is refused once. Such a notification carries no uid. It fails safely rather than posting as whichever account is current.
  • withBackgroundActive returns Go to the background even when the work throws. That is one extra compaction on a rare error path, rather than Go staying in BACKGROUNDACTIVE indefinitely.
  • A foreground loud push is now unboxed and acked, with display suppressed, and marked seen. Master neither showed nor acked it.
  • Kotlin never calls setAppStateBackground. appDidEnterBackground already does, so master's second flush is gone.
  • JS sees "background" twice on exit (activity destroy, then process ON_STOP). The second is a no-op.

Tests

  • WithBackgroundActiveTest covers:
    • a foreground push, with display suppressed
    • background ordering, with no second background report
    • the app opened during a push
    • silent pushes, in the foreground and in the background
    • throwing work
  • SendQuickReplyTest covers each refusal.
  • AppLifecycleReporterTest, RunReceiverWorkTest and BackgroundSyncScheduleTest also run.

The guards were mutation-checked.

…he main thread

One lifecycle reporter: AppLifecycleReporter (ProcessLifecycleOwner) talks to
Go and JS through a LifecycleBind seam so the mapping runs in JVM tests.
MainActivity resume/finishing-destroy go through it too.

Pushes always reach Go. In the foreground master returned before calling
handleBackgroundNotification, so a foreground push was never unboxed or
acked; now Go handles it with a notifier that does not display while the app
is in the foreground. In the background Go is held in BACKGROUNDACTIVE around
the work, then appDidEnterBackground decides whether to keep running.

Quick reply runs on a worker thread under goAsync with a status
notification, is not sent when logged out or for a negative message id (Go
sends before it checks either and swallows the send's error), and is sent in
the foreground too (master skipped it).

Also: one unique periodic background sync job (legacy duplicates cancelled
once), share intents handed over when JS registers instead of polling, and
the Kotlin seen-set capped at 100.

Flush audit (calls that run a leveldb flush on master):
- Process ON_STOP appDidEnterBackground -> appBeginBackgroundTaskNonblock:
  unchanged from the parent, no else branch.
- appWillExit: MainActivity finishing destroy, now also skipped when
  isChangingConfigurations (subset of the parent's calls).
- Push / quick reply window, background only: appDidEnterBackground ->
  appBeginBackgroundTaskNonblock, same call master made on the same path;
  master's else setAppStateBackground (a second flush) is removed.
- Foreground push / quick reply: no lifecycle call (master made none).
- Quick reply rejected by the pre-checks: no window, no call (master opened
  one).
…ly whose uid can't be read

A silent push gets no notifier, and Go only acks a push it can display, so in
the foreground Go unboxed it for nothing; master skipped it there. The
quick reply keeps running in the foreground.

Reading the current uid can throw; the reply now reports failure instead of
leaving the RemoteInput stuck sending.

Flush audit: no change to any flushing call. A foreground silent push makes
no lifecycle call (as on master); a background one is unchanged from the
previous commit.
The notification carries the account it was shown for; Go posts as the
current account, so a mismatch reports that the reply couldn't be sent.
@chrisnojima
chrisnojima added this pull request to stack #29680 September 23, 2026 19:54
@chrisnojima
chrisnojima removed this pull request from stack #29680 September 23, 2026 19:56
@chrisnojima
chrisnojima added this pull request to stack #29681 September 23, 2026 19:56
@chrisnojima
chrisnojima merged commit e4b47fa into master Sep 23, 2026
1 check passed
@chrisnojima
chrisnojima deleted the nojima/HOTPOT-js-06-android branch September 23, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant