/// Adds a transform to the given target.
// TODO(fxbug.dev/70856): perform validations and return errors for invalid inputs, such as
// a max being lower than a min.
Adds a transform to the given target.
TODO(fxbug.dev/70856): perform validations and return errors for invalid inputs, such as
a max being lower than a min.
Adds a transform to the given target . TODO ( fxbug . dev / 70856 ) : perform validations and return errors for invalid inputs such as a max being lower than a min .
async fn add_policy_transform(
        &mut self,
        target: PropertyTarget,
        transform: Transform,
    ) -> policy_base::response::Response {
        // Request the latest audio info.
        let audio_info =
            self.fetch_audio_info().await.map_err(|_| policy_base::response::Error::Unexpected)?;
        // Calculate the current external volume level.
        let stream = audio_info
            .streams
            .iter()
            .find(|stream| stream.stream_type == target)
            .ok_or(policy_base::response::Error::Unexpected)?;
        let external_volume = self.calculate_external_volume(target, stream.user_volume_level);
        // Add the transform the policy state.
        // TODO(fxbug.dev/60925): once policy targets are configurable, test this error case.
        let policy_id = self.state.add_transform(target, transform).ok_or_else(|| {
            PolicyError::InvalidArgument(
                PolicyType::Audio,
                "target".into(),
                format!("{:?}", target).into(),
            )
        })?;
        // Persist the policy state.
        self.client_proxy.write_policy(self.state.clone().into(), false).await?;
        // Put the transform into effect, updating internal/external volume levels as needed.
        self.apply_policy_transforms(target, audio_info, external_volume).await?;
        Ok(policy_base::response::Payload::Audio(Response::Policy(policy_id)))
    }
async fn add_policy_transform ( & mut self , target : PropertyTarget , transform : Transform , ) -> policy_base :: response :: Response { // Request the latest audio info. let audio_info = self . fetch_audio_info ( ) . await . map_err ( | _ | policy_base :: response :: Error :: Unexpected ) ? ; // Calculate the current external volume level. let stream = audio_info . streams . iter ( ) . find ( | stream | stream . stream_type == target ) . ok_or ( policy_base :: response :: Error :: Unexpected ) ? ; let external_volume = self . calculate_external_volume ( target , stream . user_volume_level ) ; // Add the transform the policy state. // TODO(fxbug.dev/60925): once policy targets are configurable, test this error case. let policy_id = self . state . add_transform ( target , transform ) . ok_or_else ( | | { PolicyError :: InvalidArgument ( PolicyType :: Audio , " " . into ( ) , format ! ( " " target ) . into ( ) , ) } ) ? ; // Persist the policy state. self . client_proxy . write_policy ( self . state . clone ( ) . into ( ) , false ) . await ? ; // Put the transform into effect, updating internal/external volume levels as needed. self . apply_policy_transforms ( target , audio_info , external_volume ) . await ? ; Ok ( policy_base :: response :: Payload :: Audio ( Response :: Policy ( policy_id ) ) ) }
Adds a transform to the given target.
Adds a transform to the given target .
&mut self
target
PropertyTarget
transform
Transform