/// Determine when the background usage is being played on.
///
/// We should not play earcons over a higher priority stream. In order to figure out whether there
/// is a more high-priority stream playing, we watch the BACKGROUND audio usage. If it is muted or
/// ducked, we should not play the earcons.
// TODO (fxb/44381): Remove this when it is no longer necessary to check the background usage.
Determine when the background usage is being played on.
We should not play earcons over a higher priority stream. In order to figure out whether there
is a more high-priority stream playing, we watch the BACKGROUND audio usage. If it is muted or
ducked, we should not play the earcons.
TODO (fxb/44381): Remove this when it is no longer necessary to check the background usage.
Determine when the background usage is being played on . We should not play earcons over a higher priority stream . In order to figure out whether there is a more high - priority stream playing we watch the BACKGROUND audio usage . If it is muted or ducked we should not play the earcons . TODO ( fxb / 44381 ) : Remove this when it is no longer necessary to check the background usage .
async fn watch_background_usage(
    service_context_handle: &ServiceContextHandle,
    priority_stream_playing: Arc<AtomicBool>,
) -> Result<(), Error> {
    let usage_reporter_proxy =
        service_context_handle.lock().await.connect::<UsageReporterMarker>().await?;
    // Create channel for usage reporter watch results.
    let (watcher_client, mut watcher_requests) = create_request_stream()?;
    // Watch for changes in usage.
    usage_reporter_proxy.watch(&mut RenderUsage(AudioRenderUsage::Background), watcher_client)?;
    // Handle changes in the usage, update state.
    while let Some(event) = watcher_requests.next().await {
        match event {
            Ok(OnStateChanged { usage: _usage, state, responder }) => {
                responder.send()?;
                priority_stream_playing.store(
                    match state {
                        Muted(_) | Ducked(_) => true,
                        _ => false,
                    },
                    Ordering::SeqCst,
                );
            }
            Err(_) => {
                return Err(Error::new(SwitchboardError::ExternalFailure {
                    setting_type: SettingType::Audio,
                    dependency: "UsageReporterProxy".to_string(),
                    request: "watch".to_string(),
                }));
            }
        }
    }
    Ok(())
}
async fn watch_background_usage ( service_context_handle : & ServiceContextHandle , priority_stream_playing : Arc < AtomicBool > , ) -> Result < ( ) , Error > { let usage_reporter_proxy = service_context_handle . lock ( ) . await . connect :: < UsageReporterMarker > ( ) . await ? ; // Create channel for usage reporter watch results. let ( watcher_client , mut watcher_requests ) = create_request_stream ( ) ? ; // Watch for changes in usage. usage_reporter_proxy . watch ( & mut RenderUsage ( AudioRenderUsage :: Background ) , watcher_client ) ? ; // Handle changes in the usage, update state. while let Some ( event ) = watcher_requests . next ( ) . await { match event { Ok ( OnStateChanged { usage : _usage , state , responder } ) => { responder . send ( ) ? ; priority_stream_playing . store ( match state { Muted ( _ ) | Ducked ( _ ) => true , _ => false , } , Ordering :: SeqCst , ) ; } Err ( _ ) => { return Err ( Error :: new ( SwitchboardError :: ExternalFailure { setting_type : SettingType :: Audio , dependency : " " . to_string ( ) , request : " " . to_string ( ) , } ) ) ; } } } Ok ( ( ) ) }
Determine when the background usage is being played on.
Determine when the background usage is being played on .
service_context_handle
&ServiceContextHandle
priority_stream_playing
Arc<AtomicBool>