Skip to content

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

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

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

Conversation

@CeRRiLLo89

@CeRRiLLo89 CeRRiLLo89 commented Jul 31, 2026

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.
  • Isolate the two reclaim tests from the complete PhoneWindowManager
    initialization, because the callback only requires the settings context and
    the ActivityManager service.

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 at callback execution prevents releaseMemory() from
    being called;
  • an enabled setting at callback execution preserves the existing reclaim
    call.

The tests initialize only the dependencies required by the delayed reclaim
callback instead of initializing the complete PhoneWindowManager policy.
This avoids activating unrelated camera, role-management, device-key, and
Lineage settings subsystems during the unit test.

The ActivityManager call is mocked, so the tests do not perform a real process
reclaim.

Local validation was completed with the lineage_raphael userdebug target and
a physical Xiaomi Mi 9T Pro / Redmi K20 Pro (raphael) running Android 16 /
crDroid 12.11.

Executed tests:

WmTests:com.android.server.policy.PhoneWindowManagerTests#screenOnMemoryReclaimDisabledAtExecution_doesNotReleaseMemory

WmTests:com.android.server.policy.PhoneWindowManagerTests#screenOnMemoryReclaimEnabledAtExecution_releasesMemory

Result:

  • WmTests compilation: passed
  • Instrumentation installation: passed
  • Tests selected: 2
  • Passed: 2
  • Failed: 0
  • Disabled at execution: passed
  • Enabled at execution: passed

The local crDroid WmTests baseline required two unrelated compatibility
adjustments in separate test files. Those adjustments were used only in the
local validation harness and are not included in this pull request.

Device context

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

Build: crDroid Android 16 v12.11-20260623

Validated pull request head:

60a3492aa2756fdad29b5a502b6cfa8acfff9d73

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.
  • WmTests source compilation: completed.
  • Targeted unit test execution: completed, 2 passed / 0 failed.
  • Pull request test isolation update: completed.
  • Device validation with a ROM build containing this change: 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