Skip to content

PhoneWindowManager: honor disabled screen-on reclaim setting - #1336

Draft
CeRRiLLo89 wants to merge 5 commits into
crdroidandroid:16.0from
CeRRiLLo89:raphael-screen-on-reclaim-fix
Draft

PhoneWindowManager: honor disabled screen-on reclaim setting#1336
CeRRiLLo89 wants to merge 5 commits into
crdroidandroid:16.0from
CeRRiLLo89:raphael-screen-on-reclaim-fix

Conversation

@CeRRiLLo89

Copy link
Copy Markdown
Contributor

Summary

Re-read SCREEN_ON_MEMORY_RECLAIM immediately before executing the delayed
screen-on memory reclaim.

Problem

PhoneWindowManager schedules mMemoryOpt from the cached
mScreenOnReclaim value and executes the callback 1250 ms later.

The callback previously called releaseMemoryAtScreenOn() without checking
the current setting again.

On raphael with crDroid Android 16, screen-on reclaim was reproduced while:

  • the active user was 0;
  • screen_on_memory_reclaim was 0;
  • the exact-build mitigation module was disabled;
  • the original services.jar was active.

One controlled screen-on cycle produced the reclaim log 1251 ms after wake
and killed 25 cached processes, including the Android Auto car process.

The exact reason for the stale cached state has not been proven. It may involve
setting-observer timing or cross-thread visibility.

Change

  • Centralize the current setting lookup.
  • Mark the cached flag volatile because it is updated and read from different
    execution contexts.
  • Re-read the setting before the delayed callback releases memory.
  • Preserve the existing reclaim behavior when the setting is enabled.
  • Expose the delayed callback for unit testing with @VisibleForTesting.

This does not modify:

  • LMKD
  • ZRAM
  • Cached App Freezer
  • the reclaim interval
  • the reclaim parameters
  • system_server garbage collection

Tests

Added unit coverage verifying that:

  • a disabled setting prevents the delayed callback from calling
    releaseMemory();
  • an enabled setting preserves the existing reclaim call.

The ActivityManager call is stubbed so the tests do not perform a real reclaim.

The tests have been added but have not been executed locally because a full
Android framework build environment is not currently available.

Expected test command:

atest WmTests:PhoneWindowManagerTests

Device context

Device: Xiaomi Mi 9T Pro / Redmi K20 Pro (raphael)

Build: crDroid Android 16 v12.11-20260623

The exact-build KernelSU mitigation remains enabled until a ROM build
containing this source change is available for controlled validation.

Validation status

  • Controlled device reproduction: completed.
  • Source review: completed.
  • Source compilation: pending.
  • Unit test execution: pending.
  • Device validation with a source build: pending.

Screen-on reclaim is scheduled from a cached setting and executes after a 1250 ms delay.

Re-read SCREEN_ON_MEMORY_RECLAIM before running the delayed reclaim so the disabled state is honored even if the cached value is stale or the setting changes after scheduling.

Mark the cached flag volatile because it is updated by the settings observer and read from the power notifier path.
Remove whitespace from the blank line after mMemoryOpt.
Verify that the delayed screen-on reclaim callback rechecks the current
SCREEN_ON_MEMORY_RECLAIM setting before releasing memory.

Cover both the disabled and enabled paths while stubbing the ActivityManager
call to avoid running a real reclaim during the test.
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