Report memory pressure and guard the background service ask - #498
Open
samoylenkodmitry wants to merge 5 commits into
Open
Report memory pressure and guard the background service ask#498samoylenkodmitry wants to merge 5 commits into
samoylenkodmitry wants to merge 5 commits into
Conversation
Android's onTrimMemory now reaches applications as a collected event stream: rememberMemoryPressure() delivers UiHidden, Low or Critical, so an app can free caches and warm model sessions the moment the platform asks, instead of on its own timers. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A launch with the screen off pauses without ever resuming. Asking for a foreground service from that state is a background start: the system accepts the request, never creates the service, and ends the process for the missing startForeground. Reproduced twice on a Pixel 9 Pro on Android 16; with the guard the same start stays alive with no service asked. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The activity's onTrimMemory override never fired on an EMUI Android 10 phone, so trim reports silently went nowhere there. A ComponentCallbacks2 registered on the application context receives every trim on every version; onLowMemory maps to the complete level. Verified on that phone: one "platform pressure" report per event after the change, none before. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
From the crash-fix session, verified together with this branch on the phones: the activity asks for the foreground service 700 ms after a pause and a resume cancels the ask, so a launch-shaped pause never starts a service the framework then refuses. The service tracks its own startForeground obligation, and a stop that arrives inside that window waits for the service to honour it first. A refused set_active call now logs instead of passing quietly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
samoylenkodmitry
force-pushed
the
fix/play-vitals-memory
branch
from
August 27, 2026 16:02
e4dda62 to
0a8eb55
Compare
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Google Play sets memory limits from February 2027, judged as the 90th percentile of Anonymous RSS + Swap per app state. The tightest state is a foreground service with the app off screen: 1 GB on 4 GB phones, 2 GB even on 16 GB phones. The framework had no road to hand trim reports to an application, and two service-ask defects ended the process on real phones.
What
rememberMemoryPressure(): Android'sonTrimMemoryreaches applications as a collected event stream (UiHidden, Low, Critical), plusobserve_memory_pressurefor work that must run while the composition loop sleeps. Unit tests cover the registry and the level mapping.ComponentCallbacks2on the application context. The activity override never fired on an EMUI Android 10 phone; the registered callback fires everywhere.set_activelogs instead of passing quietly.Checked
cranscan consumes this branch through
[patch.crates-io]until a release carries it.🤖 Generated with Claude Code