Engineering

Engineering Selective Audio Damping for Deep Work Sessions

A technical breakdown of how we implemented smart audio focus and ducking in Mindful Assistant to protect concentration.

Amin Shekh · November 17, 2026
Share

When we began developing Mindful Assistant, our goal was to build a tool that didn't just track time, but actively protected the user's environment. One of the most significant leaks in personal productivity isn't just visual—it is auditory. A sudden notification chime or an auto-playing video in another tab can shatter the state of flow, requiring up to twenty minutes to regain. However, a total mute is often too aggressive; users still want their deep-work soundscapes or binaural beats to play. The challenge was technical: how do we programmatically allow 'good' sounds while suppressing 'disruptive' sounds on a platform like Android where audio streams often compete for priority?

The Hierarchy of Audio Focus

Android handles audio through a system of 'Audio Focus.' When an app wants to play sound, it must request focus from the AudioManager. If granted, other apps might be 'ducked' (volume lowered) or paused. In a standard environment, every app is treated with roughly equal importance. If you are listening to a podcast and a navigation app speaks a direction, the podcast volume drops.

For Mindful Assistant, we needed to invert this relationship. We didn't want our app to be just another participant in the audio ecosystem; we wanted it to act as a selective gatekeeper. To do this, we had to leverage the AudioFocusRequest API combined with a custom OnAudioFocusChangeListener. Our engineering goal was to create a 'Focus Shield' that dynamically adjusted how the device responded to external audio interruptions based on the user's current session state.

Implementing the Selective Damping Logic

The core of the damping system relies on identifying the type of audio attempting to break through. Android categorizes audio using AudioAttributes. In our implementation, we distinguish between three primary tiers of audio importance:

  1. 1.Critical Alarms: System-level alarms or incoming calls that must break through for safety or urgency.
  2. 2.Focus Soundscapes: The user’s chosen background noise (white noise, rain, or low-fi beats).
  3. 3.Transient Distractions: Social media pings, email alerts, and incidental UI sounds.

During a focus session, Mindful Assistant requests a permanent AUDIOFOCUS_GAIN. By holding this focus, we can listen for onAudioFocusChange events triggered by other apps. When another app requests focus, the system sends us a hint. If the incoming request is AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK, we have the programmatic choice to ignore the ducking request or strictly enforce it.

We implemented a custom FocusManager class that handles these transitions. When the user starts a session, the app assumes a high-priority state. If a secondary app attempts to play a notification sound, our manager intercepts the callback and maintains the primary stream’s volume, effectively 'masking' the interruption if the user has enabled the "Deep Damping" toggle.

The Challenge of Persistent Soundscapes

A common issue in productivity apps is that the 'focus music' itself can become a distraction if it stops abruptly. We applied similar logic here as we did in Designing Interstitials: Reminders Without Breaking Focus. Rather than a hard start/stop for audio, we use a gradual gain ramp.

When a session begins, the MediaPlayer or ExoPlayer instance doesn't jump to 100% volume. Instead, we use a ValueAnimator to scale the volume from 0.0f to the user’s preferred level over 5 seconds. This technical choice prevents the 'startle response' that can occur when a soundscape suddenly fills a silent room.

Comparison of Audio Handling Strategies

StrategyMechanismUser ImpactUse Case
Standard DuckingSystem lowers background audio by 80%.Notification is clearly heard; flow is interrupted.General daily use.
Hard MutesetStreamMute or DND mode.Total silence; risk of missing emergency calls.Sleep or high-stakes meetings.
Selective DampingCustom AudioFocus interceptor.Background audio stays constant; notification is suppressed or faint.Deep work / Flow state.
Ramped GainValueAnimator on volume float.Smooth transition into focus environment.Starting a timed session.

Managing Haptic Interference

Audio is only half the battle. As we learned while Designing Granular Haptic Feedback for Prayer Notifications, physical vibration can be just as disruptive as sound. In Mindful Assistant, when the selective audio damping is active, we also request a temporary suppression of the Vibrator service for non-essential packages.

On Android 8.0 (API 26) and above, this is managed through NotificationChannels. While an app cannot globally disable other apps' vibrations without root access, Mindful Assistant encourages users to utilize the 'Work Profile' or 'Do Not Disturb' access via our onboarding flow. Technically, we check for NotificationManager.INTERRUPTION_FILTER_PRIORITY and prompt the user to allow the app to manage this state. Once granted, our FocusManager toggles the system filter to PRIORITY mode automatically when the focus timer starts, and reverts it to ALL when the session concludes.

The Transition State: Moving from Work to Rest

One of the most complex parts of the engineering was handling the end of a session. If a user has been in a 'Damped' state for 90 minutes, returning to a barrage of delayed notifications is overwhelming. We implemented a 'Cool Down' phase.

Technically, this involves:

  1. 1.Fading out the soundscape: A 10-second linear fade-out of the white noise.
  2. 2.Delayed Filter Release: We wait 30 seconds after the timer hits zero before releasing the NotificationManager interruption filter. This gives the user time to physically move away from their desk or prepare for the influx of pings.
  3. 3.Audio Focus Abandonment: We call abandonAudioFocusRequest() only after the UI transition is complete, ensuring a clean hand-off back to the system's default audio handler.

Worked Example: The Interrupted Developer

Imagine a developer, Sarah, is using Mindful Assistant while coding. She has a 'Rain' soundscape active.

  • Minute 12: An email arrives. Usually, the Android system would lower the volume of the rain to play the 'Ping' sound.
  • The Logic: Mindful Assistant’s OnAudioFocusChangeListener receives AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK.
  • The Action: Because Sarah is in a 'Deep Work' session, the app ignores the signal to lower its own volume. The system 'ping' happens, but it is masked by the consistent volume of the rain. Sarah’s internal rhythm remains undisturbed.
  • Minute 45: Sarah’s phone receives an emergency call from a whitelisted contact.
  • The Logic: The system sends AUDIOFOCUS_LOSS.
  • The Action: Mindful Assistant recognizes this as a permanent/high-priority loss. It immediately initiates a 1-second fade-out and yields focus to the Phone app, allowing the ringtone to be heard.

Lessons in Performance and Battery

Maintaining a constant audio stream and monitoring focus changes requires careful management of the WakeLock. To prevent the Android system from killing the process (and thus stopping the damping), we run the FocusManager within a Foreground Service. As discussed in our article on When to Use Android Foreground Services for Better Reliability, this ensures the focus protection stays active even if the user switches to a code editor or IDE. We optimize battery by using LocalBroadcastManager to update the UI only when the app is in the foreground, reducing unnecessary CPU cycles during the long stretches of a focus session.

What to do next

  1. 1.Audit your notification channels: Go to your Android settings and identify which apps have 'Bypass Do Not Disturb' toggled on. These are the only ones that will break through a Mindful Assistant session.
  2. 2.Test your soundscapes: Open Mindful Assistant and start a 5-minute trial session with 'Selective Damping' enabled. Have a friend send you a message to see how the masking feels in practice.
  3. 3.Evaluate your ramp time: If you find the start of a session jarring, go to Settings > Audio and increase the 'Volume Fade-In' duration to 10 seconds for a gentler transition into flow.
#android#engineering#ux design#productivity

One email per launch. No spam, unsubscribe any time.