diff options
author | Jacob Keeler <jacob.keeler@livioradio.com> | 2020-08-17 15:54:00 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-17 15:54:00 -0400 |
commit | 4c9f873f1b5f77b8a4076602c2f544809e97a24a (patch) | |
tree | 2e212f9c2d0924d84c87ebb8e2c65b832184a2dc /src/components/policy | |
parent | d2202209e499ab2682b1da554d4373b2893b605b (diff) | |
download | sdl_core-4c9f873f1b5f77b8a4076602c2f544809e97a24a.tar.gz |
Add SubtleAlert RPC (#3459)
* Add SubtleAlert RPC to project
* Add OnSubtleAlertPressed implementation
* Add `subtle_notifications_per_minute_by_priority` field to policies
Diffstat (limited to 'src/components/policy')
33 files changed, 517 insertions, 58 deletions
diff --git a/src/components/policy/policy_external/include/policy/cache_manager.h b/src/components/policy/policy_external/include/policy/cache_manager.h index 36dd6d7259..12fe8f10cd 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -309,13 +309,8 @@ class CacheManager : public CacheManagerInterface { void GetUpdateUrls(const uint32_t service_type, EndpointUrls& out_end_points) const OVERRIDE; - /** - * @brief Gets allowed number of notifications - * depending on application priority. - * @param priority Priority of application - */ virtual rpc::policy_table_interface_base::NumberOfNotificationsType - GetNotificationsNumber(const std::string& priority); + GetNotificationsNumber(const std::string& priority, const bool is_subtle); /** * @brief Gets priority for given application diff --git a/src/components/policy/policy_external/include/policy/cache_manager_interface.h b/src/components/policy/policy_external/include/policy/cache_manager_interface.h index 44df1f36a5..8ed46e0c72 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager_interface.h +++ b/src/components/policy/policy_external/include/policy/cache_manager_interface.h @@ -342,9 +342,10 @@ class CacheManagerInterface { * @brief Get allowed number of notifications * depending on application priority. * @param priority Priority of application + * @param is_subtle If true, get the number of allowed subtle notifications */ virtual policy_table::NumberOfNotificationsType GetNotificationsNumber( - const std::string& priority) = 0; + const std::string& priority, const bool is_subtle) = 0; /** * @brief Get priority for given application diff --git a/src/components/policy/policy_external/include/policy/policy_manager_impl.h b/src/components/policy/policy_external/include/policy/policy_manager_impl.h index 04fac53885..27ce30bb3d 100644 --- a/src/components/policy/policy_external/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_external/include/policy/policy_manager_impl.h @@ -442,9 +442,11 @@ class PolicyManagerImpl : public PolicyManager { /** * @brief Get number of notification by priority * @param priority Specified priority + * @param is_subtle If true, get the number of allowed subtle notifications * @return notification number */ - uint32_t GetNotificationsNumber(const std::string& priority) const OVERRIDE; + uint32_t GetNotificationsNumber(const std::string& priority, + const bool is_subtle) const OVERRIDE; /** * @brief Allows to update Vehicle Identification Number in policy table. diff --git a/src/components/policy/policy_external/include/policy/policy_table/types.h b/src/components/policy/policy_external/include/policy/policy_table/types.h index 6e6fd1afb8..7736468aa0 100644 --- a/src/components/policy/policy_external/include/policy/policy_table/types.h +++ b/src/components/policy/policy_external/include/policy/policy_table/types.h @@ -382,6 +382,7 @@ struct ModuleConfig : CompositeType { ServiceEndpoints endpoints; Optional<ServiceEndpointProperties> endpoint_properties; NumberOfNotificationsPerMinute notifications_per_minute_by_priority; + NumberOfNotificationsPerMinute subtle_notifications_per_minute_by_priority; Optional<String<0, 100> > vehicle_make; Optional<String<0, 100> > vehicle_model; Optional<String<0, 4> > vehicle_year; @@ -403,7 +404,9 @@ struct ModuleConfig : CompositeType { const ServiceEndpoints& endpoints, const ServiceEndpointProperties& endpoint_properties, const NumberOfNotificationsPerMinute& - notifications_per_minute_by_priority); + notifications_per_minute_by_priority, + const NumberOfNotificationsPerMinute& + subtle_notifications_per_minute_by_priority); ~ModuleConfig(); explicit ModuleConfig(const Json::Value* value__); void SafeCopyFrom(const ModuleConfig& from); diff --git a/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml b/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml index 7446d3acae..7fad362c57 100644 --- a/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml +++ b/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml @@ -176,6 +176,7 @@ <param name="seconds_between_retries" type="SecondsBetweenRetries" /> <param name="endpoints" type="ServiceEndpoints" /> <param name="notifications_per_minute_by_priority" type="NumberOfNotificationsPerMinute" /> + <param name="subtle_notifications_per_minute_by_priority" type="NumberOfNotificationsPerMinute" /> <param name="vehicle_make" type="String" maxlength="100" mandatory="false" /> <param name="vehicle_model" type="String" maxlength="100" diff --git a/src/components/policy/policy_external/include/policy/sql_pt_queries.h b/src/components/policy/policy_external/include/policy/sql_pt_queries.h index 8a3ad1f7df..aba08dcca1 100644 --- a/src/components/policy/policy_external/include/policy/sql_pt_queries.h +++ b/src/components/policy/policy_external/include/policy/sql_pt_queries.h @@ -52,6 +52,7 @@ extern const std::string kSelectEndpoint; extern const std::string kSelectModuleConfig; extern const std::string kSelectEndpoints; extern const std::string kSelectNotificationsPerMin; +extern const std::string kSelectSubtleNotificationsPerMin; extern const std::string kSelectNotificationsPerPriority; extern const std::string kSelectAppLevels; extern const std::string kSelectDeviceData; @@ -93,6 +94,7 @@ extern const std::string kUpdateModuleConfig; extern const std::string kInsertEndpoint; extern const std::string kInsertSecondsBetweenRetry; extern const std::string kInsertNotificationsByPriority; +extern const std::string kInsertSubtleNotificationsByPriority; extern const std::string kInsertDeviceData; extern const std::string kInsertAppLevel; extern const std::string kDeleteSecondsBetweenRetries; diff --git a/src/components/policy/policy_external/include/policy/sql_pt_representation.h b/src/components/policy/policy_external/include/policy/sql_pt_representation.h index 574806b3fb..473022c6c3 100644 --- a/src/components/policy/policy_external/include/policy/sql_pt_representation.h +++ b/src/components/policy/policy_external/include/policy/sql_pt_representation.h @@ -250,6 +250,8 @@ class SQLPTRepresentation : public virtual PTRepresentation { const policy_table::SecondsBetweenRetries& seconds); bool SaveNumberOfNotificationsPerMinute( const policy_table::NumberOfNotificationsPerMinute& notifications); + bool SaveNumberOfSubtleNotificationsPerMinute( + const policy_table::NumberOfNotificationsPerMinute& notifications); bool SaveMessageType(const std::string& type); bool SaveLanguage(const std::string& code); policy_table::VehicleDataItem PopulateVDIFromQuery( diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index 40c216a720..fee1bce426 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -1797,15 +1797,18 @@ std::string CacheManager::GetIconUrl(const std::string& policy_app_id) const { } rpc::policy_table_interface_base::NumberOfNotificationsType -CacheManager::GetNotificationsNumber(const std::string& priority) { +CacheManager::GetNotificationsNumber(const std::string& priority, + const bool is_subtle) { CACHE_MANAGER_CHECK(0); - typedef rpc::policy_table_interface_base::NumberOfNotificationsPerMinute NNPM; sync_primitives::AutoLock auto_lock(cache_lock_); - const NNPM& nnpm = - pt_->policy_table.module_config.notifications_per_minute_by_priority; + const auto& nnpm = is_subtle + ? pt_->policy_table.module_config + .subtle_notifications_per_minute_by_priority + : pt_->policy_table.module_config + .notifications_per_minute_by_priority; - NNPM::const_iterator priority_iter = nnpm.find(priority); + auto priority_iter = nnpm.find(priority); const uint32_t result = (nnpm.end() != priority_iter ? (*priority_iter).second : 0); diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index f057e21617..0c72aac4ad 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -428,6 +428,12 @@ void FilterPolicyTable( FilterInvalidPriorityValues( module_config.notifications_per_minute_by_priority); } + if (module_config.is_initialized() && + module_config.subtle_notifications_per_minute_by_priority + .is_initialized()) { + FilterInvalidPriorityValues( + module_config.subtle_notifications_per_minute_by_priority); + } if (pt.app_policies_section.is_initialized()) { policy_table::ApplicationPolicies& apps = pt.app_policies_section.apps; @@ -1640,10 +1646,10 @@ std::string PolicyManagerImpl::GetCCPUVersionFromPT() const { return cache_->GetCCPUVersionFromPT(); } -uint32_t PolicyManagerImpl::GetNotificationsNumber( - const std::string& priority) const { +uint32_t PolicyManagerImpl::GetNotificationsNumber(const std::string& priority, + const bool is_subtle) const { LOG4CXX_AUTO_TRACE(logger_); - return cache_->GetNotificationsNumber(priority); + return cache_->GetNotificationsNumber(priority, is_subtle); } bool PolicyManagerImpl::ExceededIgnitionCycles() { diff --git a/src/components/policy/policy_external/src/policy_table/types.cc b/src/components/policy/policy_external/src/policy_table/types.cc index f0ea154f94..6d50a8cf26 100644 --- a/src/components/policy/policy_external/src/policy_table/types.cc +++ b/src/components/policy/policy_external/src/policy_table/types.cc @@ -830,7 +830,9 @@ ModuleConfig::ModuleConfig( const SecondsBetweenRetries& seconds_between_retries, const ServiceEndpoints& endpoints, const ServiceEndpointProperties& endpoint_properties, - const NumberOfNotificationsPerMinute& notifications_per_minute_by_priority) + const NumberOfNotificationsPerMinute& notifications_per_minute_by_priority, + const NumberOfNotificationsPerMinute& + subtle_notifications_per_minute_by_priority) : CompositeType(kUninitialized) , exchange_after_x_ignition_cycles(exchange_after_x_ignition_cycles) , exchange_after_x_kilometers(exchange_after_x_kilometers) @@ -839,8 +841,9 @@ ModuleConfig::ModuleConfig( , seconds_between_retries(seconds_between_retries) , endpoints(endpoints) , endpoint_properties(endpoint_properties) - , notifications_per_minute_by_priority( - notifications_per_minute_by_priority) {} + , notifications_per_minute_by_priority(notifications_per_minute_by_priority) + , subtle_notifications_per_minute_by_priority( + subtle_notifications_per_minute_by_priority) {} ModuleConfig::~ModuleConfig() {} @@ -859,6 +862,8 @@ ModuleConfig::ModuleConfig(const Json::Value* value__) , endpoint_properties(impl::ValueMember(value__, "endpoint_properties")) , notifications_per_minute_by_priority( impl::ValueMember(value__, "notifications_per_minute_by_priority")) + , subtle_notifications_per_minute_by_priority(impl::ValueMember( + value__, "subtle_notifications_per_minute_by_priority")) , vehicle_make(impl::ValueMember(value__, "vehicle_make")) , vehicle_model(impl::ValueMember(value__, "vehicle_model")) , vehicle_year(impl::ValueMember(value__, "vehicle_year")) @@ -880,6 +885,8 @@ void ModuleConfig::SafeCopyFrom(const ModuleConfig& from) { endpoint_properties = from.endpoint_properties; notifications_per_minute_by_priority = from.notifications_per_minute_by_priority; + subtle_notifications_per_minute_by_priority = + from.subtle_notifications_per_minute_by_priority; lock_screen_dismissal_enabled = from.lock_screen_dismissal_enabled; certificate.assign_if_valid(from.certificate); @@ -910,6 +917,9 @@ Json::Value ModuleConfig::ToJsonValue() const { impl::WriteJsonField("notifications_per_minute_by_priority", notifications_per_minute_by_priority, &result__); + impl::WriteJsonField("subtle_notifications_per_minute_by_priority", + subtle_notifications_per_minute_by_priority, + &result__); impl::WriteJsonField("vehicle_make", vehicle_make, &result__); impl::WriteJsonField("vehicle_model", vehicle_model, &result__); impl::WriteJsonField("vehicle_year", vehicle_year, &result__); @@ -955,6 +965,9 @@ bool ModuleConfig::is_valid() const { if (!notifications_per_minute_by_priority.is_valid()) { return false; } + if (!subtle_notifications_per_minute_by_priority.is_valid()) { + return false; + } if (!vehicle_make.is_valid()) { return false; } @@ -1019,6 +1032,9 @@ bool ModuleConfig::struct_empty() const { if (notifications_per_minute_by_priority.is_initialized()) { return false; } + if (subtle_notifications_per_minute_by_priority.is_initialized()) { + return false; + } if (lock_screen_dismissal_enabled.is_initialized()) { return false; } @@ -1080,6 +1096,11 @@ void ModuleConfig::ReportErrors(rpc::ValidationReport* report__) const { notifications_per_minute_by_priority.ReportErrors( &report__->ReportSubobject("notifications_per_minute_by_priority")); } + if (!subtle_notifications_per_minute_by_priority.is_valid()) { + subtle_notifications_per_minute_by_priority.ReportErrors( + &report__->ReportSubobject( + "subtle_notifications_per_minute_by_priority")); + } if (!lock_screen_dismissal_enabled.is_valid()) { lock_screen_dismissal_enabled.ReportErrors( &report__->ReportSubobject("lock_screen_dismissal_enabled")); @@ -1143,6 +1164,7 @@ void ModuleConfig::SetPolicyTableType(PolicyTableType pt_type) { endpoints.SetPolicyTableType(pt_type); endpoint_properties.SetPolicyTableType(pt_type); notifications_per_minute_by_priority.SetPolicyTableType(pt_type); + subtle_notifications_per_minute_by_priority.SetPolicyTableType(pt_type); lock_screen_dismissal_enabled.SetPolicyTableType(pt_type); vehicle_make.SetPolicyTableType(pt_type); vehicle_model.SetPolicyTableType(pt_type); diff --git a/src/components/policy/policy_external/src/sql_pt_queries.cc b/src/components/policy/policy_external/src/sql_pt_queries.cc index 4f858637d7..95c82b6ea6 100644 --- a/src/components/policy/policy_external/src/sql_pt_queries.cc +++ b/src/components/policy/policy_external/src/sql_pt_queries.cc @@ -113,6 +113,17 @@ const std::string kCreateSchema = "CREATE INDEX IF NOT EXISTS " "`notifications_by_priority.fk_notifications_by_priority_priority1_idx` " " ON `notifications_by_priority`(`priority_value`); " + "CREATE TABLE IF NOT EXISTS `subtle_notifications_by_priority`( " + " `priority_value` VARCHAR(45) PRIMARY KEY NOT NULL, " + " `value` INTEGER NOT NULL, " + " CONSTRAINT `fk_subtle_notifications_by_priority_priority1` " + " FOREIGN KEY(`priority_value`) " + " REFERENCES `priority`(`value`) " + "); " + "CREATE INDEX IF NOT EXISTS " + "`subtle_notifications_by_priority.fk_subtle_notifications_by_priority_" + "priority1_idx` " + " ON `subtle_notifications_by_priority`(`priority_value`); " "CREATE TABLE IF NOT EXISTS `language`( " " `code` VARCHAR(25) PRIMARY KEY NOT NULL " "); " @@ -623,6 +634,10 @@ const std::string kDropSchema = "DROP INDEX IF EXISTS " "`notifications_by_priority.fk_notifications_by_priority_priority1_idx`; " "DROP TABLE IF EXISTS `notifications_by_priority`; " + "DROP INDEX IF EXISTS " + "`subtle_notifications_by_priority.fk_subtle_notifications_by_priority_" + "priority1_idx`; " + "DROP TABLE IF EXISTS `subtle_notifications_by_priority`; " "DROP TABLE IF EXISTS `hmi_level`; " "DROP TABLE IF EXISTS `hybrid_app_preference`; " "DROP TABLE IF EXISTS `priority`; " @@ -664,6 +679,7 @@ const std::string kDeleteData = "DELETE FROM `message_type`; " "DELETE FROM `language`; " "DELETE FROM `notifications_by_priority`; " + "DELETE FROM `subtle_notifications_by_priority`; " "DELETE FROM `hmi_level`; " "DELETE FROM `priority`; " "DELETE FROM `functional_group`; " @@ -875,6 +891,11 @@ const std::string kInsertNotificationsByPriority = "`value`) " " VALUES (?, ?)"; +const std::string kInsertSubtleNotificationsByPriority = + "INSERT OR REPLACE INTO `subtle_notifications_by_priority` " + "(`priority_value`, `value`) " + " VALUES (?, ?)"; + const std::string kInsertDeviceData = "INSERT OR IGNORE INTO `device` (`id`) VALUES (?)"; @@ -922,6 +943,9 @@ const std::string kSelectEndpoints = const std::string kSelectNotificationsPerMin = "SELECT `priority_value`, `value` FROM notifications_by_priority"; +const std::string kSelectSubtleNotificationsPerMin = + "SELECT `priority_value`, `value` FROM subtle_notifications_by_priority"; + const std::string kSelectNotificationsPerPriority = "SELECT `value` FROM notifications_by_priority WHERE `priority_value` = ? "; diff --git a/src/components/policy/policy_external/src/sql_pt_representation.cc b/src/components/policy/policy_external/src/sql_pt_representation.cc index 5e96d0bde0..d368707efa 100644 --- a/src/components/policy/policy_external/src/sql_pt_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_representation.cc @@ -563,6 +563,17 @@ void SQLPTRepresentation::GatherModuleConfig( notifications.GetInteger(1); } } + utils::dbms::SQLQuery subtle_notifications(db()); + if (!subtle_notifications.Prepare(sql_pt::kSelectSubtleNotificationsPerMin)) { + LOG4CXX_WARN(logger_, + "Incorrect select statement for subtle notifications"); + } else { + while (subtle_notifications.Next()) { + config->subtle_notifications_per_minute_by_priority[subtle_notifications + .GetString(0)] = + subtle_notifications.GetInteger(1); + } + } utils::dbms::SQLQuery seconds(db()); if (!seconds.Prepare(sql_pt::kSelectSecondsBetweenRetries)) { LOG4CXX_INFO(logger_, @@ -1534,6 +1545,11 @@ bool SQLPTRepresentation::SaveModuleConfig( return false; } + if (!SaveNumberOfSubtleNotificationsPerMinute( + config.subtle_notifications_per_minute_by_priority)) { + return false; + } + if (!SaveServiceEndpoints(config.endpoints)) { return false; } @@ -1860,6 +1876,28 @@ bool SQLPTRepresentation::SaveNumberOfNotificationsPerMinute( return true; } +bool SQLPTRepresentation::SaveNumberOfSubtleNotificationsPerMinute( + const policy_table::NumberOfNotificationsPerMinute& notifications) { + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertSubtleNotificationsByPriority)) { + LOG4CXX_WARN(logger_, + "Incorrect insert statement for notifications by priority."); + return false; + } + + policy_table::NumberOfNotificationsPerMinute::const_iterator it; + for (it = notifications.begin(); it != notifications.end(); ++it) { + query.Bind(0, it->first); + query.Bind(1, it->second); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into notifications by priority."); + return false; + } + } + + return true; +} + bool SQLPTRepresentation::SaveDeviceData( const policy_table::DeviceData& devices) { utils::dbms::SQLQuery query(db()); diff --git a/src/components/policy/policy_external/test/cache_manager_test.cc b/src/components/policy/policy_external/test/cache_manager_test.cc index 7bf13c250a..440df431db 100644 --- a/src/components/policy/policy_external/test/cache_manager_test.cc +++ b/src/components/policy/policy_external/test/cache_manager_test.cc @@ -123,23 +123,28 @@ TEST_F(CacheManagerTest, *pt_ = CreateCustomPT(string_table); std::string priority = "EMERGENCY"; - uint32_t notif_number = cache_manager_->GetNotificationsNumber(priority); + uint32_t notif_number = + cache_manager_->GetNotificationsNumber(priority, false); EXPECT_EQ(1u, notif_number); priority = "NAVIGATION"; - notif_number = cache_manager_->GetNotificationsNumber(priority); + notif_number = cache_manager_->GetNotificationsNumber(priority, false); EXPECT_EQ(2u, notif_number); priority = "VOICECOM"; - notif_number = cache_manager_->GetNotificationsNumber(priority); + notif_number = cache_manager_->GetNotificationsNumber(priority, false); EXPECT_EQ(3u, notif_number); + priority = "COMMUNICATION"; + notif_number = cache_manager_->GetNotificationsNumber(priority, false); + EXPECT_EQ(4u, notif_number); + priority = "NORMAL"; - notif_number = cache_manager_->GetNotificationsNumber(priority); + notif_number = cache_manager_->GetNotificationsNumber(priority, false); EXPECT_EQ(5u, notif_number); priority = "NONE"; - notif_number = cache_manager_->GetNotificationsNumber(priority); + notif_number = cache_manager_->GetNotificationsNumber(priority, false); EXPECT_EQ(6u, notif_number); } @@ -162,7 +167,78 @@ TEST_F(CacheManagerTest, GetNotificationsNumber_PriorityNotExist_ReturnZero) { *pt_ = CreateCustomPT(string_table); const std::string priority = "OTHER_PRIORITY"; - uint32_t notif_number = cache_manager_->GetNotificationsNumber(priority); + uint32_t notif_number = + cache_manager_->GetNotificationsNumber(priority, false); + EXPECT_EQ(0u, notif_number); +} + +TEST_F(CacheManagerTest, + GetNotificationsNumber_Subtle_PriorityExists_ReturnNumberFromPT) { + std::string string_table( + "{" + "\"policy_table\": {" + "\"module_config\": {" + "\"subtle_notifications_per_minute_by_priority\": {" + "\"EMERGENCY\": 7," + "\"NAVIGATION\": 8," + "\"VOICECOM\": 9," + "\"COMMUNICATION\": 10," + "\"NORMAL\": 11," + "\"NONE\": 12" + "}" + "}" + "}" + "}"); + *pt_ = CreateCustomPT(string_table); + + std::string priority = "EMERGENCY"; + uint32_t notif_number = + cache_manager_->GetNotificationsNumber(priority, true); + EXPECT_EQ(7u, notif_number); + + priority = "NAVIGATION"; + notif_number = cache_manager_->GetNotificationsNumber(priority, true); + EXPECT_EQ(8u, notif_number); + + priority = "VOICECOM"; + notif_number = cache_manager_->GetNotificationsNumber(priority, true); + EXPECT_EQ(9u, notif_number); + + priority = "COMMUNICATION"; + notif_number = cache_manager_->GetNotificationsNumber(priority, true); + EXPECT_EQ(10u, notif_number); + + priority = "NORMAL"; + notif_number = cache_manager_->GetNotificationsNumber(priority, true); + EXPECT_EQ(11u, notif_number); + + priority = "NONE"; + notif_number = cache_manager_->GetNotificationsNumber(priority, true); + EXPECT_EQ(12u, notif_number); +} + +TEST_F(CacheManagerTest, + GetNotificationsNumber_Subtle_PriorityNotExist_ReturnZero) { + const std::string string_table( + "{" + "\"policy_table\": {" + "\"module_config\": {" + "\"subtle_notifications_per_minute_by_priority\": {" + "\"EMERGENCY\": 7," + "\"NAVIGATION\": 8," + "\"VOICECOM\": 9," + "\"COMMUNICATION\": 10," + "\"NORMAL\": 11," + "\"NONE\": 12" + "}" + "}" + "}" + "}"); + *pt_ = CreateCustomPT(string_table); + + const std::string priority = "OTHER_PRIORITY"; + uint32_t notif_number = + cache_manager_->GetNotificationsNumber(priority, true); EXPECT_EQ(0u, notif_number); } diff --git a/src/components/policy/policy_external/test/json/sdl_preloaded_pt_for_merge_initial.json b/src/components/policy/policy_external/test/json/sdl_preloaded_pt_for_merge_initial.json index dec76dd96c..c949575190 100644 --- a/src/components/policy/policy_external/test/json/sdl_preloaded_pt_for_merge_initial.json +++ b/src/components/policy/policy_external/test/json/sdl_preloaded_pt_for_merge_initial.json @@ -2428,10 +2428,21 @@ "COMMUNICATION" : 6, "EMERGENCY" : 60, "NAVIGATION" : 15, + "PROJECTION" : 15, "NONE" : 0, "NORMAL" : 4, "VOICECOM" : 20 }, + "subtle_notifications_per_minute_by_priority": + { + "COMMUNICATION": 15, + "EMERGENCY": 60, + "NAVIGATION": 20, + "PROJECTION": 20, + "NONE": 0, + "NORMAL": 10, + "VOICECOM": 30 + }, "preloaded_date" : "2012-12-15", "preloaded_pt" : true, "seconds_between_retries" : [ 1, 5, 25, 125, 625 ], diff --git a/src/components/policy/policy_external/test/json/sdl_preloaded_pt_for_merge_latest.json b/src/components/policy/policy_external/test/json/sdl_preloaded_pt_for_merge_latest.json index 85693ff515..81c2093c72 100644 --- a/src/components/policy/policy_external/test/json/sdl_preloaded_pt_for_merge_latest.json +++ b/src/components/policy/policy_external/test/json/sdl_preloaded_pt_for_merge_latest.json @@ -2424,10 +2424,21 @@ "COMMUNICATION" : 6, "EMERGENCY" : 60, "NAVIGATION" : 15, + "PROJECTION" : 15, "NONE" : 0, "NORMAL" : 4, "VOICECOM" : 20 }, + "subtle_notifications_per_minute_by_priority": + { + "COMMUNICATION": 15, + "EMERGENCY": 60, + "NAVIGATION": 20, + "PROJECTION": 20, + "NONE": 0, + "NORMAL": 10, + "VOICECOM": 30 + }, "preloaded_date" : "2012-12-16", "preloaded_pt" : true, "seconds_between_retries" : [ 1, 5, 25, 125, 625 ], diff --git a/src/components/policy/policy_external/test/sql_pt_ext_representation_test.cc b/src/components/policy/policy_external/test/sql_pt_ext_representation_test.cc index ce51682f3c..97613550f2 100644 --- a/src/components/policy/policy_external/test/sql_pt_ext_representation_test.cc +++ b/src/components/policy/policy_external/test/sql_pt_ext_representation_test.cc @@ -306,6 +306,20 @@ TEST_F(SQLPTExtRepresentationTest, Json::Value(5); module_config["notifications_per_minute_by_priority"]["none"] = Json::Value(6); + module_config["subtle_notifications_per_minute_by_priority"] = + Json::Value(Json::objectValue); + module_config["subtle_notifications_per_minute_by_priority"]["emergency"] = + Json::Value(7); + module_config["subtle_notifications_per_minute_by_priority"]["navigation"] = + Json::Value(8); + module_config["subtle_notifications_per_minute_by_priority"]["VOICECOMM"] = + Json::Value(9); + module_config["subtle_notifications_per_minute_by_priority"] + ["communication"] = Json::Value(10); + module_config["subtle_notifications_per_minute_by_priority"]["normal"] = + Json::Value(11); + module_config["subtle_notifications_per_minute_by_priority"]["none"] = + Json::Value(12); module_config["vehicle_make"] = Json::Value("MakeT"); module_config["vehicle_model"] = Json::Value("ModelT"); module_config["vehicle_year"] = Json::Value("2014"); diff --git a/src/components/policy/policy_external/test/sql_pt_representation_test.cc b/src/components/policy/policy_external/test/sql_pt_representation_test.cc index 2cb5ec1aaf..ae3000fe7c 100644 --- a/src/components/policy/policy_external/test/sql_pt_representation_test.cc +++ b/src/components/policy/policy_external/test/sql_pt_representation_test.cc @@ -245,6 +245,20 @@ class SQLPTRepresentationTest : public SQLPTRepresentation, Json::Value(5); module_config["notifications_per_minute_by_priority"]["none"] = Json::Value(6); + module_config["subtle_notifications_per_minute_by_priority"] = + Json::Value(Json::objectValue); + module_config["subtle_notifications_per_minute_by_priority"]["emergency"] = + Json::Value(7); + module_config["subtle_notifications_per_minute_by_priority"]["navigation"] = + Json::Value(8); + module_config["subtle_notifications_per_minute_by_priority"]["VOICECOMM"] = + Json::Value(9); + module_config["subtle_notifications_per_minute_by_priority"] + ["communication"] = Json::Value(10); + module_config["subtle_notifications_per_minute_by_priority"]["normal"] = + Json::Value(11); + module_config["subtle_notifications_per_minute_by_priority"]["none"] = + Json::Value(12); module_config["vehicle_make"] = Json::Value("MakeT"); module_config["vehicle_model"] = Json::Value("ModelT"); module_config["vehicle_year"] = Json::Value("2014"); @@ -485,8 +499,8 @@ TEST_F(SQLPTRepresentationTest, query.Prepare(query_select); query.Next(); - // 41 - is current total tables number created by schema - const int policy_tables_number = 41; + // 42 - is current total tables number created by schema + const int policy_tables_number = 42; ASSERT_EQ(policy_tables_number, query.GetInteger(0)); const std::string query_select_count_of_iap_buffer_full = @@ -1712,6 +1726,7 @@ TEST_F(SQLPTRepresentationTest, EXPECT_EQ(0u, config.seconds_between_retries.size()); EXPECT_EQ(0u, config.endpoints.size()); EXPECT_EQ(0u, config.notifications_per_minute_by_priority.size()); + EXPECT_EQ(0u, config.subtle_notifications_per_minute_by_priority.size()); policy_table::ConsumerFriendlyMessages messages; GatherConsumerFriendlyMessages(&messages); @@ -1818,6 +1833,15 @@ TEST_F(SQLPTRepresentationTest, ASSERT_EQ(4, config.notifications_per_minute_by_priority["communication"]); ASSERT_EQ(5, config.notifications_per_minute_by_priority["normal"]); ASSERT_EQ(6, config.notifications_per_minute_by_priority["none"]); + ASSERT_EQ(6u, config.subtle_notifications_per_minute_by_priority.size()); + ASSERT_EQ(7, config.subtle_notifications_per_minute_by_priority["emergency"]); + ASSERT_EQ(8, + config.subtle_notifications_per_minute_by_priority["navigation"]); + ASSERT_EQ(9, config.subtle_notifications_per_minute_by_priority["VOICECOMM"]); + ASSERT_EQ( + 10, config.subtle_notifications_per_minute_by_priority["communication"]); + ASSERT_EQ(11, config.subtle_notifications_per_minute_by_priority["normal"]); + ASSERT_EQ(12, config.subtle_notifications_per_minute_by_priority["none"]); EXPECT_EQ(1u, config.endpoints.size()); policy_table::ServiceEndpoints& service_endpoints = config.endpoints; EXPECT_EQ("0x00", service_endpoints.begin()->first); diff --git a/src/components/policy/policy_regular/include/policy/cache_manager.h b/src/components/policy/policy_regular/include/policy/cache_manager.h index 053d4dc807..25b4a8bc18 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -292,13 +292,8 @@ class CacheManager : public CacheManagerInterface { */ virtual std::string GetIconUrl(const std::string& policy_app_id) const; - /** - * @brief Get allowed number of notifications - * depending on application priority. - * @param priority Priority of application - */ virtual rpc::policy_table_interface_base::NumberOfNotificationsType - GetNotificationsNumber(const std::string& priority); + GetNotificationsNumber(const std::string& priority, const bool is_subtle); /** * @brief Get priority for given application diff --git a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h index f161724671..14130c0316 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h @@ -325,9 +325,10 @@ class CacheManagerInterface { * @brief Get allowed number of notifications * depending on application priority. * @param priority Priority of application + * @param is_subtle If true, get the number of allowed subtle notifications */ virtual policy_table::NumberOfNotificationsType GetNotificationsNumber( - const std::string& priority) = 0; + const std::string& priority, const bool is_subtle) = 0; /** * @brief Get priority for given application diff --git a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h index 1b87e58310..307697dd64 100644 --- a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h @@ -458,9 +458,11 @@ class PolicyManagerImpl : public PolicyManager { /** * @brief Get number of notification by priority * @param priority Specified priority + * @param is_subtle If true, get the number of allowed subtle notifications * @return notification number */ - uint32_t GetNotificationsNumber(const std::string& priority) const OVERRIDE; + uint32_t GetNotificationsNumber(const std::string& priority, + const bool is_subtle) const OVERRIDE; /** * @brief Allows to update Vehicle Identification Number in policy table. diff --git a/src/components/policy/policy_regular/include/policy/policy_table/types.h b/src/components/policy/policy_regular/include/policy/policy_table/types.h index 1c6442501f..8ef42c822e 100644 --- a/src/components/policy/policy_regular/include/policy/policy_table/types.h +++ b/src/components/policy/policy_regular/include/policy/policy_table/types.h @@ -323,6 +323,7 @@ struct ModuleConfig : CompositeType { ServiceEndpoints endpoints; Optional<ServiceEndpointProperties> endpoint_properties; NumberOfNotificationsPerMinute notifications_per_minute_by_priority; + NumberOfNotificationsPerMinute subtle_notifications_per_minute_by_priority; Optional<String<1, 100> > vehicle_make; Optional<String<1, 100> > vehicle_model; Optional<String<4, 4> > vehicle_year; @@ -342,7 +343,9 @@ struct ModuleConfig : CompositeType { const ServiceEndpoints& endpoints, const ServiceEndpointProperties& endpoint_properties, const NumberOfNotificationsPerMinute& - notifications_per_minute_by_priority); + notifications_per_minute_by_priority, + const NumberOfNotificationsPerMinute& + subtle_notifications_per_minute_by_priority); ~ModuleConfig(); explicit ModuleConfig(const Json::Value* value__); void SafeCopyFrom(const ModuleConfig& from); diff --git a/src/components/policy/policy_regular/include/policy/sql_pt_queries.h b/src/components/policy/policy_regular/include/policy/sql_pt_queries.h index 0b0ae11f3f..5bf85a4bb5 100644 --- a/src/components/policy/policy_regular/include/policy/sql_pt_queries.h +++ b/src/components/policy/policy_regular/include/policy/sql_pt_queries.h @@ -52,6 +52,7 @@ extern const std::string kSelectEndpoint; extern const std::string kSelectModuleConfig; extern const std::string kSelectEndpoints; extern const std::string kSelectNotificationsPerMin; +extern const std::string kSelectSubtleNotificationsPerMin; extern const std::string kSelectNotificationsPerPriority; extern const std::string kSelectAppLevels; extern const std::string kSelectDeviceData; @@ -93,6 +94,7 @@ extern const std::string kUpdateModuleConfig; extern const std::string kInsertEndpoint; extern const std::string kInsertSecondsBetweenRetry; extern const std::string kInsertNotificationsByPriority; +extern const std::string kInsertSubtleNotificationsByPriority; extern const std::string kInsertDeviceData; extern const std::string kInsertAppLevel; extern const std::string kDeleteSecondsBetweenRetries; diff --git a/src/components/policy/policy_regular/include/policy/sql_pt_representation.h b/src/components/policy/policy_regular/include/policy/sql_pt_representation.h index eeeaeed2cd..512bfd6326 100644 --- a/src/components/policy/policy_regular/include/policy/sql_pt_representation.h +++ b/src/components/policy/policy_regular/include/policy/sql_pt_representation.h @@ -249,6 +249,8 @@ class SQLPTRepresentation : public virtual PTRepresentation { const policy_table::SecondsBetweenRetries& seconds); bool SaveNumberOfNotificationsPerMinute( const policy_table::NumberOfNotificationsPerMinute& notifications); + bool SaveNumberOfSubtleNotificationsPerMinute( + const policy_table::NumberOfNotificationsPerMinute& notifications); bool SaveMessageType(const std::string& type); bool SaveLanguage(const std::string& code); policy_table::VehicleDataItem PopulateVDIFromQuery( diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index 75f0e72113..97e0aa3b4d 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -1100,17 +1100,20 @@ std::string CacheManager::GetIconUrl(const std::string& policy_app_id) const { } rpc::policy_table_interface_base::NumberOfNotificationsType -CacheManager::GetNotificationsNumber(const std::string& priority) { +CacheManager::GetNotificationsNumber(const std::string& priority, + const bool is_subtle) { CACHE_MANAGER_CHECK(0); - typedef rpc::policy_table_interface_base::NumberOfNotificationsPerMinute NNPM; sync_primitives::AutoLock auto_lock(cache_lock_); - const NNPM& nnpm = - pt_->policy_table.module_config.notifications_per_minute_by_priority; + const auto& nnpm = is_subtle + ? pt_->policy_table.module_config + .subtle_notifications_per_minute_by_priority + : pt_->policy_table.module_config + .notifications_per_minute_by_priority; - NNPM::const_iterator priority_iter = nnpm.find(priority); + auto priority_iter = nnpm.find(priority); - const rpc::policy_table_interface_base::NumberOfNotificationsType result = + const uint32_t result = (nnpm.end() != priority_iter ? (*priority_iter).second : 0u); return result; } diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc index b40d71dd73..8f3f32e9cb 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -291,6 +291,12 @@ void FilterPolicyTable( FilterInvalidPriorityValues( module_config.notifications_per_minute_by_priority); } + if (module_config.is_initialized() && + module_config.subtle_notifications_per_minute_by_priority + .is_initialized()) { + FilterInvalidPriorityValues( + module_config.subtle_notifications_per_minute_by_priority); + } if (pt.app_policies_section.is_initialized()) { policy_table::ApplicationPolicies& apps = pt.app_policies_section.apps; @@ -1231,10 +1237,10 @@ std::string PolicyManagerImpl::GetCCPUVersionFromPT() const { return cache_->GetCCPUVersionFromPT(); } -uint32_t PolicyManagerImpl::GetNotificationsNumber( - const std::string& priority) const { +uint32_t PolicyManagerImpl::GetNotificationsNumber(const std::string& priority, + const bool is_subtle) const { LOG4CXX_AUTO_TRACE(logger_); - return cache_->GetNotificationsNumber(priority); + return cache_->GetNotificationsNumber(priority, is_subtle); } bool PolicyManagerImpl::ExceededIgnitionCycles() { diff --git a/src/components/policy/policy_regular/src/policy_table/types.cc b/src/components/policy/policy_regular/src/policy_table/types.cc index 1c7d06dedf..df59afe3d8 100644 --- a/src/components/policy/policy_regular/src/policy_table/types.cc +++ b/src/components/policy/policy_regular/src/policy_table/types.cc @@ -720,7 +720,9 @@ ModuleConfig::ModuleConfig( const SecondsBetweenRetries& seconds_between_retries, const ServiceEndpoints& endpoints, const ServiceEndpointProperties& endpoint_properties, - const NumberOfNotificationsPerMinute& notifications_per_minute_by_priority) + const NumberOfNotificationsPerMinute& notifications_per_minute_by_priority, + const NumberOfNotificationsPerMinute& + subtle_notifications_per_minute_by_priority) : CompositeType(kUninitialized) , exchange_after_x_ignition_cycles(exchange_after_x_ignition_cycles) , exchange_after_x_kilometers(exchange_after_x_kilometers) @@ -729,8 +731,9 @@ ModuleConfig::ModuleConfig( , seconds_between_retries(seconds_between_retries) , endpoints(endpoints) , endpoint_properties(endpoint_properties) - , notifications_per_minute_by_priority( - notifications_per_minute_by_priority) {} + , notifications_per_minute_by_priority(notifications_per_minute_by_priority) + , subtle_notifications_per_minute_by_priority( + subtle_notifications_per_minute_by_priority) {} ModuleConfig::~ModuleConfig() {} @@ -752,6 +755,8 @@ ModuleConfig::ModuleConfig(const Json::Value* value__) , endpoint_properties(impl::ValueMember(value__, "endpoint_properties")) , notifications_per_minute_by_priority( impl::ValueMember(value__, "notifications_per_minute_by_priority")) + , subtle_notifications_per_minute_by_priority(impl::ValueMember( + value__, "subtle_notifications_per_minute_by_priority")) , vehicle_make(impl::ValueMember(value__, "vehicle_make")) , vehicle_model(impl::ValueMember(value__, "vehicle_model")) , vehicle_year(impl::ValueMember(value__, "vehicle_year")) @@ -772,6 +777,8 @@ void ModuleConfig::SafeCopyFrom(const ModuleConfig& from) { endpoint_properties = from.endpoint_properties; notifications_per_minute_by_priority = from.notifications_per_minute_by_priority; + subtle_notifications_per_minute_by_priority = + from.subtle_notifications_per_minute_by_priority; lock_screen_dismissal_enabled = from.lock_screen_dismissal_enabled; @@ -802,6 +809,9 @@ Json::Value ModuleConfig::ToJsonValue() const { impl::WriteJsonField("notifications_per_minute_by_priority", notifications_per_minute_by_priority, &result__); + impl::WriteJsonField("subtle_notifications_per_minute_by_priority", + subtle_notifications_per_minute_by_priority, + &result__); impl::WriteJsonField("vehicle_make", vehicle_make, &result__); impl::WriteJsonField("vehicle_model", vehicle_model, &result__); impl::WriteJsonField("vehicle_year", vehicle_year, &result__); @@ -844,6 +854,9 @@ bool ModuleConfig::is_valid() const { if (!notifications_per_minute_by_priority.is_valid()) { return false; } + if (!subtle_notifications_per_minute_by_priority.is_valid()) { + return false; + } if (!lock_screen_dismissal_enabled.is_valid()) { return false; } @@ -906,6 +919,9 @@ bool ModuleConfig::struct_empty() const { if (notifications_per_minute_by_priority.is_initialized()) { return false; } + if (subtle_notifications_per_minute_by_priority.is_initialized()) { + return false; + } if (lock_screen_dismissal_enabled.is_initialized()) { return false; } @@ -968,6 +984,11 @@ void ModuleConfig::ReportErrors(rpc::ValidationReport* report__) const { notifications_per_minute_by_priority.ReportErrors( &report__->ReportSubobject("notifications_per_minute_by_priority")); } + if (!subtle_notifications_per_minute_by_priority.is_valid()) { + subtle_notifications_per_minute_by_priority.ReportErrors( + &report__->ReportSubobject( + "subtle_notifications_per_minute_by_priority")); + } if (!lock_screen_dismissal_enabled.is_valid()) { lock_screen_dismissal_enabled.ReportErrors( &report__->ReportSubobject("lock_screen_dismissal_enabled")); @@ -1012,6 +1033,7 @@ void ModuleConfig::SetPolicyTableType(PolicyTableType pt_type) { endpoints.SetPolicyTableType(pt_type); endpoint_properties.SetPolicyTableType(pt_type); notifications_per_minute_by_priority.SetPolicyTableType(pt_type); + subtle_notifications_per_minute_by_priority.SetPolicyTableType(pt_type); lock_screen_dismissal_enabled.SetPolicyTableType(pt_type); vehicle_make.SetPolicyTableType(pt_type); vehicle_model.SetPolicyTableType(pt_type); diff --git a/src/components/policy/policy_regular/src/sql_pt_queries.cc b/src/components/policy/policy_regular/src/sql_pt_queries.cc index 7aa853fd74..4910ee32e9 100644 --- a/src/components/policy/policy_regular/src/sql_pt_queries.cc +++ b/src/components/policy/policy_regular/src/sql_pt_queries.cc @@ -103,6 +103,20 @@ const std::string kCreateSchema = "CREATE TABLE IF NOT EXISTS `language`( " " `code` VARCHAR(25) PRIMARY KEY NOT NULL " "); " + "CREATE TABLE IF NOT EXISTS `subtle_notifications_by_priority`( " + " `priority_value` VARCHAR(45) PRIMARY KEY NOT NULL, " + " `value` INTEGER NOT NULL, " + " CONSTRAINT `fk_subtle_notifications_by_priority_priority1` " + " FOREIGN KEY(`priority_value`) " + " REFERENCES `priority`(`value`) " + "); " + "CREATE INDEX IF NOT EXISTS " + "`subtle_notifications_by_priority.fk_subtle_notifications_by_priority_" + "priority1_idx` " + " ON `subtle_notifications_by_priority`(`priority_value`); " + "CREATE TABLE IF NOT EXISTS `language`( " + " `code` VARCHAR(25) PRIMARY KEY NOT NULL " + "); " "CREATE TABLE IF NOT EXISTS `message_type`( " " `name` VARCHAR(45) PRIMARY KEY NOT NULL " "); " @@ -586,6 +600,10 @@ const std::string kDropSchema = "DROP INDEX IF EXISTS " "`notifications_by_priority.fk_notifications_by_priority_priority1_idx`; " "DROP TABLE IF EXISTS `notifications_by_priority`; " + "DROP INDEX IF EXISTS " + "`subtle_notifications_by_priority.fk_subtle_notifications_by_priority_" + "priority1_idx`; " + "DROP TABLE IF EXISTS `subtle_notifications_by_priority`; " "DROP TABLE IF EXISTS `hmi_level`; " "DROP TABLE IF EXISTS `hybrid_app_preference`; " "DROP TABLE IF EXISTS `priority`; " @@ -624,6 +642,7 @@ const std::string kDeleteData = "DELETE FROM `message_type`; " "DELETE FROM `language`; " "DELETE FROM `notifications_by_priority`; " + "DELETE FROM `subtle_notifications_by_priority`; " "DELETE FROM `hmi_level`; " "DELETE FROM `priority`; " "DELETE FROM `functional_group`; " @@ -830,6 +849,11 @@ const std::string kInsertNotificationsByPriority = "`value`) " " VALUES (?, ?)"; +const std::string kInsertSubtleNotificationsByPriority = + "INSERT OR REPLACE INTO `subtle_notifications_by_priority` " + "(`priority_value`, `value`) " + " VALUES (?, ?)"; + const std::string kInsertDeviceData = "INSERT OR IGNORE INTO `device` (`id`) VALUES (?)"; @@ -865,6 +889,9 @@ const std::string kSelectEndpoints = const std::string kSelectNotificationsPerMin = "SELECT `priority_value`, `value` FROM notifications_by_priority"; +const std::string kSelectSubtleNotificationsPerMin = + "SELECT `priority_value`, `value` FROM subtle_notifications_by_priority"; + const std::string kSelectNotificationsPerPriority = "SELECT `value` FROM notifications_by_priority WHERE `priority_value` = ? "; diff --git a/src/components/policy/policy_regular/src/sql_pt_representation.cc b/src/components/policy/policy_regular/src/sql_pt_representation.cc index bd4dc6e2c2..8ad278ec72 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -551,6 +551,17 @@ void SQLPTRepresentation::GatherModuleConfig( notifications.GetInteger(1); } } + utils::dbms::SQLQuery subtle_notifications(db()); + if (!subtle_notifications.Prepare(sql_pt::kSelectSubtleNotificationsPerMin)) { + LOG4CXX_WARN(logger_, + "Incorrect select statement for subtle notifications"); + } else { + while (subtle_notifications.Next()) { + config->subtle_notifications_per_minute_by_priority[subtle_notifications + .GetString(0)] = + subtle_notifications.GetInteger(1); + } + } utils::dbms::SQLQuery seconds(db()); if (!seconds.Prepare(sql_pt::kSelectSecondsBetweenRetries)) { LOG4CXX_INFO(logger_, @@ -1480,6 +1491,11 @@ bool SQLPTRepresentation::SaveModuleConfig( return false; } + if (!SaveNumberOfSubtleNotificationsPerMinute( + config.subtle_notifications_per_minute_by_priority)) { + return false; + } + if (!SaveServiceEndpoints(config.endpoints)) { return false; } @@ -1723,6 +1739,28 @@ bool SQLPTRepresentation::SaveNumberOfNotificationsPerMinute( return true; } +bool SQLPTRepresentation::SaveNumberOfSubtleNotificationsPerMinute( + const policy_table::NumberOfNotificationsPerMinute& notifications) { + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertSubtleNotificationsByPriority)) { + LOG4CXX_WARN(logger_, + "Incorrect insert statement for notifications by priority."); + return false; + } + + policy_table::NumberOfNotificationsPerMinute::const_iterator it; + for (it = notifications.begin(); it != notifications.end(); ++it) { + query.Bind(0, it->first); + query.Bind(1, it->second); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into notifications by priority."); + return false; + } + } + + return true; +} + bool SQLPTRepresentation::SaveDeviceData( const policy_table::DeviceData& devices) { utils::dbms::SQLQuery query(db()); diff --git a/src/components/policy/policy_regular/test/cache_manager_test.cc b/src/components/policy/policy_regular/test/cache_manager_test.cc index 206ee53604..5666de03b0 100644 --- a/src/components/policy/policy_regular/test/cache_manager_test.cc +++ b/src/components/policy/policy_regular/test/cache_manager_test.cc @@ -122,23 +122,28 @@ TEST_F(CacheManagerTest, *pt_ = CreateCustomPT(string_table); std::string priority = "EMERGENCY"; - uint32_t notif_number = cache_manager_->GetNotificationsNumber(priority); + uint32_t notif_number = + cache_manager_->GetNotificationsNumber(priority, false); EXPECT_EQ(1u, notif_number); priority = "NAVIGATION"; - notif_number = cache_manager_->GetNotificationsNumber(priority); + notif_number = cache_manager_->GetNotificationsNumber(priority, false); EXPECT_EQ(2u, notif_number); priority = "VOICECOM"; - notif_number = cache_manager_->GetNotificationsNumber(priority); + notif_number = cache_manager_->GetNotificationsNumber(priority, false); EXPECT_EQ(3u, notif_number); + priority = "COMMUNICATION"; + notif_number = cache_manager_->GetNotificationsNumber(priority, false); + EXPECT_EQ(4u, notif_number); + priority = "NORMAL"; - notif_number = cache_manager_->GetNotificationsNumber(priority); + notif_number = cache_manager_->GetNotificationsNumber(priority, false); EXPECT_EQ(5u, notif_number); priority = "NONE"; - notif_number = cache_manager_->GetNotificationsNumber(priority); + notif_number = cache_manager_->GetNotificationsNumber(priority, false); EXPECT_EQ(6u, notif_number); } @@ -162,7 +167,78 @@ TEST_F(CacheManagerTest, GetNotificationsNumber_PriorityNotExist_ReturnZero) { *pt_ = CreateCustomPT(string_table); std::string priority = "OTHER_PRIORITY"; - uint32_t notif_number = cache_manager_->GetNotificationsNumber(priority); + uint32_t notif_number = + cache_manager_->GetNotificationsNumber(priority, false); + EXPECT_EQ(0u, notif_number); +} + +TEST_F(CacheManagerTest, + GetNotificationsNumber_Subtle_PriorityExists_ReturnNumberFromPT) { + std::string string_table( + "{" + "\"policy_table\": {" + "\"module_config\": {" + "\"subtle_notifications_per_minute_by_priority\": {" + "\"EMERGENCY\": 7," + "\"NAVIGATION\": 8," + "\"VOICECOM\": 9," + "\"COMMUNICATION\": 10," + "\"NORMAL\": 11," + "\"NONE\": 12" + "}" + "}" + "}" + "}"); + *pt_ = CreateCustomPT(string_table); + + std::string priority = "EMERGENCY"; + uint32_t notif_number = + cache_manager_->GetNotificationsNumber(priority, true); + EXPECT_EQ(7u, notif_number); + + priority = "NAVIGATION"; + notif_number = cache_manager_->GetNotificationsNumber(priority, true); + EXPECT_EQ(8u, notif_number); + + priority = "VOICECOM"; + notif_number = cache_manager_->GetNotificationsNumber(priority, true); + EXPECT_EQ(9u, notif_number); + + priority = "COMMUNICATION"; + notif_number = cache_manager_->GetNotificationsNumber(priority, true); + EXPECT_EQ(10u, notif_number); + + priority = "NORMAL"; + notif_number = cache_manager_->GetNotificationsNumber(priority, true); + EXPECT_EQ(11u, notif_number); + + priority = "NONE"; + notif_number = cache_manager_->GetNotificationsNumber(priority, true); + EXPECT_EQ(12u, notif_number); +} + +TEST_F(CacheManagerTest, + GetNotificationsNumber_Subtle_PriorityNotExist_ReturnZero) { + const std::string string_table( + "{" + "\"policy_table\": {" + "\"module_config\": {" + "\"subtle_notifications_per_minute_by_priority\": {" + "\"EMERGENCY\": 7," + "\"NAVIGATION\": 8," + "\"VOICECOM\": 9," + "\"COMMUNICATION\": 10," + "\"NORMAL\": 11," + "\"NONE\": 12" + "}" + "}" + "}" + "}"); + *pt_ = CreateCustomPT(string_table); + + const std::string priority = "OTHER_PRIORITY"; + uint32_t notif_number = + cache_manager_->GetNotificationsNumber(priority, true); EXPECT_EQ(0u, notif_number); } diff --git a/src/components/policy/policy_regular/test/include/policy/mock_pt_representation.h b/src/components/policy/policy_regular/test/include/policy/mock_pt_representation.h index 8cf3884c11..80aab3fde5 100644 --- a/src/components/policy/policy_regular/test/include/policy/mock_pt_representation.h +++ b/src/components/policy/policy_regular/test/include/policy/mock_pt_representation.h @@ -70,7 +70,8 @@ class MockPTRepresentation : virtual public PTRepresentation { std::vector<UserFriendlyMessage>(const std::vector<std::string>& msg_code, const std::string& language)); MOCK_METHOD2(GetUpdateUrls, void(int service_type, EndpointUrls&)); - MOCK_METHOD1(GetNotificationsNumber, int(const std::string& priority)); + MOCK_METHOD2(GetNotificationsNumber, + int(const std::string& priority, const bool is_subtle)); MOCK_METHOD0(Init, InitResult()); MOCK_METHOD0(Close, bool()); MOCK_METHOD0(Clear, bool()); diff --git a/src/components/policy/policy_regular/test/json/sdl_preloaded_pt_for_merge_initial.json b/src/components/policy/policy_regular/test/json/sdl_preloaded_pt_for_merge_initial.json index 3855ccd481..d17a4b82e4 100644 --- a/src/components/policy/policy_regular/test/json/sdl_preloaded_pt_for_merge_initial.json +++ b/src/components/policy/policy_regular/test/json/sdl_preloaded_pt_for_merge_initial.json @@ -2424,10 +2424,21 @@ "COMMUNICATION" : 6, "EMERGENCY" : 60, "NAVIGATION" : 15, + "PROJECTION" : 15, "NONE" : 0, "NORMAL" : 4, "VOICECOM" : 20 }, + "subtle_notifications_per_minute_by_priority": + { + "COMMUNICATION": 15, + "EMERGENCY": 60, + "NAVIGATION": 20, + "PROJECTION": 20, + "NONE": 0, + "NORMAL": 10, + "VOICECOM": 30 + }, "preloaded_date" : "2012-12-15", "preloaded_pt" : true, "seconds_between_retries" : [ 1, 5, 25, 125, 625 ], diff --git a/src/components/policy/policy_regular/test/json/sdl_preloaded_pt_for_merge_latest.json b/src/components/policy/policy_regular/test/json/sdl_preloaded_pt_for_merge_latest.json index 85693ff515..81c2093c72 100644 --- a/src/components/policy/policy_regular/test/json/sdl_preloaded_pt_for_merge_latest.json +++ b/src/components/policy/policy_regular/test/json/sdl_preloaded_pt_for_merge_latest.json @@ -2424,10 +2424,21 @@ "COMMUNICATION" : 6, "EMERGENCY" : 60, "NAVIGATION" : 15, + "PROJECTION" : 15, "NONE" : 0, "NORMAL" : 4, "VOICECOM" : 20 }, + "subtle_notifications_per_minute_by_priority": + { + "COMMUNICATION": 15, + "EMERGENCY": 60, + "NAVIGATION": 20, + "PROJECTION": 20, + "NONE": 0, + "NORMAL": 10, + "VOICECOM": 30 + }, "preloaded_date" : "2012-12-16", "preloaded_pt" : true, "seconds_between_retries" : [ 1, 5, 25, 125, 625 ], diff --git a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc index eadcd0ba4f..8da9158999 100644 --- a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc +++ b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc @@ -250,6 +250,20 @@ class SQLPTRepresentationTest : protected SQLPTRepresentation, Json::Value(5); module_config["notifications_per_minute_by_priority"]["none"] = Json::Value(6); + module_config["subtle_notifications_per_minute_by_priority"] = + Json::Value(Json::objectValue); + module_config["subtle_notifications_per_minute_by_priority"]["emergency"] = + Json::Value(7); + module_config["subtle_notifications_per_minute_by_priority"]["navigation"] = + Json::Value(8); + module_config["subtle_notifications_per_minute_by_priority"]["VOICECOMM"] = + Json::Value(9); + module_config["subtle_notifications_per_minute_by_priority"] + ["communication"] = Json::Value(10); + module_config["subtle_notifications_per_minute_by_priority"]["normal"] = + Json::Value(11); + module_config["subtle_notifications_per_minute_by_priority"]["none"] = + Json::Value(12); module_config["vehicle_make"] = Json::Value(""); module_config["vehicle_model"] = Json::Value(""); module_config["vehicle_year"] = Json::Value(""); @@ -589,8 +603,8 @@ TEST_F(SQLPTRepresentationTest, ASSERT_TRUE(reps->RefreshDB()); // Check PT structure destroyed and tables number is 0 - // There are 37 tables in the database, now. - const int32_t total_tables_number = 37; + // There are 38 tables in the database, now. + const int32_t total_tables_number = 38; ASSERT_EQ(total_tables_number, FetchOneInt(query_select)); const std::string query_select_count_of_iap_buffer_full = @@ -1879,6 +1893,7 @@ TEST_F(SQLPTRepresentationTest, Save_SetPolicyTableThenSave_ExpectSavedToPT) { EXPECT_EQ(0u, config.seconds_between_retries.size()); EXPECT_EQ(0u, config.endpoints.size()); EXPECT_EQ(0u, config.notifications_per_minute_by_priority.size()); + EXPECT_EQ(0u, config.subtle_notifications_per_minute_by_priority.size()); policy_table::ConsumerFriendlyMessages messages; GatherConsumerFriendlyMessages(&messages); @@ -1986,6 +2001,15 @@ TEST_F(SQLPTRepresentationTest, Save_SetPolicyTableThenSave_ExpectSavedToPT) { ASSERT_EQ(4, config.notifications_per_minute_by_priority["communication"]); ASSERT_EQ(5, config.notifications_per_minute_by_priority["normal"]); ASSERT_EQ(6, config.notifications_per_minute_by_priority["none"]); + ASSERT_EQ(6u, config.subtle_notifications_per_minute_by_priority.size()); + ASSERT_EQ(7, config.subtle_notifications_per_minute_by_priority["emergency"]); + ASSERT_EQ(8, + config.subtle_notifications_per_minute_by_priority["navigation"]); + ASSERT_EQ(9, config.subtle_notifications_per_minute_by_priority["VOICECOMM"]); + ASSERT_EQ( + 10, config.subtle_notifications_per_minute_by_priority["communication"]); + ASSERT_EQ(11, config.subtle_notifications_per_minute_by_priority["normal"]); + ASSERT_EQ(12, config.subtle_notifications_per_minute_by_priority["none"]); EXPECT_EQ(1u, config.endpoints.size()); policy_table::ServiceEndpoints& service_endpoints = config.endpoints; EXPECT_EQ("0x00", service_endpoints.begin()->first); |