#include "device/bluetooth/floss/floss_dbus_manager.h"
#include <memory>
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_pump_type.h"
#include "base/threading/thread.h"
#include "build/build_config.h"
#include "components/device_event_log/device_event_log.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_manager.h"
#include "dbus/object_proxy.h"
#include "device/bluetooth/floss/fake_floss_adapter_client.h"
#include "device/bluetooth/floss/fake_floss_admin_client.h"
#include "device/bluetooth/floss/fake_floss_advertiser_client.h"
#include "device/bluetooth/floss/fake_floss_battery_manager_client.h"
#include "device/bluetooth/floss/fake_floss_bluetooth_telephony_client.h"
#include "device/bluetooth/floss/fake_floss_gatt_manager_client.h"
#include "device/bluetooth/floss/fake_floss_lescan_client.h"
#include "device/bluetooth/floss/fake_floss_logging_client.h"
#include "device/bluetooth/floss/fake_floss_manager_client.h"
#include "device/bluetooth/floss/fake_floss_socket_manager.h"
#include "device/bluetooth/floss/floss_adapter_client.h"
#include "device/bluetooth/floss/floss_advertiser_client.h"
#include "device/bluetooth/floss/floss_battery_manager_client.h"
#include "device/bluetooth/floss/floss_bluetooth_telephony_client.h"
#include "device/bluetooth/floss/floss_lescan_client.h"
#include "device/bluetooth/floss/floss_logging_client.h"
#include "device/bluetooth/floss/floss_manager_client.h"
#include "device/bluetooth/floss/floss_socket_manager.h"
#include "floss_dbus_manager.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "device/bluetooth/floss/floss_admin_client.h"
#endif
namespace floss {
namespace {
FlossDBusManager* g_floss_dbus_manager = …;
}
const int FlossDBusManager::kInvalidAdapter = …;
static bool g_using_floss_dbus_manager_for_testing = …;
const int FlossDBusManager::kClientReadyTimeoutMs = …;
const int FlossDBusManager::kWaitServiceTimeoutMs = …;
FlossDBusManager::ClientInitializer::ClientInitializer(
base::OnceClosure on_ready,
int client_count)
: … { … }
FlossDBusManager::ClientInitializer::~ClientInitializer() = default;
FlossDBusManager::FlossDBusManager(dbus::Bus* bus, bool use_stubs) : … { … }
FlossDBusManager::~FlossDBusManager() = default;
dbus::PropertySet* FlossDBusManager::CreateProperties(
dbus::ObjectProxy* object_proxy,
const dbus::ObjectPath& object_path,
const std::string& interface_name) { … }
void FlossDBusManager::ObjectAdded(const dbus::ObjectPath& object_path,
const std::string& interface_name) { … }
void FlossDBusManager::ObjectRemoved(const dbus::ObjectPath& object_path,
const std::string& interface_name) { … }
void FlossDBusManager::InitAdapterClientsIfReady() { … }
void FlossDBusManager::InitAdapterLoggingClientsIfReady() { … }
#if BUILDFLAG(IS_CHROMEOS)
void FlossDBusManager::InitAdminClientsIfReady() {
if (admin_interface_present_ && HasActiveAdapter() && client_on_ready_ &&
!client_on_ready_->Finished()) {
GetAdminClient()->Init(GetSystemBus(), kAdapterService, active_adapter_,
version_, client_on_ready_->CreateReadyClosure());
}
}
#endif
void FlossDBusManager::InitBatteryClientsIfReady() { … }
void FlossDBusManager::InitTelephonyClientsIfReady() { … }
void FlossDBusManager::InitGattClientsIfReady() { … }
void FlossDBusManager::InitSocketManagerClientsIfReady() { … }
void FlossDBusManager::Initialize(dbus::Bus* system_bus) { … }
void FlossDBusManager::InitializeFake() { … }
void FlossDBusManager::SetAllClientsPresentForTesting() { … }
std::unique_ptr<FlossDBusManagerSetter>
floss::FlossDBusManager::GetSetterForTesting() { … }
bool FlossDBusManager::IsInitialized() { … }
void FlossDBusManager::Shutdown() { … }
FlossDBusManager* FlossDBusManager::Get() { … }
void FlossDBusManager::CreateGlobalInstance(dbus::Bus* bus, bool use_stubs) { … }
bool FlossDBusManager::CallWhenObjectManagerSupportIsKnown(
base::OnceClosure callback) { … }
void FlossDBusManager::OnObjectManagerSupported(dbus::Response* response) { … }
void FlossDBusManager::OnWaitServiceAvailableTimeout() { … }
void FlossDBusManager::OnManagerServiceAvailable(bool is_available) { … }
void FlossDBusManager::OnObjectManagerNotSupported(
dbus::ErrorResponse* response) { … }
void FlossDBusManager::OnManagerClientInitComplete() { … }
void FlossDBusManager::SwitchAdapter(int adapter, base::OnceClosure on_ready) { … }
bool FlossDBusManager::HasActiveAdapter() const { … }
int FlossDBusManager::GetActiveAdapter() const { … }
bool FlossDBusManager::AreClientsReady() const { … }
FlossAdapterClient* FlossDBusManager::GetAdapterClient() { … }
FlossGattManagerClient* FlossDBusManager::GetGattManagerClient() { … }
FlossManagerClient* FlossDBusManager::GetManagerClient() { … }
FlossSocketManager* FlossDBusManager::GetSocketManager() { … }
FlossLEScanClient* FlossDBusManager::GetLEScanClient() { … }
FlossAdvertiserClient* FlossDBusManager::GetAdvertiserClient() { … }
FlossBatteryManagerClient* FlossDBusManager::GetBatteryManagerClient() { … }
FlossBluetoothTelephonyClient* FlossDBusManager::GetBluetoothTelephonyClient() { … }
FlossLoggingClient* FlossDBusManager::GetLoggingClient() { … }
#if BUILDFLAG(IS_CHROMEOS)
FlossAdminClient* FlossDBusManager::GetAdminClient() {
return client_bundle_->admin_client();
}
#endif
void FlossDBusManager::InitializeAdapterClients(int adapter,
base::OnceClosure on_ready) { … }
void FlossDBusManagerSetter::SetFlossManagerClient(
std::unique_ptr<FlossManagerClient> client) { … }
void FlossDBusManagerSetter::SetFlossAdapterClient(
std::unique_ptr<FlossAdapterClient> client) { … }
void FlossDBusManagerSetter::SetFlossGattManagerClient(
std::unique_ptr<FlossGattManagerClient> client) { … }
void FlossDBusManagerSetter::SetFlossSocketManager(
std::unique_ptr<FlossSocketManager> mgr) { … }
void FlossDBusManagerSetter::SetFlossLEScanClient(
std::unique_ptr<FlossLEScanClient> client) { … }
void FlossDBusManagerSetter::SetFlossAdvertiserClient(
std::unique_ptr<FlossAdvertiserClient> client) { … }
void FlossDBusManagerSetter::SetFlossBatteryManagerClient(
std::unique_ptr<FlossBatteryManagerClient> client) { … }
void FlossDBusManagerSetter::SetFlossBluetoothTelephonyClient(
std::unique_ptr<FlossBluetoothTelephonyClient> client) { … }
void FlossDBusManagerSetter::SetFlossLoggingClient(
std::unique_ptr<FlossLoggingClient> client) { … }
#if BUILDFLAG(IS_CHROMEOS)
void FlossDBusManagerSetter::SetFlossAdminClient(
std::unique_ptr<FlossAdminClient> client) {
FlossDBusManager::Get()->client_bundle_->admin_client_ = std::move(client);
}
#endif
FlossClientBundle::FlossClientBundle(bool use_stubs) : … { … }
FlossClientBundle::~FlossClientBundle() = default;
void FlossClientBundle::ResetAdapterClients() { … }
}