Cached apps freezer

Android 11 QPR3 or higher supports the cached apps freezer. This feature stops execution for cached processes and reduces resource usage by misbehaving apps that might attempt to operate while cached. The framework freezes cached apps by migrating their processes into a frozen cgroup; this reduces active and idle CPU consumption in presence of active cached apps. The app freezer can be enabled using a system configuration flag or a developer option.

Implement the apps freezer

The cached apps freezer leverages the kernel cgroup v2 freezer. Devices shipping with a compatible kernel can (optionally) enable it. To do so, enable the developer option "Suspend execution for cached apps" or set the device config flag activity_manager_native_boot use_freezer to true. For example:

adb shell device_config put activity_manager_native_boot use_freezer true && adb reboot

The freezer is disabled when the flag use_freezer is set to false or the developer option is disabled. You can toggle this setting by changing a device configuration in a software release or update.

The apps freezer doesn't expose official APIs (and doesn't have a reference implementation client), but does use the hidden system APIs setProcessFrozen and enableFreezer. For details on these APIs, refer to ActivityManager's and the ActivityManagerService API. Developers can also refer to the client code in ActivityManager for experiments.

Handle custom features

Typically, processes aren't expected to do any work when cached, but some apps might have custom features supported by processes that are expected to run while cached. When the apps freezer is enabled on a device running such an app, the cached processes are frozen and might prevent custom features from working.

As a workaround, if an app has a process that needs to perform activities while cached, change the process status to non-cached (such as Bound ForeGround Service (BFGS) or foreground) before the process needs to do any work to allow the app to remain active.

Test the apps freezer

To verify the app freezer is working as intended, use the following resources:

  • Check for a list of frozen processes using the adb shell dumpsys activity command and grep the Frozen keyword.

  • Check for the presence of the /sys/fs/cgroup/uid_0/cgroup.freeze file.

  • View logcat, which shows frozen and unfrozen entries each time a process migrates in or out of the freezer. For example:

    adb logcat | grep -i "\(freezing\|froze\)"