/// Processes a `request` for information from an HFP procedure.
Processes a `request` for information from an HFP procedure.
Processes a ` request ` for information from an HFP procedure .
async fn procedure_request(&mut self, request: InformationRequest) {
        let marker = (&request).into();
        match request {
            InformationRequest::GetAgFeatures { response } => {
                let features = (&self._local_config).into();
                // Update the procedure with the retrieved AG update.
                self.connection.receive_ag_request(marker, response(features)).await;
            }
            InformationRequest::GetSubscriberNumberInformation { response } => {
                let result = if let Some(handler) = &mut self.handler {
                    handler.subscriber_number_information().await.ok().unwrap_or_else(Vec::new)
                } else {
                    vec![]
                };
                self.connection.receive_ag_request(marker, response(result)).await;
            }
            InformationRequest::GetAgIndicatorStatus { response } => {
                let call_ind = self.calls.indicators();
                let status = Indicators {
                    service: self.network.service_available.unwrap_or(false),
                    call: call_ind.call,
                    callsetup: call_ind.callsetup,
                    callheld: call_ind.callheld,
                    signal: self.network.signal_strength.map(|ss| ss as u8).unwrap_or(0),
                    roam: self.network.roaming.unwrap_or(false),
                    battchg: 5, // TODO: Retrieve battery status from Fuchsia power service.
                };
                // Update the procedure with the retrieved AG update.
                self.connection.receive_ag_request(marker, response(status)).await;
            }
            InformationRequest::GetNetworkOperatorName { response } => {
                let format = self.connection.network_operator_name_format();
                let name = match &self.handler {
                    Some(h) => {
                        let result = h.query_operator().await;
                        if let Err(err) = &result {
                            warn!(
                                "Got error attempting to retrieve operator name from AG: {:}",
                                err
                            );
                        };
                        result.ok().flatten()
                    }
                    None => None,
                };
                let name_option = match (name, format) {
                    (Some(n), Some(_)) => Some(n),
                    _ => None, // The format must be set before getting the network name.
                };
                // Update the procedure with the result of retrieving the AG network name.
                self.connection.receive_ag_request(marker, response(name_option)).await;
            }
            InformationRequest::SendDtmf { code, response } => {
                self.calls.send_dtmf_code(code).await;
                self.connection.receive_ag_request(marker, response()).await;
            }
            InformationRequest::SetNrec { enable, response } => {
                let result = if let Some(handler) = &mut self.handler {
                    if let Ok(Ok(())) = handler.set_nrec_mode(enable).await {
                        Ok(())
                    } else {
                        Err(())
                    }
                } else {
                    Err(())
                };
                self.connection.receive_ag_request(marker, response(result)).await;
            }
            InformationRequest::SpeakerVolumeSynchronization { level, response } => {
                self.gain_control.report_speaker_gain(level);
                self.connection.receive_ag_request(marker, response()).await;
            }
            InformationRequest::MicrophoneVolumeSynchronization { level, response } => {
                self.gain_control.report_microphone_gain(level);
                self.connection.receive_ag_request(marker, response()).await;
            }
            InformationRequest::QueryCurrentCalls { response } => {
                let result = self.calls.current_calls();
                self.connection.receive_ag_request(marker, response(result)).await;
            }
        };
    }
async fn procedure_request ( & mut self , request : InformationRequest ) { let marker = ( & request ) . into ( ) ; match request { InformationRequest :: GetAgFeatures { response } => { let features = ( & self . _local_config ) . into ( ) ; // Update the procedure with the retrieved AG update. self . connection . receive_ag_request ( marker , response ( features ) ) . await ; } InformationRequest :: GetSubscriberNumberInformation { response } => { let result = if let Some ( handler ) = & mut self . handler { handler . subscriber_number_information ( ) . await . ok ( ) . unwrap_or_else ( Vec :: new ) } else { vec ! [ ] } ; self . connection . receive_ag_request ( marker , response ( result ) ) . await ; } InformationRequest :: GetAgIndicatorStatus { response } => { let call_ind = self . calls . indicators ( ) ; let status = Indicators { service : self . network . service_available . unwrap_or ( false ) , call : call_ind . call , callsetup : call_ind . callsetup , callheld : call_ind . callheld , signal : self . network . signal_strength . map ( | ss | ss as u8 ) . unwrap_or ( 0 ) , roam : self . network . roaming . unwrap_or ( false ) , battchg : 5 , // TODO: Retrieve battery status from Fuchsia power service. } ; // Update the procedure with the retrieved AG update. self . connection . receive_ag_request ( marker , response ( status ) ) . await ; } InformationRequest :: GetNetworkOperatorName { response } => { let format = self . connection . network_operator_name_format ( ) ; let name = match & self . handler { Some ( h ) => { let result = h . query_operator ( ) . await ; if let Err ( err ) = & result { warn ! ( " " err ) ; } ; result . ok ( ) . flatten ( ) } None => None , } ; let name_option = match ( name , format ) { ( Some ( n ) , Some ( _ ) ) => Some ( n ) , _ => None , // The format must be set before getting the network name. } ; // Update the procedure with the result of retrieving the AG network name. self . connection . receive_ag_request ( marker , response ( name_option ) ) . await ; } InformationRequest :: SendDtmf { code , response } => { self . calls . send_dtmf_code ( code ) . await ; self . connection . receive_ag_request ( marker , response ( ) ) . await ; } InformationRequest :: SetNrec { enable , response } => { let result = if let Some ( handler ) = & mut self . handler { if let Ok ( Ok ( ( ) ) ) = handler . set_nrec_mode ( enable ) . await { Ok ( ( ) ) } else { Err ( ( ) ) } } else { Err ( ( ) ) } ; self . connection . receive_ag_request ( marker , response ( result ) ) . await ; } InformationRequest :: SpeakerVolumeSynchronization { level , response } => { self . gain_control . report_speaker_gain ( level ) ; self . connection . receive_ag_request ( marker , response ( ) ) . await ; } InformationRequest :: MicrophoneVolumeSynchronization { level , response } => { self . gain_control . report_microphone_gain ( level ) ; self . connection . receive_ag_request ( marker , response ( ) ) . await ; } InformationRequest :: QueryCurrentCalls { response } => { let result = self . calls . current_calls ( ) ; self . connection . receive_ag_request ( marker , response ( result ) ) . await ; } } ; }
Processes a `request` for information from an HFP procedure.
Processes a ` request ` for information from an HFP procedure .
&mut self
request
InformationRequest