#ifndef CHROMEOS_ASH_COMPONENTS_DBUS_AUDIO_FAKE_CRAS_AUDIO_CLIENT_H_
#define CHROMEOS_ASH_COMPONENTS_DBUS_AUDIO_FAKE_CRAS_AUDIO_CLIENT_H_
#include <stdint.h>
#include <vector>
#include "base/component_export.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "chromeos/ash/components/dbus/audio/cras_audio_client.h"
#include "chromeos/ash/components/dbus/audio/voice_isolation_ui_appearance.h"
namespace ash {
class COMPONENT_EXPORT(DBUS_AUDIO) FakeCrasAudioClient
: public CrasAudioClient {
public:
using ClientTypeToInputStreamCount = base::flat_map<std::string, uint32_t>;
FakeCrasAudioClient();
FakeCrasAudioClient(const FakeCrasAudioClient&) = delete;
FakeCrasAudioClient& operator=(const FakeCrasAudioClient&) = delete;
~FakeCrasAudioClient() override;
static FakeCrasAudioClient* Get();
void SetVoiceIsolationUIAppearance(VoiceIsolationUIAppearance appearance);
bool GetVoiceIsolationUIEnabled();
uint32_t GetVoiceIsolationUIPreferredEffect();
void SetNoiseCancellationSupported(bool noise_cancellation_supported);
uint32_t GetNoiseCancellationEnabledCount();
void SetStyleTransferSupported(bool style_transfer_supported);
bool GetStyleTransferEnabled();
void SetHfpMicSrSupported(bool hfp_mic_sr_supported);
uint32_t GetHfpMicSrEnabled();
void SetSpatialAudioSupported(bool spatial_audio_supported);
void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override;
bool HasObserver(const Observer* observer) const override;
void GetVolumeState(
chromeos::DBusMethodCallback<VolumeState> callback) override;
void GetDefaultOutputBufferSize(
chromeos::DBusMethodCallback<int> callback) override;
void GetSystemAecSupported(
chromeos::DBusMethodCallback<bool> callback) override;
void GetSystemAecGroupId(
chromeos::DBusMethodCallback<int32_t> callback) override;
void GetSystemNsSupported(
chromeos::DBusMethodCallback<bool> callback) override;
void GetSystemAgcSupported(
chromeos::DBusMethodCallback<bool> callback) override;
void GetNodes(chromeos::DBusMethodCallback<AudioNodeList> callback) override;
void GetNumberOfNonChromeOutputStreams(
chromeos::DBusMethodCallback<int32_t> callback) override;
void GetNumberOfActiveOutputStreams(
chromeos::DBusMethodCallback<int> callback) override;
void GetNumberOfInputStreamsWithPermission(
chromeos::DBusMethodCallback<ClientTypeToInputStreamCount>) override;
void GetSpeakOnMuteDetectionEnabled(
chromeos::DBusMethodCallback<bool> callback) override;
void SetOutputNodeVolume(uint64_t node_id, int32_t volume) override;
void SetOutputUserMute(bool mute_on) override;
void SetInputNodeGain(uint64_t node_id, int32_t gain) override;
void SetInputMute(bool mute_on) override;
void GetAudioEffectDlcs(
chromeos::DBusMethodCallback<std::string> callback) override;
void GetVoiceIsolationUIAppearance(
chromeos::DBusMethodCallback<VoiceIsolationUIAppearance> callback)
override;
void SetVoiceIsolationUIEnabled(bool voice_isolation_on) override;
void SetVoiceIsolationUIPreferredEffect(uint32_t effect_mode) override;
void SetNoiseCancellationEnabled(bool noise_cancellation_on) override;
void GetNoiseCancellationSupported(
chromeos::DBusMethodCallback<bool> callback) override;
void SetStyleTransferEnabled(bool style_transfer_on) override;
void GetStyleTransferSupported(
chromeos::DBusMethodCallback<bool> callback) override;
void SetActiveOutputNode(uint64_t node_id) override;
void SetActiveInputNode(uint64_t node_id) override;
void SetHotwordModel(uint64_t node_id,
const std::string& hotword_model,
chromeos::VoidDBusMethodCallback callback) override;
void SetFixA2dpPacketSize(bool enabled) override;
void SetFlossEnabled(bool enabled) override;
void SetSpeakOnMuteDetection(bool enabled) override;
void SetEwmaPowerReportEnabled(bool enabled) override;
void SetSidetoneEnabled(bool enabled) override;
void GetSidetoneSupported(
chromeos::DBusMethodCallback<bool> callback) override;
void AddActiveInputNode(uint64_t node_id) override;
void RemoveActiveInputNode(uint64_t node_id) override;
void AddActiveOutputNode(uint64_t node_id) override;
void RemoveActiveOutputNode(uint64_t node_id) override;
void SwapLeftRight(uint64_t node_id, bool swap) override;
void SetDisplayRotation(uint64_t node_id,
cras::DisplayRotation rotation) override;
void SetGlobalOutputChannelRemix(int32_t channels,
const std::vector<double>& mixer) override;
void SetPlayerPlaybackStatus(const std::string& playback_status) override;
void SetPlayerIdentity(const std::string& playback_identity) override;
void SetPlayerPosition(const int64_t& position) override;
void SetPlayerDuration(const int64_t& duration) override;
void SetPlayerMetadata(
const std::map<std::string, std::string>& metadata) override;
void ResendBluetoothBattery() override;
void WaitForServiceToBeAvailable(
chromeos::WaitForServiceToBeAvailableCallback callback) override;
void SetForceRespectUiGains(bool force_respect_ui_gains_enabled) override;
void GetNumStreamIgnoreUiGains(
chromeos::DBusMethodCallback<int> callback) override;
void GetNumberOfArcStreams(
chromeos::DBusMethodCallback<int> callback) override;
void SetHfpMicSrEnabled(bool hfp_mic_sr_on) override;
void GetHfpMicSrSupported(
chromeos::DBusMethodCallback<bool> callback) override;
void SetSpatialAudio(bool spatial_audio_enabled) override;
void GetSpatialAudioSupported(
chromeos::DBusMethodCallback<bool> callback) override;
void SetNumberOfNonChromeOutputStreams(int32_t streams);
void InsertAudioNodeToList(const AudioNode& audio_node);
void RemoveAudioNodeFromList(const uint64_t& node_id);
void SetAudioNodesForTesting(const AudioNodeList& audio_nodes);
void SetAudioNodesAndNotifyObserversForTesting(
const AudioNodeList& new_nodes);
void NotifyOutputNodeVolumeChangedForTesting(uint64_t node_id, int volume);
void NotifyInputNodeGainChangedForTesting(uint64_t node_id, int gain);
void NotifyHotwordTriggeredForTesting(uint64_t tv_sec, uint64_t tv_nsec);
void SetBluetoothBattteryLevelForTesting(uint32_t level);
void SetActiveInputStreamsWithPermission(
const ClientTypeToInputStreamCount& input_streams);
void NotifySurveyTriggered(
const base::flat_map<std::string, std::string>& survey_specific_data);
void SetNumberOfArcStreams(int32_t streams);
void SetAudioEffectDlcsForTesting(const std::string& audio_effect_dlcs);
const AudioNodeList& node_list() const { return node_list_; }
const uint64_t& active_input_node_id() const { return active_input_node_id_; }
const uint64_t& active_output_node_id() const {
return active_output_node_id_;
}
void disable_volume_change_events() { enable_volume_change_events_ = false; }
void send_volume_change_events_asynchronous() {
send_volume_change_events_synchronous_ = false;
}
void disable_gain_change_events() { enable_gain_change_events_ = false; }
bool noise_cancellation_enabled() const {
return voice_isolation_ui_enabled_;
}
bool style_transfer_enabled() const { return voice_isolation_ui_enabled_; }
bool speak_on_mute_detection_enabled() const {
return speak_on_mute_detection_enabled_;
}
bool force_respect_ui_gains_enabled() const {
return force_respect_ui_gains_enabled_;
}
bool hfp_mic_sr_enabled() const { return hfp_mic_sr_enabled_; }
bool spatial_audio_enabled() const { return spatial_audio_enabled_; }
private:
AudioNodeList::iterator FindNode(uint64_t node_id);
VolumeState volume_state_;
AudioNodeList node_list_;
VoiceIsolationUIAppearance voice_isolation_ui_appearance_;
uint64_t active_input_node_id_ = 0;
uint64_t active_output_node_id_ = 0;
bool enable_volume_change_events_ = true;
bool send_volume_change_events_synchronous_ = true;
bool enable_gain_change_events_ = true;
bool noise_cancellation_supported_ = false;
bool style_transfer_supported_ = false;
uint32_t battery_level_ = 0;
uint32_t noise_cancellation_enabled_counter_ = 0;
int32_t number_non_chrome_output_streams_ = 0;
bool voice_isolation_ui_enabled_ = false;
uint32_t voice_isolation_preferred_effect_ = 0;
bool speak_on_mute_detection_enabled_ = false;
bool ewma_power_report_enabled_ = false;
bool sidetone_enabled_ = false;
bool sidetone_supported_ = false;
bool force_respect_ui_gains_enabled_ = false;
bool hfp_mic_sr_enabled_ = false;
bool hfp_mic_sr_supported_ = false;
bool spatial_audio_enabled_ = false;
bool spatial_audio_supported_ = false;
ClientTypeToInputStreamCount active_input_streams_;
int32_t number_arc_streams_ = 0;
std::string audio_effect_dlcs_;
base::ObserverList<Observer>::Unchecked observers_;
base::WeakPtrFactory<FakeCrasAudioClient> weak_ptr_factory_{this};
};
}
#endif