Manage audio resources during suspend

To ensure system stability and the ability to enter low-power states like Suspend-to-RAM (S2R) or Suspend-to-Disk (S2D), it's crucial that audio resources are properly managed during power transitions.

Apps might not always release audio input or output streams when the system initiates a suspend. Active audio streams can prevent the audio subsystem and underlying hardware from becoming idle, which can block the system-on-a-chip (SoC) from entering deep sleep. This results in failed suspend attempts and increased power consumption.

OEMs must implement a robust fallback mechanism within their Audio hardware abstraction layer (HAL) implementation to handle active audio streams during suspend transitions. This is essential for platform stability, regardless of app behavior.

Apps should manage audio resources correctly, but the system can't rely on this for fundamental power state transitions. The Audio HAL is the appropriate layer to enforce resource deactivation to ensure the system's ability to enter suspend states. We recommend this approach for robust power management.

Implement power management

To implement robust power management in Audio HAL, follow these steps:

  1. Detect system power state changes, particularly the transition to suspend.

  2. When the system is preparing to suspend, intervene if any audio streams (both input and output) are still active:

    • Release hardware output streams and discard incoming data from audio framework.
    • Release hardware input streams and send silent audio to the framework.

    This HAL-level action ensures that the audio hardware can become idle, letting the system to successfully suspend, even if an app hasn't released its audio resources.

  3. When the system resumes from suspend, restore the audio subsystem to its active state. This involves unmuting any previously muted output streams and reactivating input streams, letting apps continue audio playback and capture.

Impact on apps

The HAL-level management of audio resources during suspend impacts apps in the following ways:

  • Transparent suspend: For apps using a microphone, the system suspend (entering S2D or S2R) is transparent.
  • Muted audio during transition: After the suspend transition is initiated, active streams are muted at the HAL. The app continues to run, but it receives only muted audio during suspend.
  • Automatic resume: Upon system resume, the app automatically starts receiving or sending real audio data again without requiring any resource re-acquisition or recovery actions.