Skip to content

feat: allow apps to provide Android Context externally#391

Merged
tony19 merged 1 commit into
mainfrom
claude/review-open-prs-avya32
Jul 9, 2026
Merged

feat: allow apps to provide Android Context externally#391
tony19 merged 1 commit into
mainfrom
claude/review-open-prs-avya32

Conversation

@tony19

@tony19 tony19 commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

This is a reviewed and touched-up version of #361 (by @lgoldstein), opened as a draft for your review as part of the open-PR triage.

It adds a public API — AndroidContextUtil.setApplicationContext(Context) — so an application can supply the Android Context explicitly instead of relying on the reflection-based AppGlobals.getInitialApplication() workaround, which may stop working under Google's non-SDK interface restrictions.

  • The provided context is reduced to its application context and stored in a static AtomicReference.
  • getContext() now prefers the externally provided context and falls back to the existing reflection workaround when none was set.
  • The constructor now takes android.content.Context (a supertype of the old ContextWrapper, so existing source callers keep compiling).
  • Hardcoded API-level literals were modernized to Build.VERSION_CODES.*, and getVersionCode() uses getLongVersionCode() on API 28+.

What I changed on top of #361

  1. Fixed the README example. The docs referenced a non-existent AndroidContextUtils class (plural); corrected to AndroidContextUtil so the snippets compile.
  2. Added test coverage in AndroidContextUtilTest for the new API: that a provided context is used, that the no-arg constructor picks it up, and that clearing it falls back to reflection. The static holder is now reset in @Before/@After so it can't leak between tests.

Notes / things to confirm

Credit for the original change goes to @lgoldstein (#361).

🤖 Generated with Claude Code

https://claude.ai/code/session_01BBrtdK6G1WtVPvCxenWAXz


Generated by Claude Code

Adds AndroidContextUtil.setApplicationContext(Context) so an application can
supply the Android Context instead of relying on the reflection-based
AppGlobals.getInitialApplication() workaround, which may break under Google's
non-SDK interface restrictions. The provided context is reduced to its
application context and held in a static AtomicReference; getContext() prefers
it and falls back to reflection when none was provided.

Also modernizes hardcoded API-level literals to Build.VERSION_CODES constants
and uses getLongVersionCode() on API 28+.

This builds on the work from #361 by lgoldstein, adding test coverage for the
new API (including static-holder reset between tests) and fixing the README
example that referenced a non-existent "AndroidContextUtils" class.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BBrtdK6G1WtVPvCxenWAXz
@tony19 tony19 marked this pull request as ready for review July 9, 2026 04:52
@tony19 tony19 merged commit e1e97ab into main Jul 9, 2026
3 checks passed
@tony19 tony19 deleted the claude/review-open-prs-avya32 branch July 9, 2026 04:52
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