async fn handle_volume_request(
    audio: Option<SettingResponse>,
    last_media_user_volume: Arc<Mutex<Option<f32>>>,
    volume_button_event: Arc<Mutex<i8>>,
    common_earcons_params: CommonEarconsParams,
) {
    if let Some(SettingResponse::Audio(audio_info)) = audio {
        let changed_streams = match audio_info.changed_streams {
            Some(streams) => streams,
            None => Vec::new(),
        };
        fx_log_info!("[earcons_agent] changed streams: {:?}", changed_streams);

        let new_media_user_volume: Option<f32> =
            match changed_streams.iter().find(|&&x| x.stream_type == AudioStreamType::Media) {
                Some(stream) => Some(stream.user_volume_level),
                None => None,
            };
        let volume_up_max_pressed =
            new_media_user_volume == Some(MAX_VOLUME) && *volume_button_event.lock().await == 1;
        let stream_is_media =
            changed_streams.iter().find(|&&x| x.stream_type == AudioStreamType::Media).is_some();
        let mut last_media_user_volume_lock = last_media_user_volume.lock().await;

        // Logging for debugging volume changes
        fx_log_info!("[earcons_agent] Is media stream: {}", stream_is_media);
        fx_log_info!("[earcons_agent] Volume up pressed while max: {}", volume_up_max_pressed);
        fx_log_info!("[earcons_agent] New media user volume: {:?}", new_media_user_volume);
        fx_log_info!("[earcons_agent] Last media user volume: {:?}", *last_media_user_volume_lock);

        if ((*last_media_user_volume_lock != new_media_user_volume) || volume_up_max_pressed)
            && stream_is_media
        {
            if *last_media_user_volume_lock != None {
                // On restore, the last media user volume is set for the first time, and registers
                // as different from the last seen volume, because it is initially None. Don't play
                // the earcons sound on that set.
                fasync::spawn(async move {
                    play_media_volume_sound(new_media_user_volume, common_earcons_params).await;
                });
            }
            *last_media_user_volume_lock = new_media_user_volume;
        }
    }
}
/// Handle the volume state acquired from the switchboard, and determine whether
/// the sounds should be played.
Handle the volume state acquired from the switchboard, and determine whether
the sounds should be played.
Handle the volume state acquired from the switchboard and determine whether the sounds should be played .
async fn handle_volume_request(
    audio: Option<SettingResponse>,
    last_media_user_volume: Arc<Mutex<Option<f32>>>,
    volume_button_event: Arc<Mutex<i8>>,
    common_earcons_params: CommonEarconsParams,
) {
    if let Some(SettingResponse::Audio(audio_info)) = audio {
        let changed_streams = match audio_info.changed_streams {
            Some(streams) => streams,
            None => Vec::new(),
        };
        fx_log_info!("[earcons_agent] changed streams: {:?}", changed_streams);
        let new_media_user_volume: Option<f32> =
            match changed_streams.iter().find(|&&x| x.stream_type == AudioStreamType::Media) {
                Some(stream) => Some(stream.user_volume_level),
                None => None,
            };
        let volume_up_max_pressed =
            new_media_user_volume == Some(MAX_VOLUME) && *volume_button_event.lock().await == 1;
        let stream_is_media =
            changed_streams.iter().find(|&&x| x.stream_type == AudioStreamType::Media).is_some();
        let mut last_media_user_volume_lock = last_media_user_volume.lock().await;
        // Logging for debugging volume changes
        fx_log_info!("[earcons_agent] Is media stream: {}", stream_is_media);
        fx_log_info!("[earcons_agent] Volume up pressed while max: {}", volume_up_max_pressed);
        fx_log_info!("[earcons_agent] New media user volume: {:?}", new_media_user_volume);
        fx_log_info!("[earcons_agent] Last media user volume: {:?}", *last_media_user_volume_lock);
        if ((*last_media_user_volume_lock != new_media_user_volume) || volume_up_max_pressed)
            && stream_is_media
        {
            if *last_media_user_volume_lock != None {
                // On restore, the last media user volume is set for the first time, and registers
                // as different from the last seen volume, because it is initially None. Don't play
                // the earcons sound on that set.
                fasync::spawn(async move {
                    play_media_volume_sound(new_media_user_volume, common_earcons_params).await;
                });
            }
            *last_media_user_volume_lock = new_media_user_volume;
        }
    }
}
async fn handle_volume_request ( audio : Option < SettingResponse > , last_media_user_volume : Arc < Mutex < Option < f32 > > > , volume_button_event : Arc < Mutex < i8 > > , common_earcons_params : CommonEarconsParams , ) { if let Some ( SettingResponse :: Audio ( audio_info ) ) = audio { let changed_streams = match audio_info . changed_streams { Some ( streams ) => streams , None => Vec :: new ( ) , } ; fx_log_info ! ( " " changed_streams ) ; let new_media_user_volume : Option < f32 > = match changed_streams . iter ( ) . find ( | & & x | x . stream_type == AudioStreamType :: Media ) { Some ( stream ) => Some ( stream . user_volume_level ) , None => None , } ; let volume_up_max_pressed = new_media_user_volume == Some ( MAX_VOLUME ) && * volume_button_event . lock ( ) . await == 1 ; let stream_is_media = changed_streams . iter ( ) . find ( | & & x | x . stream_type == AudioStreamType :: Media ) . is_some ( ) ; let mut last_media_user_volume_lock = last_media_user_volume . lock ( ) . await ; // Logging for debugging volume changes fx_log_info ! ( " " stream_is_media ) ; fx_log_info ! ( " " volume_up_max_pressed ) ; fx_log_info ! ( " " new_media_user_volume ) ; fx_log_info ! ( " " last_media_user_volume_lock ) ; if ( ( * last_media_user_volume_lock != new_media_user_volume ) || volume_up_max_pressed ) && stream_is_media { if * last_media_user_volume_lock != None { // On restore, the last media user volume is set for the first time, and registers // as different from the last seen volume, because it is initially None. Don't play // the earcons sound on that set. fasync :: spawn ( async move { play_media_volume_sound ( new_media_user_volume , common_earcons_params ) . await ; } ) ; } * last_media_user_volume_lock = new_media_user_volume ; } } }
Handle the volume state acquired from the switchboard, and determine whether
the sounds should be played.
Handle the volume state acquired from the switchboard and determine whether the sounds should be played .
audio
Option<SettingResponse>
last_media_user_volume
Arc<Mutex<Option<f32>>>
volume_button_event
Arc<Mutex<i8>>
common_earcons_params
CommonEarconsParams
audio
Option<SettingResponse>
last_media_user_volume
Arc<Mutex<Option<f32>>>
volume_button_event
Arc<Mutex<i8>>
common_earcons_params
CommonEarconsParams