Skip to content

perf(engine): stop logcat while precise input is live - #70

Closed
jeffreyyan4 wants to merge 1 commit into
heykay-47:mainfrom
jeffreyyan4:perf/pause-logcat-during-precise-input
Closed

jeffreyyan4 wants to merge 1 commit into
heykay-47:mainfrom
jeffreyyan4:perf/pause-logcat-during-precise-input

Conversation

@jeffreyyan4

Copy link
Copy Markdown

Why

Once the Shizuku input stream is live, LogReader skips every log line (shouldParse() is false), but the unfiltered logcat -v threadtime,uid -T 1 keeps running through the shell service. That keeps logd, the shell logcat process and the app's reader thread busy with every line on the phone, all day, outside Doze.

On a Find X9 Pro (ColorOS 17, CPH2791_17.0.0.102) after 6 days of uptime, top showed logd at about 80 minutes of CPU time and the log-reader and logcat processes at about 17 minutes between them. In that state the stream does no detection work.

What changed

  • SnapEngine stops the log reader while precise input is live and no teaching session needs the log. Teaching still learns from the log, so beginTeaching and prepareTeachingLogs start it again, and releaseTeachingLogs and endTeaching pause it afterwards.
  • When the input stream ends, for example when Shizuku stops, the log reader restarts straight away as the fallback. It goes through the existing onAccessChanged(OFF) and reconnect path, so background consent works as before.
  • While paused, the last LogAccess state is kept. The home status, listeningSince and the paused notification therefore behave as before. startBackgroundLogs and onConsentResumed don't start a reader or show the consent prompt while paused.
  • A new LogPause class keeps the pause and resume state, covered by LogPauseTest.
  • docs/privacy.md and CONTRIBUTING.md described the log stream staying open during precise input. Both now describe the new behaviour.

This adds no new detection risk. While precise input was live, log lines were already discarded without parsing. Before the first key edge after a start, the log still runs as it does today.

CI on the fork passed: unit tests, release build and reproducibility (run). The advisory lint step reports the existing StartActivityAndCollapseDeprecated error in SnapTileService.kt:80, which this change doesn't touch.

Tested on device: not tested

🤖 Generated with Claude Code

Once the Shizuku input stream is live, log lines are read and discarded
without parsing, but the unfiltered logcat stream keeps running. That
keeps logd, the shell logcat process and the app's reader thread busy
with every line on the phone, around the clock.

Stop the log reader while precise input is live and no teaching session
needs the log. Restart it when teaching begins, or as the fallback when
the input stream ends. The last access state is kept while paused, so
the home status, listening state and paused notification are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Input Handling
    • System-log reading now pauses while precise input is active and resumes during key teaching.
    • If the precise input stream ends, system-log reading can restart as a fallback.
    • On Find X9, the precise-input option appears after a valid key event is received and a key is learned.

SnapEngine now pauses system-log reading during precise input, except while teaching a key. It updates connection and reconnect behavior based on log demand. The privacy description and Find X9 device note also reflect the updated behavior.

Changes: System-log pause behavior

Layer / File(s) Summary
Pause rules and state
app/src/main/java/com/heykay/snapkeymap/SnapEngine.kt, app/src/test/java/com/heykay/snapkeymap/LogPauseTest.kt
LogPause allows log reads when precise input is inactive or teaching is active. Tests cover read conditions, repeated pauses, and resume behavior.
Engine lifecycle and documentation
app/src/main/java/com/heykay/snapkeymap/SnapEngine.kt, docs/privacy.md, CONTRIBUTING.md
SnapEngine applies log-demand gating across connection, reconnect, teaching, consent, background-start, stop, and input-source updates. The privacy description and Find X9 note reflect the updated behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Merge Risk: Minimal · up to a7f76

No actionable issue remains from this review; the change is mergeable after normal checks.

Security architecture risk: Low · up to a7f76

The change reduces unnecessary device-log reading without adding privileges or external interfaces. The remaining risk is in restoring the fallback reader across input loss and consent changes; concurrent Android lifecycle behavior remains unverified in operation.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The affected privileged-data scope remains the existing on-device system-log stream and its detection fallback. The change reduces when that stream is consumed; the compared production changes introduce no new data destination, permission, or cross-service authority.

Trust Boundaries and Controls

  • observed — Connection and reconnect retain reader-demand and READ_LOGS prerequisites. Background startup retains the foreground-consent route for local reading, while consent resume now avoids starting an unnecessary reader during precise input. The existing accessibility-service boundary requires BIND_ACCESSIBILITY_SERVICE.

Resilience and Maintainability Implications

  • observed — Existing cleanup and identity controls contain late work after a pause: LogReader clears the current session and rejects replaced-session reports, while SnapEngine rejects stale queued log generations. ShizukuLogStream also checks closure during binding and after acquiring the returned stream, closes late-acquired input, and schedules service unbinding.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 32233d5 and a7f7631.

Files selected for processing: 4

  • CONTRIBUTING.md
  • app/src/main/java/com/heykay/snapkeymap/SnapEngine.kt
  • app/src/test/java/com/heykay/snapkeymap/LogPauseTest.kt
  • docs/privacy.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@jeffreyyan4 jeffreyyan4 closed this Nov 7, 2026
@jeffreyyan4
jeffreyyan4 deleted the perf/pause-logcat-during-precise-input branch November 7, 2026 15:04
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