Loading system/btif/test/btif_dm_test.cc +34 −7 Original line number Diff line number Diff line Loading @@ -23,8 +23,9 @@ #include <memory> #include "bta/include/bta_api_data_types.h" #include "btif/include/btif_dm.h" #include "btif/include/mock_core_callbacks.h" #include "main/shim/entry.h" #include "main/shim/shim.h" #include "main/shim/stack.h" #include "module.h" #include "stack/include/bt_dev_class.h" Loading Loading @@ -116,21 +117,47 @@ TEST_F(BtifDmWithUidTest, bta_energy_info_cb__with_uid) { ASSERT_TRUE(invoke_energy_info_cb_entered); } // Mock implementation for GetStorage() static bluetooth::storage::StorageModule* s_StorageModule = nullptr; bluetooth::storage::StorageModule* bluetooth::shim::GetStorage() { return s_StorageModule; } bluetooth::os::Handler* bluetooth::shim::GetGdShimHandler() { return nullptr; } bluetooth::hci::LeAdvertisingManager* bluetooth::shim::GetAdvertising() { return nullptr; } bluetooth::hci::ControllerInterface* bluetooth::shim::GetController() { return nullptr; } bluetooth::hci::HciInterface* bluetooth::shim::GetHciLayer() { return nullptr; } bluetooth::hci::RemoteNameRequestModule* bluetooth::shim::GetRemoteNameRequest() { return nullptr; } bluetooth::hci::LeScanningManager* bluetooth::shim::GetScanning() { return nullptr; } bluetooth::hci::DistanceMeasurementManager* bluetooth::shim::GetDistanceMeasurementManager() { return nullptr; } bluetooth::hal::SnoopLogger* bluetooth::shim::GetSnoopLogger() { return nullptr; } bluetooth::lpp::LppOffloadInterface* bluetooth::shim::GetLppOffloadManager() { return nullptr; } bluetooth::hci::AclManager* bluetooth::shim::GetAclManager() { return nullptr; } bluetooth::metrics::CounterMetrics* bluetooth::shim::GetCounterMetrics() { return nullptr; } bluetooth::hci::MsftExtensionManager* bluetooth::shim::GetMsftExtensionManager() { return nullptr; } bool bluetooth::shim::is_gd_stack_started_up() { return s_StorageModule != nullptr; } class BtifDmWithStackTest : public BtifDmTest { protected: void SetUp() override { BtifDmTest::SetUp(); modules_.add<bluetooth::storage::StorageModule>(); bluetooth::shim::Stack::GetInstance()->StartModuleStack( &modules_, new bluetooth::os::Thread("gd_stack_thread", bluetooth::os::Thread::Priority::NORMAL)); thread_ = new bluetooth::os::Thread("gd_stack_thread", bluetooth::os::Thread::Priority::NORMAL); storage_module_ = new bluetooth::storage::StorageModule(new bluetooth::os::Handler(thread_)); storage_module_->Start(); s_StorageModule = storage_module_; } void TearDown() override { bluetooth::shim::Stack::GetInstance()->Stop(); storage_module_->Stop(); s_StorageModule = nullptr; delete storage_module_; delete thread_; BtifDmTest::TearDown(); } bluetooth::ModuleList modules_; bluetooth::os::Thread* thread_; bluetooth::storage::StorageModule* storage_module_; }; TEST_F_WITH_FLAGS(BtifDmWithStackTest, btif_dm_search_services_evt__BTA_DM_NAME_READ_EVT) { Loading system/gd/module.h +3 −0 Original line number Diff line number Diff line Loading @@ -81,9 +81,12 @@ class Module { friend TestModuleRegistry; public: Module() = default; virtual ~Module() = default; protected: Module(os::Handler* handler) : handler_(handler) {} // Populate the provided list with modules that must start before yours virtual void ListDependencies(ModuleList* list) const = 0; Loading system/gd/storage/storage_module.cc +13 −9 Original line number Diff line number Diff line Loading @@ -63,11 +63,20 @@ const std::string StorageModule::kTimeCreatedFormat = "%Y-%m-%d %H:%M:%S"; const std::string StorageModule::kAdapterSection = BTIF_STORAGE_SECTION_ADAPTER; StorageModule::StorageModule(std::string config_file_path, StorageModule::StorageModule() : StorageModule(nullptr, os::ParameterProvider::ConfigFilePath(), kDefaultConfigSaveDelay, kDefaultTempDeviceCapacity, false, false) {} StorageModule::StorageModule(os::Handler* handler) : StorageModule(handler, os::ParameterProvider::ConfigFilePath(), kDefaultConfigSaveDelay, kDefaultTempDeviceCapacity, false, false) {} StorageModule::StorageModule(os::Handler* handler, std::string config_file_path, std::chrono::milliseconds config_save_delay, size_t temp_devices_capacity, bool is_restricted_mode, bool is_single_user_mode) : config_file_path_(std::move(config_file_path)), : Module(handler), config_file_path_(std::move(config_file_path)), config_save_delay_(config_save_delay), temp_devices_capacity_(temp_devices_capacity), is_restricted_mode_(is_restricted_mode), Loading @@ -84,10 +93,7 @@ StorageModule::~StorageModule() { pimpl_.reset(); } const ModuleFactory StorageModule::Factory = ModuleFactory([]() { return new StorageModule(os::ParameterProvider::ConfigFilePath(), kDefaultConfigSaveDelay, kDefaultTempDeviceCapacity, false, false); }); const ModuleFactory StorageModule::Factory = ModuleFactory([]() { return new StorageModule(); }); struct StorageModule::impl { explicit impl(Handler* handler, ConfigCache cache, size_t in_memory_cache_size_limit) Loading Loading @@ -144,9 +150,7 @@ void StorageModule::Clear() { pimpl_->cache_.Clear(); } void StorageModule::ListDependencies(ModuleList* list) const { list->add<metrics::CounterMetrics>(); } void StorageModule::ListDependencies(ModuleList* /*list*/) const {} void StorageModule::Start() { std::lock_guard<std::recursive_mutex> lock(mutex_); Loading system/gd/storage/storage_module.h +8 −4 Original line number Diff line number Diff line Loading @@ -55,12 +55,17 @@ public: static const std::string kAdapterSection; StorageModule(); StorageModule(os::Handler*); StorageModule(const StorageModule&) = delete; StorageModule& operator=(const StorageModule&) = delete; ~StorageModule(); static const ModuleFactory Factory; void Start() override; void Stop() override; // Methods to access the storage layer via Device abstraction // - Devices will be lazily created when methods below are called. Hence, no std::optional<> nor // nullptr is used in Loading Loading @@ -121,8 +126,6 @@ public: protected: void ListDependencies(ModuleList* list) const override; void Start() override; void Stop() override; std::string ToString() const override; friend shim::BtifConfigInterface; Loading @@ -147,8 +150,9 @@ protected: // - temp_devices_capacity is the number of temporary, typically unpaired devices to hold in a // memory based LRU // - is_restricted_mode and is_single_user_mode are flags from upper layer StorageModule(std::string config_file_path, std::chrono::milliseconds config_save_delay, size_t temp_devices_capacity, bool is_restricted_mode, bool is_single_user_mode); StorageModule(os::Handler* handler, std::string config_file_path, std::chrono::milliseconds config_save_delay, size_t temp_devices_capacity, bool is_restricted_mode, bool is_single_user_mode); bool HasSection(const std::string& section) const; bool HasProperty(const std::string& section, const std::string& property) const; Loading system/gd/storage/storage_module_test.cc +2 −2 Original line number Diff line number Diff line Loading @@ -53,8 +53,8 @@ class TestStorageModule : public StorageModule { public: TestStorageModule(std::string config_file_path, std::chrono::milliseconds config_save_delay, bool is_restricted_mode, bool is_single_user_mode) : StorageModule(std::move(config_file_path), config_save_delay, kTestTempDevicesCapacity, is_restricted_mode, is_single_user_mode) {} : StorageModule(nullptr, std::move(config_file_path), config_save_delay, kTestTempDevicesCapacity, is_restricted_mode, is_single_user_mode) {} ConfigCache* GetMemoryOnlyConfigCachePublic() { return StorageModule::GetMemoryOnlyConfigCache(); Loading Loading
system/btif/test/btif_dm_test.cc +34 −7 Original line number Diff line number Diff line Loading @@ -23,8 +23,9 @@ #include <memory> #include "bta/include/bta_api_data_types.h" #include "btif/include/btif_dm.h" #include "btif/include/mock_core_callbacks.h" #include "main/shim/entry.h" #include "main/shim/shim.h" #include "main/shim/stack.h" #include "module.h" #include "stack/include/bt_dev_class.h" Loading Loading @@ -116,21 +117,47 @@ TEST_F(BtifDmWithUidTest, bta_energy_info_cb__with_uid) { ASSERT_TRUE(invoke_energy_info_cb_entered); } // Mock implementation for GetStorage() static bluetooth::storage::StorageModule* s_StorageModule = nullptr; bluetooth::storage::StorageModule* bluetooth::shim::GetStorage() { return s_StorageModule; } bluetooth::os::Handler* bluetooth::shim::GetGdShimHandler() { return nullptr; } bluetooth::hci::LeAdvertisingManager* bluetooth::shim::GetAdvertising() { return nullptr; } bluetooth::hci::ControllerInterface* bluetooth::shim::GetController() { return nullptr; } bluetooth::hci::HciInterface* bluetooth::shim::GetHciLayer() { return nullptr; } bluetooth::hci::RemoteNameRequestModule* bluetooth::shim::GetRemoteNameRequest() { return nullptr; } bluetooth::hci::LeScanningManager* bluetooth::shim::GetScanning() { return nullptr; } bluetooth::hci::DistanceMeasurementManager* bluetooth::shim::GetDistanceMeasurementManager() { return nullptr; } bluetooth::hal::SnoopLogger* bluetooth::shim::GetSnoopLogger() { return nullptr; } bluetooth::lpp::LppOffloadInterface* bluetooth::shim::GetLppOffloadManager() { return nullptr; } bluetooth::hci::AclManager* bluetooth::shim::GetAclManager() { return nullptr; } bluetooth::metrics::CounterMetrics* bluetooth::shim::GetCounterMetrics() { return nullptr; } bluetooth::hci::MsftExtensionManager* bluetooth::shim::GetMsftExtensionManager() { return nullptr; } bool bluetooth::shim::is_gd_stack_started_up() { return s_StorageModule != nullptr; } class BtifDmWithStackTest : public BtifDmTest { protected: void SetUp() override { BtifDmTest::SetUp(); modules_.add<bluetooth::storage::StorageModule>(); bluetooth::shim::Stack::GetInstance()->StartModuleStack( &modules_, new bluetooth::os::Thread("gd_stack_thread", bluetooth::os::Thread::Priority::NORMAL)); thread_ = new bluetooth::os::Thread("gd_stack_thread", bluetooth::os::Thread::Priority::NORMAL); storage_module_ = new bluetooth::storage::StorageModule(new bluetooth::os::Handler(thread_)); storage_module_->Start(); s_StorageModule = storage_module_; } void TearDown() override { bluetooth::shim::Stack::GetInstance()->Stop(); storage_module_->Stop(); s_StorageModule = nullptr; delete storage_module_; delete thread_; BtifDmTest::TearDown(); } bluetooth::ModuleList modules_; bluetooth::os::Thread* thread_; bluetooth::storage::StorageModule* storage_module_; }; TEST_F_WITH_FLAGS(BtifDmWithStackTest, btif_dm_search_services_evt__BTA_DM_NAME_READ_EVT) { Loading
system/gd/module.h +3 −0 Original line number Diff line number Diff line Loading @@ -81,9 +81,12 @@ class Module { friend TestModuleRegistry; public: Module() = default; virtual ~Module() = default; protected: Module(os::Handler* handler) : handler_(handler) {} // Populate the provided list with modules that must start before yours virtual void ListDependencies(ModuleList* list) const = 0; Loading
system/gd/storage/storage_module.cc +13 −9 Original line number Diff line number Diff line Loading @@ -63,11 +63,20 @@ const std::string StorageModule::kTimeCreatedFormat = "%Y-%m-%d %H:%M:%S"; const std::string StorageModule::kAdapterSection = BTIF_STORAGE_SECTION_ADAPTER; StorageModule::StorageModule(std::string config_file_path, StorageModule::StorageModule() : StorageModule(nullptr, os::ParameterProvider::ConfigFilePath(), kDefaultConfigSaveDelay, kDefaultTempDeviceCapacity, false, false) {} StorageModule::StorageModule(os::Handler* handler) : StorageModule(handler, os::ParameterProvider::ConfigFilePath(), kDefaultConfigSaveDelay, kDefaultTempDeviceCapacity, false, false) {} StorageModule::StorageModule(os::Handler* handler, std::string config_file_path, std::chrono::milliseconds config_save_delay, size_t temp_devices_capacity, bool is_restricted_mode, bool is_single_user_mode) : config_file_path_(std::move(config_file_path)), : Module(handler), config_file_path_(std::move(config_file_path)), config_save_delay_(config_save_delay), temp_devices_capacity_(temp_devices_capacity), is_restricted_mode_(is_restricted_mode), Loading @@ -84,10 +93,7 @@ StorageModule::~StorageModule() { pimpl_.reset(); } const ModuleFactory StorageModule::Factory = ModuleFactory([]() { return new StorageModule(os::ParameterProvider::ConfigFilePath(), kDefaultConfigSaveDelay, kDefaultTempDeviceCapacity, false, false); }); const ModuleFactory StorageModule::Factory = ModuleFactory([]() { return new StorageModule(); }); struct StorageModule::impl { explicit impl(Handler* handler, ConfigCache cache, size_t in_memory_cache_size_limit) Loading Loading @@ -144,9 +150,7 @@ void StorageModule::Clear() { pimpl_->cache_.Clear(); } void StorageModule::ListDependencies(ModuleList* list) const { list->add<metrics::CounterMetrics>(); } void StorageModule::ListDependencies(ModuleList* /*list*/) const {} void StorageModule::Start() { std::lock_guard<std::recursive_mutex> lock(mutex_); Loading
system/gd/storage/storage_module.h +8 −4 Original line number Diff line number Diff line Loading @@ -55,12 +55,17 @@ public: static const std::string kAdapterSection; StorageModule(); StorageModule(os::Handler*); StorageModule(const StorageModule&) = delete; StorageModule& operator=(const StorageModule&) = delete; ~StorageModule(); static const ModuleFactory Factory; void Start() override; void Stop() override; // Methods to access the storage layer via Device abstraction // - Devices will be lazily created when methods below are called. Hence, no std::optional<> nor // nullptr is used in Loading Loading @@ -121,8 +126,6 @@ public: protected: void ListDependencies(ModuleList* list) const override; void Start() override; void Stop() override; std::string ToString() const override; friend shim::BtifConfigInterface; Loading @@ -147,8 +150,9 @@ protected: // - temp_devices_capacity is the number of temporary, typically unpaired devices to hold in a // memory based LRU // - is_restricted_mode and is_single_user_mode are flags from upper layer StorageModule(std::string config_file_path, std::chrono::milliseconds config_save_delay, size_t temp_devices_capacity, bool is_restricted_mode, bool is_single_user_mode); StorageModule(os::Handler* handler, std::string config_file_path, std::chrono::milliseconds config_save_delay, size_t temp_devices_capacity, bool is_restricted_mode, bool is_single_user_mode); bool HasSection(const std::string& section) const; bool HasProperty(const std::string& section, const std::string& property) const; Loading
system/gd/storage/storage_module_test.cc +2 −2 Original line number Diff line number Diff line Loading @@ -53,8 +53,8 @@ class TestStorageModule : public StorageModule { public: TestStorageModule(std::string config_file_path, std::chrono::milliseconds config_save_delay, bool is_restricted_mode, bool is_single_user_mode) : StorageModule(std::move(config_file_path), config_save_delay, kTestTempDevicesCapacity, is_restricted_mode, is_single_user_mode) {} : StorageModule(nullptr, std::move(config_file_path), config_save_delay, kTestTempDevicesCapacity, is_restricted_mode, is_single_user_mode) {} ConfigCache* GetMemoryOnlyConfigCachePublic() { return StorageModule::GetMemoryOnlyConfigCache(); Loading