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>()?;

    // 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(e) => {
                return Err(Error::new(SwitchboardError::ExternalFailure {
                    setting_type: SettingType::Audio,
                    dependency: "UseageReporterProxy".to_string(),
                    request: "watch".to_string(),
                    error: Error::new(e),
                }));
            }
        }
    }
    Ok(())
}
// 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.
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.
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>()?;
    // 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(e) => {
                return Err(Error::new(SwitchboardError::ExternalFailure {
                    setting_type: SettingType::Audio,
                    dependency: "UseageReporterProxy".to_string(),
                    request: "watch".to_string(),
                    error: Error::new(e),
                }));
            }
        }
    }
    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 > ( ) ? ; // 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 ( e ) => { return Err ( Error :: new ( SwitchboardError :: ExternalFailure { setting_type : SettingType :: Audio , dependency : " " . to_string ( ) , request : " " . to_string ( ) , error : Error :: new ( e ) , } ) ) ; } } } Ok ( ( ) ) }
We should not play earcons over a higher priority stream.
We should not play earcons over a higher priority stream .
service_context_handle
&ServiceContextHandle
priority_stream_playing
Arc<AtomicBool>
service_context_handle
&ServiceContextHandle
priority_stream_playing
Arc<AtomicBool>