Skip to content

fix: [SDK-4845] always finish base notification trampoline via finally#2681

Merged
abdulraqeeb33 merged 3 commits into
mainfrom
ar/sdk-4845
Jul 8, 2026
Merged

fix: [SDK-4845] always finish base notification trampoline via finally#2681
abdulraqeeb33 merged 3 commits into
mainfrom
ar/sdk-4845

Conversation

@abdulraqeeb33

Copy link
Copy Markdown
Contributor

Summary

Follow-up to SDK-4734 / #2678, addressing @fadi-george's review comment on that PR.

PR #2678 fixed the HMS trampoline so finish() always runs (via try/finally) even when init fails or processing throws. NotificationOpenedActivityBase — the GMS / base trampoline used by NotificationOpenedActivity and NotificationOpenedActivityAndroid22AndOlder — still had the same early-return-before-finish shape:

  • If OneSignal.initWithContext(...) returns false, the coroutine early-returns and AndroidUtils.finishSafely(...) is skipped.
  • If openedProcessor.processFromContext(...) throws, finishSafely(...) is likewise skipped.

In both cases the transient trampoline activity is never dismissed and lingers in its task. Not a crash (suspendifyOnDefault catches/logs and the init branch is a plain early return), but a real, low-frequency lifecycle strand that is inconsistent with the now-fixed HMS path.

Fix

Wrap the coroutine body in try { ... } finally { runOnUiThread { AndroidUtils.finishSafely(this) } } so the trampoline is always dismissed on the main thread after processing, an early return, or an exception. Keeping finish() in finally (after processFromContext) preserves the documented Xiaomi requirement that startActivity() runs before finish().

Test plan

Added two regression tests to NotificationOpenedActivityBaseTest mirroring the HMS coverage:

  • does not finish the base trampoline until after open processing runs — asserts the synchronous part does not finish the activity, and it finishes only after processFromContext runs.
  • always finishes the base trampoline even when initialization fails — asserts the activity is finished on the initWithContext == false early-return path (the core regression) without invoking processFromContext.

Full module unit tests and detekt pass locally.

Made with Cursor

NotificationOpenedActivityBase called AndroidUtils.finishSafely only on the
success path: an init failure early-returned and a thrown processFromContext
both skipped it, stranding the transient trampoline activity. This is the same
early-return-before-finish shape removed from the HMS trampoline in #2678.

Wrap the coroutine body in try/finally so finishSafely always runs on the main
thread after processing, an early return, or an exception. Keeping finish in
finally (after processFromContext) preserves the Xiaomi
startActivity()-before-finish() ordering.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

📊 Diff Coverage Report

Diff Coverage Report (Changed Lines Only)

Gate: aggregate coverage on changed executable lines must be ≥ 80% (JaCoCo line data for lines touched in the diff).

Changed Files Coverage

  • NotificationOpenedActivityBase.kt: 0/8 touched executable lines (0.0%) (16 touched lines in diff)
    • 8 uncovered touched lines in this file

Overall (aggregate gate)

0/8 touched executable lines covered (0.0% — requires ≥ 80%)

Per-file detail (informational; gate is aggregate above):

  • NotificationOpenedActivityBase.kt: 0.0% (8 uncovered touched lines)

❌ Coverage Check Failed

Aggregate coverage on touched lines is 0.0% (minimum 80%).

📥 View workflow run

AR Abdul Azeez and others added 2 commits July 7, 2026 11:33
…st intent

Address review feedback on the base-trampoline finally fix:
- Rename the success-path test to reflect it is an ordering guard (finish after
  processFromContext), not the core regression.
- Add a regression test asserting the trampoline is still finished when
  processFromContext throws (the exception propagates, but finally must have
  finished the activity first).
- Drain the main-thread looper before asserting isFinishing so the assertions
  don't rely on runOnUiThread happening to run synchronously.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep the comments concise and free of ticket numbers.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

2 participants