Skip to content

perf(android): avoid screen and device-type IPC candidates - #655

Merged
marandaneto merged 3 commits into
mainfrom
fix/remaining-main-thread-ipc
Jul 27, 2026
Merged

perf(android): avoid screen and device-type IPC candidates#655
marandaneto merged 3 commits into
mainfrom
fix/remaining-main-thread-ipc

Conversation

@marandaneto

@marandaneto marandaneto commented Jul 27, 2026

Copy link
Copy Markdown
Member

💡 Motivation and Context

Screen autocapture queried ActivityInfo through PackageManager on every Activity.onStart, and device-type detection queried UiModeManager while building static context. Both paths can run on the main thread and can be served from state already loaded in the process. Screen autocapture now uses the activity's current title, so apps that set titles dynamically may emit a different $screen_name for $screen events and change report grouping; this is called out in the changeset.

The network-time candidate was also reviewed. Android already caches the synchronized network-time sample, and reading it does not perform an NTP request. This PR therefore keeps the simpler existing once-per-minute synchronous cache and documents that its occasional cached-value IPC is accepted.

💚 How did you test it?

  • make test
  • make checkFormat
  • Focused unit tests for screen-name compatibility without getActivityInfo and API 28 device-type compatibility

An API 28 Perfetto Binder trace was considered, but no Android device or emulator was connected locally, so this PR does not claim runtime trace verification.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with the Pi coding agent using repository file, shell, Git, Gradle, and GitHub CLI tools. No shareable agent session link was generated. Activity and UI-mode queries use already-loaded local state instead of adding callback/cache complexity. The proposed asynchronous network-time refresh was rolled back after reviewing AOSP: the OS already caches network time, and the existing once-per-minute synchronous read is the simpler accepted tradeoff. TelephonyManager.networkOperatorName remains unchanged because the callback alternative would require location permission.

@marandaneto marandaneto self-assigned this Jul 27, 2026
@marandaneto marandaneto changed the title perf(android): avoid remaining main-thread IPC candidates perf(android): avoid screen and device-type IPC candidates Jul 27, 2026
@marandaneto
marandaneto marked this pull request as ready for review July 27, 2026 07:24
@marandaneto
marandaneto requested a review from a team as a code owner July 27, 2026 07:24
@greptile-apps

greptile-apps Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
posthog-android/src/main/java/com/posthog/android/internal/PostHogAndroidUtils.kt:138
**Runtime titles rename screen events**

When an activity changes its title before `onActivityStarted`, this code emits the mutable runtime title instead of the manifest-defined label previously returned by `ActivityInfo.loadLabel`, causing existing screen events to be renamed or split across analytics dashboards.

Reviews (1): Last reviewed commit: "revert: keep synchronous network time ca..." | Re-trigger Greptile

@ioannisj ioannisj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG Left a discussion point on greptile thread

@marandaneto
marandaneto enabled auto-merge (squash) July 27, 2026 08:27
@marandaneto
marandaneto merged commit b3c6ccc into main Jul 27, 2026
15 checks passed
@marandaneto
marandaneto deleted the fix/remaining-main-thread-ipc branch July 27, 2026 08:35
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