AOSP Framework & Internals
6 min read

PowerManagerService (PMS)

Explore how Android violently manages sleep states and how the framework coordinates with the kernel to keep the screen on.

Mobile processors devour battery capacity at an alarming rate. Android solves this hardware reality with a ruthless philosophy. The CPU must be completely suspended as often as physically possible. The PowerManagerService (PMS) exists to enforce this rule. It acts as the absolute authority on when the device is awake, when the screen renders, and when the CPU is allowed to sleep.

Why Background Tasks Break When the Screen Darkens

Smartphones do not behave like desktop computers. When the screen turns off, the Linux kernel immediately attempts to suspend the CPU to halt power consumption. A sudden sleep state would instantly drop the network connection if an application is downloading a large file. The system needs a way for critical tasks to veto the kernel sleep command.

This veto power is called a Wake Lock. A Wake Lock is a formal request from an application to the PowerManagerService to keep specific hardware components running. The most common type is a partial wake lock. This specific lock allows the screen to turn off but forces the CPU to remain active.

When an application requires a wake lock, it makes a Binder call to the PowerManagerService. PMS receives this request and adds the application to its internal registry of active locks. It then executes a Java Native Interface (JNI) call into the Android framework native layer. This native code writes directly to a specific Linux kernel node at /sys/power/wake_lock. The kernel reads this active lock and physically blocks the CPU hardware from entering the low-power suspend state.

To understand why user-space applications cannot directly control power hardware, we can visualize the request path. The following sequence diagram shows how the request travels from the application down to the kernel. Pay attention to how PMS acts as the strict gatekeeper between the application layer and the hardware.

The application acquires the lock, completes its task, and releases the lock using the same path. If the application crashes or fails to release the lock, the CPU remains awake and drains the battery entirely. This single mechanism is responsible for the majority of battery drain issues on Android devices.

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock lock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyApp::Download");

lock.acquire(10 * 60 * 1000L); 
// Execute background network download
lock.release();

Common Mistake: Forgetting to release a wake lock or failing to use a timeout in acquire() will keep the CPU awake indefinitely. Always use a timeout to protect against unexpected application crashes.

The Screen Wake Sequence

Waking up a device requires more than just sending voltage to the display panel. The operating system must coordinate the transition from a deep sleep state back to an active rendering state. Visual corruption or a frozen frame appears if the display turns on before the graphics pipeline is ready.

The wake sequence is a heavily orchestrated dance across multiple system services. It begins with a hardware interrupt from the physical power button. The InputManagerService catches this interrupt and forwards the event to the PhoneWindowManager. This window policy engine determines that the button press means the device should wake up. It then sends a command to the PowerManagerService to initiate the sequence.

PMS transitions its internal state to awake and commands the Display Hardware Abstraction Layer (HAL) to power on the OLED panel. Simultaneously, it notifies the ActivityManagerService (AMS) that the screen is active. AMS responds by moving the top-most Activity into the resumed state. The application then starts rendering user interface frames.

We can map this hardware interrupt through the framework to the display and UI components. This flowchart clarifies why the screen sometimes feels delayed when waking up under heavy load. Notice how PMS sits at the center of the broadcast.

The central role of PMS ensures that no single component turns on the screen independently. By coordinating the Display HAL and the ActivityManagerService, PMS guarantees that the screen only illuminates when a valid UI frame is ready to be drawn.

To trace exactly what components are currently holding wake locks or influencing power states, platform engineers rely on a specific diagnostic command. This command dumps the internal state of the PowerManagerService directly to the terminal.

adb shell dumpsys power

Warning: Engineers often assume a sleeping screen means the CPU is also asleep. Always check the dumpsys power output, as a rogue background app can hold a wake lock and keep the CPU running indefinitely while the screen is completely black.

Idle Timers and the Teardown Sequence

A device cannot rely on the user to manually turn off the screen every time they finish a task. The system must autonomously determine when it is safe to return to a sleep state to conserve power. This requires tracking user interaction and safely winding down active components.

The PowerManagerService constantly runs internal timers based on the user's screen timeout settings. Every time the user touches the screen, the InputManagerService resets this timer. When interaction stops, the timer counts down. If it reaches zero, PMS begins the sleep sequence. It does not simply cut power instantly.

Before turning off the screen entirely, PMS queries the DreamManagerService to check for a configured screen saver. If a daydream should run while docked, PMS hands control over to that service. If not, PMS dims the screen brightness as a visual warning. If no input interrupts the dimming phase, PMS issues the suspend command to the Linux kernel. The kernel then parks the CPU cores and freezes all non-critical processes.

This automated lifecycle ensures the device always defaults back to its lowest power state. The PowerManagerService acts as the final judge of idle time. It balances the user's need for a responsive device with the physical limits of battery chemistry.

PowerManagerService operates as the heartbeat monitor of the Android system. It bridges hardware interrupts, coordinates UI rendering states, and dictates when the kernel is allowed to sleep. The entire architecture is built around the assumption that the CPU must be suspended as aggressively as possible.

Managing the CPU and screen handles immediate physical state, but applications still need to run periodic background tasks without being killed. That requirement introduces a completely different mechanism for scheduling work over time.