From e7af1061be064f983f64a837f665d3d4d51c601c Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 17 Dec 2018 17:49:46 +0000 Subject: Add lock_screen_dismissal_enabled to API and policy --- src/appMain/sdl_preloaded_pt.json | 3 ++- src/components/interfaces/MOBILE_API.xml | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/appMain/sdl_preloaded_pt.json b/src/appMain/sdl_preloaded_pt.json index 2630d8bd8e..3888650ed2 100644 --- a/src/appMain/sdl_preloaded_pt.json +++ b/src/appMain/sdl_preloaded_pt.json @@ -33,7 +33,8 @@ "COMMUNICATION": 6, "NORMAL": 4, "NONE": 0 - } + }, + "lock_screen_dismissal_enabled": true }, "functional_groupings": { "Base-4": { diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml index fb6e9dc95e..970a4805fb 100644 --- a/src/components/interfaces/MOBILE_API.xml +++ b/src/components/interfaces/MOBILE_API.xml @@ -7554,6 +7554,13 @@ Current State of Driver Distraction + + + If enabled, the lock screen will be able to be dismissed while connected to SDL, allowing users + the ability to interact with the app. Dismissals should include a warning to the user and ensure + that they are not the driver. + + -- cgit v1.2.1 From cba71653afd3ee68ae97b47505391db821aaac8d Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 17 Dec 2018 17:52:33 +0000 Subject: Add lock_screen_dismissal_enabled to Policy databse Removed debug logs --- .../include/policy/policy_table/types.h | 1 + .../policy/policy_external/src/policy_table/types.cc | 20 ++++++++++++++++++-- .../policy/policy_external/src/sql_pt_queries.cc | 10 ++++++---- .../policy_external/src/sql_pt_representation.cc | 7 +++++++ .../include/policy/policy_table/types.h | 1 + .../policy/policy_regular/src/policy_table/types.cc | 20 +++++++++++++++++++- .../policy/policy_regular/src/sql_pt_queries.cc | 11 ++++++----- .../policy_regular/src/sql_pt_representation.cc | 7 ++++++- 8 files changed, 64 insertions(+), 13 deletions(-) (limited to 'src') 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 994fd86579..8795e2690f 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 @@ -364,6 +364,7 @@ struct ModuleConfig : CompositeType { Optional > certificate; Optional preloaded_pt; Optional full_app_id_supported; + Optional lock_screen_dismissal_enabled; public: ModuleConfig(); 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 ca3f8a1648..d39b3f7623 100644 --- a/src/components/policy/policy_external/src/policy_table/types.cc +++ b/src/components/policy/policy_external/src/policy_table/types.cc @@ -788,8 +788,9 @@ ModuleConfig::ModuleConfig(const Json::Value* value__) , preloaded_date(impl::ValueMember(value__, "preloaded_date")) , certificate(impl::ValueMember(value__, "certificate")) , preloaded_pt(impl::ValueMember(value__, "preloaded_pt")) - , full_app_id_supported( - impl::ValueMember(value__, "full_app_id_supported")) {} + , full_app_id_supported(impl::ValueMember(value__, "full_app_id_supported")) + , lock_screen_dismissal_enabled( + impl::ValueMember(value__, "lock_screen_dismissal_enabled")) {} void ModuleConfig::SafeCopyFrom(const ModuleConfig& from) { exchange_after_x_days = from.exchange_after_x_days; @@ -801,6 +802,7 @@ void ModuleConfig::SafeCopyFrom(const ModuleConfig& from) { endpoints = from.endpoints; notifications_per_minute_by_priority = from.notifications_per_minute_by_priority; + lock_screen_dismissal_enabled = from.lock_screen_dismissal_enabled; certificate.assign_if_valid(from.certificate); vehicle_make.assign_if_valid(from.vehicle_make); @@ -834,6 +836,9 @@ Json::Value ModuleConfig::ToJsonValue() const { impl::WriteJsonField("vehicle_year", vehicle_year, &result__); impl::WriteJsonField("certificate", certificate, &result__); impl::WriteJsonField("preloaded_date", preloaded_date, &result__); + impl::WriteJsonField("lock_screen_dismissal_enabled", + lock_screen_dismissal_enabled, + &result__); return result__; } @@ -883,6 +888,9 @@ bool ModuleConfig::is_valid() const { if (!preloaded_date.is_valid()) { return false; } + if (!lock_screen_dismissal_enabled.is_valid()) { + return false; + } return Validate(); } @@ -925,6 +933,9 @@ bool ModuleConfig::struct_empty() const { if (notifications_per_minute_by_priority.is_initialized()) { return false; } + if (lock_screen_dismissal_enabled.is_initialized()) { + return false; + } if (vehicle_make.is_initialized()) { return false; } @@ -979,6 +990,10 @@ void ModuleConfig::ReportErrors(rpc::ValidationReport* report__) const { notifications_per_minute_by_priority.ReportErrors( &report__->ReportSubobject("notifications_per_minute_by_priority")); } + if (!lock_screen_dismissal_enabled.is_valid()) { + lock_screen_dismissal_enabled.ReportErrors( + &report__->ReportSubobject("lock_screen_dismissal_enabled")); + } if (!vehicle_make.is_valid()) { vehicle_make.ReportErrors(&report__->ReportSubobject("vehicle_make")); } @@ -1037,6 +1052,7 @@ void ModuleConfig::SetPolicyTableType(PolicyTableType pt_type) { seconds_between_retries.SetPolicyTableType(pt_type); endpoints.SetPolicyTableType(pt_type); 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); vehicle_year.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 f4cac214a5..5592fdecd8 100644 --- a/src/components/policy/policy_external/src/sql_pt_queries.cc +++ b/src/components/policy/policy_external/src/sql_pt_queries.cc @@ -76,7 +76,8 @@ const std::string kCreateSchema = " `vehicle_model` VARCHAR(45), " " `vehicle_year` VARCHAR(4), " " `preloaded_date` VARCHAR (10), " - " `certificate` VARCHAR (45) " + " `certificate` VARCHAR (45), " + " `lock_screen_dismissal_enabled` BOOL" "); " "CREATE TABLE IF NOT EXISTS `functional_group`( " " `id` INTEGER PRIMARY KEY NOT NULL, " @@ -459,7 +460,7 @@ const std::string kInsertInitData = " VALUES (0, 0, 0, 0); " "INSERT OR IGNORE INTO `module_config` (`preloaded_pt`, `is_first_run`," " `exchange_after_x_ignition_cycles`, `exchange_after_x_kilometers`, " - " `exchange_after_x_days`, `timeout_after_x_seconds`) " + " `exchange_after_x_days`, `timeout_after_x_seconds`)" " VALUES(1, 0, 0, 0, 0, 0); " "INSERT OR IGNORE INTO `priority`(`value`) VALUES ('EMERGENCY'); " "INSERT OR IGNORE INTO `priority`(`value`) VALUES ('NAVIGATION'); " @@ -734,7 +735,7 @@ const std::string kUpdateModuleConfig = " `exchange_after_x_kilometers` = ?, `exchange_after_x_days` = ?, " " `timeout_after_x_seconds` = ?, `vehicle_make` = ?, " " `vehicle_model` = ?, `vehicle_year` = ?, `preloaded_date` = ?, " - " `certificate` = ? "; + " `certificate` = ?, lock_screen_dismissal_enabled = ?"; const std::string kInsertEndpoint = "INSERT INTO `endpoint` (`service`, `url`, `application_id`) " @@ -785,7 +786,8 @@ const std::string kSelectModuleConfig = "SELECT `preloaded_pt`, `exchange_after_x_ignition_cycles`, " " `exchange_after_x_kilometers`, `exchange_after_x_days`, " " `timeout_after_x_seconds`, `vehicle_make`," - " `vehicle_model`, `vehicle_year`, `preloaded_date`, `certificate` " + " `vehicle_model`, `vehicle_year`, `preloaded_date`, `certificate`, " + " `lock_screen_dismissal_enabled` " " FROM `module_config`"; const std::string kSelectEndpoints = 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 1bb0cf0fa1..d5950f9d42 100644 --- a/src/components/policy/policy_external/src/sql_pt_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_representation.cc @@ -552,6 +552,9 @@ void SQLPTRepresentation::GatherModuleConfig( *config->vehicle_year = query.GetString(7); *config->preloaded_date = query.GetString(8); *config->certificate = query.GetString(9); + if (!query.IsNull(10)) { + *config->lock_screen_dismissal_enabled = query.GetBoolean(10); + } } utils::dbms::SQLQuery endpoints(db()); @@ -1412,6 +1415,10 @@ bool SQLPTRepresentation::SaveModuleConfig( config.certificate.is_initialized() ? query.Bind(9, *(config.certificate)) : query.Bind(9); + config.lock_screen_dismissal_enabled.is_initialized() + ? query.Bind(10, *(config.lock_screen_dismissal_enabled)) + : query.Bind(10); + if (!query.Exec()) { LOG4CXX_WARN(logger_, "Incorrect update module config"); return false; 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 e41069a86c..c2a8f901ad 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 @@ -302,6 +302,7 @@ struct ModuleConfig : CompositeType { Optional > vehicle_year; Optional > preloaded_date; Optional > certificate; + Optional lock_screen_dismissal_enabled; public: ModuleConfig(); 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 bdf1329dee..7fdfde996c 100644 --- a/src/components/policy/policy_regular/src/policy_table/types.cc +++ b/src/components/policy/policy_regular/src/policy_table/types.cc @@ -678,7 +678,9 @@ ModuleConfig::ModuleConfig(const Json::Value* value__) , vehicle_model(impl::ValueMember(value__, "vehicle_model")) , vehicle_year(impl::ValueMember(value__, "vehicle_year")) , preloaded_date(impl::ValueMember(value__, "preloaded_date")) - , certificate(impl::ValueMember(value__, "certificate")) {} + , certificate(impl::ValueMember(value__, "certificate")) + , lock_screen_dismissal_enabled( + impl::ValueMember(value__, "lock_screen_dismissal_enabled")) {} void ModuleConfig::SafeCopyFrom(const ModuleConfig& from) { // device_certificates = from.device_certificates; // According to the @@ -692,6 +694,8 @@ void ModuleConfig::SafeCopyFrom(const ModuleConfig& from) { notifications_per_minute_by_priority = from.notifications_per_minute_by_priority; + lock_screen_dismissal_enabled = from.lock_screen_dismissal_enabled; + vehicle_make.assign_if_valid(from.vehicle_make); vehicle_model.assign_if_valid(from.vehicle_model); vehicle_year.assign_if_valid(from.vehicle_year); @@ -723,6 +727,9 @@ Json::Value ModuleConfig::ToJsonValue() const { impl::WriteJsonField("vehicle_year", vehicle_year, &result__); impl::WriteJsonField("certificate", certificate, &result__); impl::WriteJsonField("preloaded_date", preloaded_date, &result__); + impl::WriteJsonField("lock_screen_dismissal_enabled", + lock_screen_dismissal_enabled, + &result__); return result__; } @@ -754,6 +761,9 @@ bool ModuleConfig::is_valid() const { if (!notifications_per_minute_by_priority.is_valid()) { return false; } + if (!lock_screen_dismissal_enabled.is_valid()) { + return false; + } if (!vehicle_make.is_valid()) { return false; } @@ -808,6 +818,9 @@ bool ModuleConfig::struct_empty() const { if (notifications_per_minute_by_priority.is_initialized()) { return false; } + if (lock_screen_dismissal_enabled.is_initialized()) { + return false; + } if (vehicle_make.is_initialized()) { return false; } @@ -863,6 +876,10 @@ void ModuleConfig::ReportErrors(rpc::ValidationReport* report__) const { notifications_per_minute_by_priority.ReportErrors( &report__->ReportSubobject("notifications_per_minute_by_priority")); } + if (!lock_screen_dismissal_enabled.is_valid()) { + lock_screen_dismissal_enabled.ReportErrors( + &report__->ReportSubobject("lock_screen_dismissal_enabled")); + } if (!vehicle_make.is_valid()) { vehicle_make.ReportErrors(&report__->ReportSubobject("vehicle_make")); } @@ -902,6 +919,7 @@ void ModuleConfig::SetPolicyTableType(PolicyTableType pt_type) { seconds_between_retries.SetPolicyTableType(pt_type); endpoints.SetPolicyTableType(pt_type); 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); vehicle_year.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 a97b0ab153..ab57ab989f 100644 --- a/src/components/policy/policy_regular/src/sql_pt_queries.cc +++ b/src/components/policy/policy_regular/src/sql_pt_queries.cc @@ -71,7 +71,8 @@ const std::string kCreateSchema = " `certificate` TEXT, " " `vehicle_make` VARCHAR(45), " " `vehicle_model` VARCHAR(45), " - " `vehicle_year` VARCHAR(4) " + " `vehicle_year` VARCHAR(4), " + " `lock_screen_dismissal_enabled` BOOL" "); " "CREATE TABLE IF NOT EXISTS `functional_group`( " " `id` INTEGER PRIMARY KEY NOT NULL, " @@ -419,7 +420,7 @@ const std::string kInsertInitData = " VALUES (0, 0, 0, 0); " "INSERT OR IGNORE INTO `module_config` (`preloaded_pt`, `is_first_run`," " `exchange_after_x_ignition_cycles`, `exchange_after_x_kilometers`, " - " `exchange_after_x_days`, `timeout_after_x_seconds`) " + " `exchange_after_x_days`, `timeout_after_x_seconds`)" " VALUES(1, 0, 0, 0, 0, 0); " "INSERT OR IGNORE INTO `priority`(`value`) VALUES ('EMERGENCY'); " "INSERT OR IGNORE INTO `priority`(`value`) VALUES ('NAVIGATION'); " @@ -682,7 +683,8 @@ const std::string kUpdateModuleConfig = " `exchange_after_x_ignition_cycles` = ?," " `exchange_after_x_kilometers` = ?, `exchange_after_x_days` = ?, " " `timeout_after_x_seconds` = ?, `certificate` = ?, `vehicle_make` = ?, " - " `vehicle_model` = ?, `vehicle_year` = ? "; + " `vehicle_model` = ?, `vehicle_year` = ?, lock_screen_dismissal_enabled " + "= ?"; const std::string kInsertEndpoint = "INSERT INTO `endpoint` (`service`, `url`, `application_id`) " @@ -722,7 +724,7 @@ const std::string kSelectModuleConfig = "SELECT `preloaded_pt`, `exchange_after_x_ignition_cycles`, " " `exchange_after_x_kilometers`, `exchange_after_x_days`, " " `timeout_after_x_seconds`, `certificate`, `vehicle_make`," - " `vehicle_model`, `vehicle_year` " + " `vehicle_model`, `vehicle_year` ,`lock_screen_dismissal_enabled`" " FROM `module_config`"; const std::string kSelectEndpoints = @@ -907,6 +909,5 @@ const std::string kSaveModuleMeta = "`ignition_cycles_since_last_exchange` = ? "; const std::string kSelectModuleMeta = "SELECT* FROM `module_meta`"; - } // namespace sql_pt } // namespace policy 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 20ba9ec651..bcd3322b0d 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -525,7 +525,9 @@ void SQLPTRepresentation::GatherModuleConfig( *config->vehicle_make = query.GetString(6); *config->vehicle_model = query.GetString(7); *config->vehicle_year = query.GetString(8); - *config->preloaded_date = query.GetString(9); + if (!query.IsNull(9)) { + *config->lock_screen_dismissal_enabled = query.GetBoolean(9); + } } utils::dbms::SQLQuery endpoints(db()); @@ -1365,6 +1367,9 @@ bool SQLPTRepresentation::SaveModuleConfig( : query.Bind(7); config.vehicle_year.is_initialized() ? query.Bind(8, *(config.vehicle_year)) : query.Bind(8); + config.lock_screen_dismissal_enabled.is_initialized() + ? query.Bind(9, *(config.lock_screen_dismissal_enabled)) + : query.Bind(9); if (!query.Exec()) { LOG4CXX_WARN(logger_, "Incorrect update module config"); return false; -- cgit v1.2.1 From 4f46c006c75c79adefa6071bbca8d8b3eeb6135a Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 17 Dec 2018 17:54:58 +0000 Subject: Add lock_screen_dismissal_enabled to Policy Interface Removed redundant comments of overridden functions --- .../application_manager/policies/policy_handler.h | 1 + .../test/commands/hmi/hmi_notifications_test.cc | 27 +++++++++++++++++++--- .../hmi/on_driver_distraction_notification_test.cc | 22 ++++++++++-------- .../src/policies/policy_handler.cc | 6 +++++ .../policies/policy_handler_interface.h | 5 ++++ .../policy_external/policy/policy_listener.h | 6 +++++ .../policy/policy_external/policy/policy_manager.h | 10 ++++++++ .../policy/policy_regular/policy/policy_manager.h | 11 +++++++++ .../policies/mock_policy_handler_interface.h | 2 ++ .../policy_external/policy/mock_cache_manager.h | 2 ++ .../policy_external/policy/mock_policy_manager.h | 2 ++ .../policy_regular/policy/mock_cache_manager.h | 2 ++ .../policy_regular/policy/mock_policy_manager.h | 2 ++ .../policy_external/include/policy/cache_manager.h | 3 +++ .../include/policy/cache_manager_interface.h | 10 ++++++++ .../include/policy/policy_manager_impl.h | 2 ++ .../policy/policy_external/src/cache_manager.cc | 12 ++++++++++ .../policy_external/src/policy_manager_impl.cc | 6 +++++ .../policy_regular/include/policy/cache_manager.h | 2 ++ .../include/policy/cache_manager_interface.h | 11 +++++++++ .../include/policy/policy_manager_impl.h | 13 +++++++++++ .../policy/policy_regular/src/cache_manager.cc | 16 +++++++++++++ .../policy_regular/src/policy_manager_impl.cc | 16 +++++++++++++ 23 files changed, 177 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index abffd3eebb..68ab57ff64 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -204,6 +204,7 @@ class PolicyHandler : public PolicyHandlerInterface, uint32_t TimeoutExchangeMSec() const OVERRIDE; void OnExceededTimeout() OVERRIDE; void OnSystemReady() OVERRIDE; + const boost::optional LockScreenDismissalEnabledState() const OVERRIDE; void PTUpdatedAt(Counters counter, int value) OVERRIDE; void add_listener(PolicyHandlerObserver* listener) OVERRIDE; void remove_listener(PolicyHandlerObserver* listener) OVERRIDE; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc index 8f2feed877..1653889789 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc @@ -1797,7 +1797,14 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) { CreateCommand(message); EXPECT_CALL(app_mngr_, set_driver_distraction_state(state)); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + + ON_CALL(app_mngr_, GetPolicyHandler()) + .WillByDefault(ReturnRef(mock_policy_handler_)); + typedef boost::optional OptionalBool; + ON_CALL(mock_policy_handler_, LockScreenDismissalEnabledState()) + .WillByDefault(Return(OptionalBool(true))); + ON_CALL(app_mngr_, applications()).WillByDefault(Return(applications_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); EXPECT_CALL(*app_ptr_, app_id()).Times(0); command->Run(); @@ -1814,7 +1821,14 @@ TEST_F(HMICommandsNotificationsTest, ApplicationSharedPtr invalid_app; application_set_.insert(invalid_app); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + + ON_CALL(app_mngr_, GetPolicyHandler()) + .WillByDefault(ReturnRef(mock_policy_handler_)); + typedef boost::optional OptionalBool; + ON_CALL(mock_policy_handler_, LockScreenDismissalEnabledState()) + .WillByDefault(Return(OptionalBool(true))); + ON_CALL(app_mngr_, applications()).WillByDefault(Return(applications_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); EXPECT_CALL(*app_ptr_, app_id()).Times(0); command->Run(); @@ -1829,7 +1843,14 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationValidApp) { CreateCommand(message); application_set_.insert(app_); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + + ON_CALL(app_mngr_, GetPolicyHandler()) + .WillByDefault(ReturnRef(mock_policy_handler_)); + typedef boost::optional OptionalBool; + ON_CALL(mock_policy_handler_, LockScreenDismissalEnabledState()) + .WillByDefault(Return(OptionalBool(true))); + ON_CALL(app_mngr_, applications()).WillByDefault(Return(applications_)); + policy::CheckPermissionResult result; result.hmi_level_permitted = policy::kRpcAllowed; EXPECT_CALL(app_mngr_, GetPolicyHandler()) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc index 802ad01d0b..52732de56d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc @@ -65,7 +65,17 @@ class HMIOnDriverDistractionNotificationTest : public CommandsTest { public: HMIOnDriverDistractionNotificationTest() - : app_set_lock_(std::make_shared()) {} + : mock_app_(CreateMockApp()) + , app_set_lock_(std::make_shared()) + , accessor(app_set_, app_set_lock_) { + app_set_.insert(mock_app_); + InitMocksRelations(); + } + + typedef std::shared_ptr NotificationPtr; + typedef boost::optional OptionalBool; + + MockAppPtr mock_app_; std::shared_ptr app_set_lock_; policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; }; @@ -128,14 +138,8 @@ TEST_F(HMIOnDriverDistractionNotificationTest, NotificationPtr command( CreateCommand(commands_msg)); - EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); - - MockAppPtr mock_app = CreateMockApp(); - am::ApplicationSet app_set; - app_set.insert(mock_app); - - DataAccessor accessor(app_set, app_set_lock_); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + ON_CALL(mock_policy_handler_interface_, LockScreenDismissalEnabledState()) + .WillByDefault(Return(boost::optional())); policy::CheckPermissionResult result; result.hmi_level_permitted = policy::kRpcAllowed; diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index bee88633c1..72424b74f9 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1574,6 +1574,12 @@ void PolicyHandler::OnSystemReady() { policy_manager_->OnSystemReady(); } +const boost::optional PolicyHandler::LockScreenDismissalEnabledState() + const { + POLICY_LIB_CHECK(boost::optional()); + return policy_manager_->LockScreenDismissalEnabledState(); +} + void PolicyHandler::PTUpdatedAt(Counters counter, int value) { POLICY_LIB_CHECK_VOID(); policy_manager_->PTUpdatedAt(counter, value); diff --git a/src/components/include/application_manager/policies/policy_handler_interface.h b/src/components/include/application_manager/policies/policy_handler_interface.h index 708c4ddd32..a743b92185 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -38,6 +38,8 @@ #include #include #include +#include "boost/optional.hpp" + #include "application_manager/application.h" #include "application_manager/policies/policy_handler_observer.h" #include "interfaces/MOBILE_API.h" @@ -49,6 +51,7 @@ #include "smart_objects/smart_object.h" #include "utils/callable.h" #include "utils/custom_string.h" +#include "utils/optional.h" using namespace ::rpc::policy_table_interface_base; namespace policy { @@ -121,6 +124,8 @@ class PolicyHandlerInterface { virtual uint32_t TimeoutExchangeMSec() const = 0; virtual void OnExceededTimeout() = 0; virtual void OnSystemReady() = 0; + virtual const boost::optional LockScreenDismissalEnabledState() + const = 0; virtual void PTUpdatedAt(Counters counter, int value) = 0; virtual void add_listener(PolicyHandlerObserver* listener) = 0; virtual void remove_listener(PolicyHandlerObserver* listener) = 0; diff --git a/src/components/include/policy/policy_external/policy/policy_listener.h b/src/components/include/policy/policy_external/policy/policy_listener.h index 8299d019f5..c64a6d5496 100644 --- a/src/components/include/policy/policy_external/policy/policy_listener.h +++ b/src/components/include/policy/policy_external/policy/policy_listener.h @@ -175,6 +175,12 @@ class PolicyListener { virtual void OnUpdateHMIStatus(const std::string& device_id, const std::string& policy_app_id, const std::string& hmi_level) = 0; + + /** + * @brief Notify Connected mobile apps about changing state of + * LockScreenDismissal + */ + virtual void OnLockScreenDismissalStateChanged() = 0; }; } // namespace policy #endif // SRC_COMPONENTS_INCLUDE_POLICY_POLICY_EXTERNAL_POLICY_POLICY_LISTENER_H_ diff --git a/src/components/include/policy/policy_external/policy/policy_manager.h b/src/components/include/policy/policy_external/policy/policy_manager.h index 331b579365..6a80e6615e 100644 --- a/src/components/include/policy/policy_external/policy/policy_manager.h +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -36,6 +36,7 @@ #include #include "utils/callable.h" +#include "utils/optional.h" #include "policy/access_remote.h" #include "policy/cache_manager_interface.h" @@ -164,6 +165,15 @@ class PolicyManager : public usage_statistics::StatisticsManager { */ virtual void KmsChanged(int kilometers) = 0; + /** + * @brief Returns state of the lock screen that could be able to be dismissed + * while connected to SDL, allowing users the ability to interact with the + * app. + * @return bool True if lock screen can be dismissed. + */ + virtual const boost::optional LockScreenDismissalEnabledState() + const = 0; + /** * @brief Increments counter of ignition cycles */ diff --git a/src/components/include/policy/policy_regular/policy/policy_manager.h b/src/components/include/policy/policy_regular/policy/policy_manager.h index f82657ef26..eee7986948 100644 --- a/src/components/include/policy/policy_regular/policy/policy_manager.h +++ b/src/components/include/policy/policy_regular/policy/policy_manager.h @@ -35,6 +35,7 @@ #include #include +#include "boost/optional.hpp" #include "policy/access_remote.h" #include "policy/cache_manager_interface.h" @@ -43,6 +44,7 @@ #include "policy/policy_types.h" #include "policy/usage_statistics/statistics_manager.h" #include "utils/callable.h" +#include "utils/optional.h" namespace policy { class PolicySettings; @@ -164,6 +166,15 @@ class PolicyManager : public usage_statistics::StatisticsManager { */ virtual void KmsChanged(int kilometers) = 0; + /** + * @brief Returns state of the lock screen that could be able to be dismissed + * while connected to SDL, allowing users the ability to interact with the + * app. + * @return bool True if lock screen can be dismissed. + */ + virtual const boost::optional LockScreenDismissalEnabledState() + const = 0; + /** * @brief Increments counter of ignition cycles */ diff --git a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h index 059442f424..7ba29a625d 100644 --- a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h +++ b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h @@ -109,6 +109,8 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { MOCK_CONST_METHOD0(TimeoutExchangeMSec, uint32_t()); MOCK_METHOD0(OnExceededTimeout, void()); MOCK_METHOD0(OnSystemReady, void()); + MOCK_CONST_METHOD0(LockScreenDismissalEnabledState, + const boost::optional()); MOCK_METHOD2(PTUpdatedAt, void(policy::Counters counter, int value)); MOCK_METHOD1(add_listener, void(policy::PolicyHandlerObserver* listener)); MOCK_METHOD1(remove_listener, void(policy::PolicyHandlerObserver* listener)); diff --git a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h index 6f754ad2c9..ab5c34f91d 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h @@ -110,6 +110,8 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { policy_table::AppServiceParameters* app_service_parameters)); MOCK_CONST_METHOD1(UnknownRPCPassthroughAllowed, bool(const std::string& policy_app_id)); + MOCK_CONST_METHOD0(LockScreenDismissalEnabledState, + const boost::optional()); MOCK_CONST_METHOD1(GetDeviceConsent, DeviceConsent(const std::string& device_id)); MOCK_METHOD2(SetDeviceConsent, diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h index 7ebf73ae54..be346c49ff 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h @@ -77,6 +77,8 @@ class MockPolicyManager : public PolicyManager { MOCK_METHOD0(ResetUserConsent, bool()); MOCK_CONST_METHOD0(GetPolicyTableStatus, std::string()); MOCK_METHOD1(KmsChanged, void(int kilometers)); + MOCK_CONST_METHOD0(LockScreenDismissalEnabledState, + const boost::optional()); MOCK_METHOD0(IncrementIgnitionCycles, void()); MOCK_METHOD0(ForcePTExchange, std::string()); MOCK_METHOD0(ForcePTExchangeAtUserRequest, std::string()); diff --git a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h index dacdaf202f..13cc45cfe2 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h @@ -91,6 +91,8 @@ class MockCacheManagerInterface : public CacheManagerInterface { MOCK_METHOD2(SetHybridAppPreference, void(const std::string& policy_app_id, const std::string& hybrid_app_preference)); + MOCK_CONST_METHOD0(LockScreenDismissalEnabledState, + const boost::optional()); MOCK_METHOD1(SetVINValue, bool(const std::string& value)); MOCK_METHOD2(GetUserFriendlyMsg, std::vector( diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h index 73bf2d387b..c440c26208 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h @@ -78,6 +78,8 @@ class MockPolicyManager : public PolicyManager { MOCK_METHOD0(ResetUserConsent, bool()); MOCK_CONST_METHOD0(GetPolicyTableStatus, std::string()); MOCK_METHOD1(KmsChanged, void(int kilometers)); + MOCK_CONST_METHOD0(LockScreenDismissalEnabledState, + const boost::optional()); MOCK_METHOD0(IncrementIgnitionCycles, void()); MOCK_METHOD0(ForcePTExchange, std::string()); MOCK_METHOD0(ForcePTExchangeAtUserRequest, std::string()); 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 15eb51565d..144061e58b 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_CACHE_MANAGER_H_ #include +#include "boost/optional.hpp" #include "policy/cache_manager_interface.h" #include "policy/pt_ext_representation.h" @@ -158,6 +159,8 @@ class CacheManager : public CacheManagerInterface { */ virtual const VehicleInfo GetVehicleInfo() const; + const boost::optional LockScreenDismissalEnabledState() const OVERRIDE; + /** * @brief Get a list of enabled cloud applications * @param enabled_apps List filled with the policy app id of each enabled 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 980ad42dcd..10e3ddde8e 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 @@ -35,6 +35,7 @@ #include #include +#include "boost/optional.hpp" #include "policy/policy_table/types.h" #include "policy/pt_representation.h" @@ -269,6 +270,15 @@ class CacheManagerInterface { virtual bool UnknownRPCPassthroughAllowed( const std::string& policy_app_id) const = 0; + /** + * @brief Returns state of the lock screen that could be able to be dismissed + * while connected to SDL, allowing users the ability to interact with the + * app. + * @return bool True if lock screen can be dismissed. + */ + virtual const boost::optional LockScreenDismissalEnabledState() + const = 0; + /** * @brief Allows to update 'vin' field in module_meta table. * 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 2f8f6cf070..1ea85ff6d5 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 @@ -148,6 +148,8 @@ class PolicyManagerImpl : public PolicyManager { */ void KmsChanged(int kilometers) OVERRIDE; + const boost::optional LockScreenDismissalEnabledState() const OVERRIDE; + /** * @brief Increments counter of ignition cycles */ diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index bd38f7bf8f..6e0c868ed8 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -1561,6 +1561,18 @@ bool CacheManager::UnknownRPCPassthroughAllowed( return false; } +const boost::optional CacheManager::LockScreenDismissalEnabledState() + const { + boost::optional empty; + CACHE_MANAGER_CHECK(empty); + sync_primitives::AutoLock auto_lock(cache_lock_); + policy_table::ModuleConfig& module_config = pt_->policy_table.module_config; + if (module_config.lock_screen_dismissal_enabled.is_initialized()) { + return boost::optional(*module_config.lock_screen_dismissal_enabled); + } + return empty; +} + std::vector CacheManager::GetUserFriendlyMsg( const std::vector& msg_codes, const std::string& language, 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 15900f0187..f56758f0f8 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -1738,6 +1738,12 @@ void PolicyManagerImpl::KmsChanged(int kilometers) { } } +const boost::optional PolicyManagerImpl::LockScreenDismissalEnabledState() + const { + LOG4CXX_AUTO_TRACE(logger_); + return cache_->LockScreenDismissalEnabledState(); +} + void PolicyManagerImpl::IncrementIgnitionCycles() { cache_->IncrementIgnitionCycles(); } 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 30732f685c..392956c784 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -146,6 +146,8 @@ class CacheManager : public CacheManagerInterface { */ virtual const VehicleInfo GetVehicleInfo() const; + const boost::optional LockScreenDismissalEnabledState() const OVERRIDE; + /** * @brief Get a list of enabled cloud applications * @param enabled_apps List filled with the policy app id of each enabled 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 da15a4ecab..a59cb4522d 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 @@ -35,11 +35,13 @@ #include #include +#include "boost/optional.hpp" #include "policy/policy_settings.h" #include "policy/policy_table/types.h" #include "policy/policy_types.h" #include "policy/usage_statistics/counter.h" +#include "utils/optional.h" namespace policy_table = rpc::policy_table_interface_base; @@ -254,6 +256,15 @@ class CacheManagerInterface { virtual bool UnknownRPCPassthroughAllowed( const std::string& policy_app_id) const = 0; + /** + * @brief Returns state of the lock screen that could be able to be dismissed + * while connected to SDL, allowing users the ability to interact with the + * app. + * @return bool True if lock screen can be dismissed. + */ + virtual const boost::optional LockScreenDismissalEnabledState() + const = 0; + /** * @brief Allows to update 'vin' field in module_meta table. * 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 1860f7e591..407b3510d6 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 @@ -162,6 +162,8 @@ class PolicyManagerImpl : public PolicyManager { */ void KmsChanged(int kilometers) OVERRIDE; + const boost::optional LockScreenDismissalEnabledState() const OVERRIDE; + /** * @brief Increments counter of ignition cycles */ @@ -819,6 +821,17 @@ class PolicyManagerImpl : public PolicyManager { const std::shared_ptr update, const std::shared_ptr snapshot); + /** + * @brief Compares current policies to the updated one. + * Trigger actions in case if certain fields after update were changed. + * This function should be called after PT update. + * Actions require already updated policy table + * @param update Shared pointer to policy table update + * @param snapshot Shared pointer to old copy of policy table + */ + void CheckPermissionsChangesAfterUpdate(const policy_table::Table& update, + const policy_table::Table& snapshot); + /** * @brief Fill structure to be sent with OnPermissionsChanged notification * diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index 94ce52b6f1..ebc1e2315e 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -856,6 +856,22 @@ bool CacheManager::UnknownRPCPassthroughAllowed( return false; } +const boost::optional CacheManager::LockScreenDismissalEnabledState() + const { + LOG4CXX_AUTO_TRACE(logger_); + boost::optional empty; + CACHE_MANAGER_CHECK(empty); + sync_primitives::AutoLock auto_lock(cache_lock_); + policy_table::ModuleConfig& module_config = pt_->policy_table.module_config; + if (module_config.lock_screen_dismissal_enabled.is_initialized()) { + LOG4CXX_TRACE(logger_, + "state = " << *module_config.lock_screen_dismissal_enabled); + return boost::optional(*module_config.lock_screen_dismissal_enabled); + } + LOG4CXX_TRACE(logger_, "state = empty"); + return empty; +} + std::vector CacheManager::GetUserFriendlyMsg( const std::vector& msg_codes, const std::string& language) { LOG4CXX_AUTO_TRACE(logger_); 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 0884fc53b6..ae32908100 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -401,6 +401,17 @@ void PolicyManagerImpl::CheckPermissionsChanges( CheckAppPolicy(this, pt_update, snapshot)); } +void PolicyManagerImpl::CheckPermissionsChangesAfterUpdate( + const policy_table::Table& update, const policy_table::Table& snapshot) { + const auto new_lock_screen_dismissal_enabled = + update.policy_table.module_config.lock_screen_dismissal_enabled; + const auto old_lock_screen_dismissal_enabled = + snapshot.policy_table.module_config.lock_screen_dismissal_enabled; + if (new_lock_screen_dismissal_enabled != old_lock_screen_dismissal_enabled) { + listener()->OnLockScreenDismissalStateChanged(); + } +} + void PolicyManagerImpl::PrepareNotificationData( const policy_table::FunctionalGroupings& groups, const policy_table::Strings& group_names, @@ -1068,6 +1079,11 @@ void PolicyManagerImpl::KmsChanged(int kilometers) { } } +const boost::optional PolicyManagerImpl::LockScreenDismissalEnabledState() + const { + return cache_->LockScreenDismissalEnabledState(); +} + void PolicyManagerImpl::IncrementIgnitionCycles() { cache_->IncrementIgnitionCycles(); } -- cgit v1.2.1 From 8e77a09d4c6800e28e2d8693381bb75a0d14c89e Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 17 Dec 2018 17:55:33 +0000 Subject: Process lock_screen_dismissal_enabled logic --- .../include/application_manager/smart_object_keys.h | 1 + .../commands/hmi/on_driver_distraction_notification.cc | 17 +++++++++++++---- .../application_manager/src/application_manager_impl.cc | 12 ++++++++++++ .../application_manager/src/smart_object_keys.cc | 1 + 4 files changed, 27 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/components/application_manager/include/application_manager/smart_object_keys.h b/src/components/application_manager/include/application_manager/smart_object_keys.h index 328d7f5e81..a24e624536 100644 --- a/src/components/application_manager/include/application_manager/smart_object_keys.h +++ b/src/components/application_manager/include/application_manager/smart_object_keys.h @@ -480,6 +480,7 @@ namespace mobile_notification { extern const char* state; extern const char* syncp_timeout; extern const char* syncp_url; +extern const char* lock_screen_dismissal_enabled; } // namespace mobile_notification namespace hmi_levels { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_driver_distraction_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_driver_distraction_notification.cc index 2f3ee60a16..0e3a66aad7 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_driver_distraction_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_driver_distraction_notification.cc @@ -108,14 +108,12 @@ OnDriverDistractionNotification::~OnDriverDistractionNotification() {} void OnDriverDistractionNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); - const hmi_apis::Common_DriverDistractionState::eType state = + const auto state = static_cast( (*message_)[strings::msg_params][hmi_notification::state].asInt()); application_manager_.set_driver_distraction_state(state); - smart_objects::SmartObjectSPtr on_driver_distraction = - std::make_shared(); - + auto on_driver_distraction = std::make_shared(); if (!on_driver_distraction) { LOG4CXX_ERROR(logger_, "NULL pointer"); return; @@ -127,6 +125,17 @@ void OnDriverDistractionNotification::Run() { (*on_driver_distraction)[strings::msg_params][mobile_notification::state] = state; + const auto lock_screen_dismissal = + application_manager_.GetPolicyHandler().LockScreenDismissalEnabledState(); + + if (lock_screen_dismissal && + hmi_apis::Common_DriverDistractionState::DD_ON == state) { + (*on_driver_distraction) + [strings::msg_params] + [mobile_notification::lock_screen_dismissal_enabled] = + *lock_screen_dismissal; + } + const ApplicationSet applications = application_manager_.applications().GetData(); diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 3a92009d4f..ae10478e5e 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -3916,6 +3916,18 @@ void ApplicationManagerImpl::SendDriverDistractionState( mobile_api::FunctionID::OnDriverDistractionID; (*on_driver_distraction)[strings::msg_params][mobile_notification::state] = driver_distraction_state(); + const auto lock_screen_dismissal = + policy_handler_->LockScreenDismissalEnabledState(); + + if (lock_screen_dismissal && + hmi_apis::Common_DriverDistractionState::DD_ON == + driver_distraction_state()) { + (*on_driver_distraction) + [strings::msg_params] + [mobile_notification::lock_screen_dismissal_enabled] = + *lock_screen_dismissal; + } + (*on_driver_distraction)[strings::params][strings::connection_key] = application->app_id(); diff --git a/src/components/application_manager/src/smart_object_keys.cc b/src/components/application_manager/src/smart_object_keys.cc index 54033b12ab..3c0db278b6 100644 --- a/src/components/application_manager/src/smart_object_keys.cc +++ b/src/components/application_manager/src/smart_object_keys.cc @@ -441,6 +441,7 @@ namespace mobile_notification { const char* state = "state"; const char* syncp_timeout = "Timeout"; const char* syncp_url = "URL"; +const char* lock_screen_dismissal_enabled = "lockScreenDismissalEnabled"; } // namespace mobile_notification namespace hmi_levels { -- cgit v1.2.1 From 056173456d80ce93ad8266c928f442d5d20a0f3a Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 10 Jan 2019 14:24:29 +0000 Subject: Unit tests for sdl_passanger mode lock screen dismissal --- .../test/commands/hmi/hmi_notifications_test.cc | 9 ++- .../hmi/on_driver_distraction_notification_test.cc | 84 +++++++++++++++------- 2 files changed, 62 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc index 1653889789..88be43b4b3 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc @@ -1801,6 +1801,7 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) { ON_CALL(app_mngr_, GetPolicyHandler()) .WillByDefault(ReturnRef(mock_policy_handler_)); typedef boost::optional OptionalBool; + ON_CALL(mock_policy_handler_, LockScreenDismissalEnabledState()) .WillByDefault(Return(OptionalBool(true))); ON_CALL(app_mngr_, applications()).WillByDefault(Return(applications_)); @@ -1812,8 +1813,7 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) { TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationInvalidApp) { - const hmi_apis::Common_DriverDistractionState::eType state = - hmi_apis::Common_DriverDistractionState::DD_ON; + const auto state = hmi_apis::Common_DriverDistractionState::DD_ON; MessageSharedPtr message = CreateMessage(); (*message)[am::strings::msg_params][am::hmi_notification::state] = state; std::shared_ptr command = @@ -1853,14 +1853,13 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationValidApp) { policy::CheckPermissionResult result; result.hmi_level_permitted = policy::kRpcAllowed; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_)); EXPECT_CALL(mock_policy_handler_, CheckPermissions(_, _, _, _)) .WillOnce(GetArg3(&result)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)) .WillOnce(GetMessage(message)); - EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); + ON_CALL(*app_ptr_, app_id()).WillByDefault(Return(kAppId_)); command->Run(); EXPECT_EQ( diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc index 52732de56d..38c21cfbc4 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc @@ -53,13 +53,15 @@ namespace on_driver_distraction_notification { using ::testing::_; using ::testing::Eq; +using ::testing::NiceMock; using ::testing::Return; +using ::testing::SaveArg; + namespace am = ::application_manager; using am::commands::MessageSharedPtr; using sdl_rpc_plugin::commands::hmi::OnDriverDistractionNotification; using namespace am::commands; - -typedef std::shared_ptr NotificationPtr; +using test::components::commands_test::MobileResultCodeIs; class HMIOnDriverDistractionNotificationTest : public CommandsTest { @@ -77,7 +79,16 @@ class HMIOnDriverDistractionNotificationTest MockAppPtr mock_app_; std::shared_ptr app_set_lock_; - policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; + am::ApplicationSet app_set_; + DataAccessor accessor; + NiceMock + mock_policy_handler_interface_; + + void InitMocksRelations() { + ON_CALL(app_mngr_, applications()).WillByDefault(Return(accessor)); + ON_CALL(app_mngr_, GetPolicyHandler()) + .WillByDefault(ReturnRef(mock_policy_handler_interface_)); + } }; MATCHER_P2(CheckNotificationParams, function_id, state, "") { @@ -97,9 +108,9 @@ ACTION_P(GetArg3, result) { arg3 = *result; } -TEST_F(HMIOnDriverDistractionNotificationTest, Run_PushMobileMessage_SUCCESS) { - const hmi_apis::Common_DriverDistractionState::eType state = - hmi_apis::Common_DriverDistractionState::DD_ON; +TEST_F(HMIOnDriverDistractionNotificationTest, + Run_SendNotificationToMobile_SUCCESS) { + const auto state = hmi_apis::Common_DriverDistractionState::DD_ON; MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; @@ -108,30 +119,48 @@ TEST_F(HMIOnDriverDistractionNotificationTest, Run_PushMobileMessage_SUCCESS) { EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); - MockAppPtr mock_app = CreateMockApp(); - am::ApplicationSet app_set; - app_set.insert(mock_app); + ON_CALL(mock_policy_handler_interface_, LockScreenDismissalEnabledState()) + .WillByDefault(Return(OptionalBool(true))); - DataAccessor accessor(app_set, app_set_lock_); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); policy::CheckPermissionResult result; - result.hmi_level_permitted = policy::kRpcDisallowed; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_interface_)); + result.hmi_level_permitted = policy::kRpcAllowed; EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) .WillOnce(GetArg3(&result)); - EXPECT_CALL(*mock_app, + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + CheckNotificationParams( + am::mobile_api::FunctionID::OnDriverDistractionID, state), + Command::CommandSource::SOURCE_SDL)); + command->Run(); +} + +TEST_F(HMIOnDriverDistractionNotificationTest, + Run_PushMobileMessage_If_DisallowedByPolicy) { + const auto state = hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); + (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; + NotificationPtr command( + CreateCommand(commands_msg)); + + ON_CALL(mock_policy_handler_interface_, LockScreenDismissalEnabledState()) + .WillByDefault(Return(OptionalBool(true))); + + policy::CheckPermissionResult result; + result.hmi_level_permitted = policy::kRpcDisallowed; + EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) + .WillOnce(GetArg3(&result)); + EXPECT_CALL(*mock_app_, PushMobileMessage(CheckNotificationParams( am::mobile_api::FunctionID::OnDriverDistractionID, state))); + EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); command->Run(); } TEST_F(HMIOnDriverDistractionNotificationTest, - Run_SendNotificationToMobile_SUCCESS) { - const hmi_apis::Common_DriverDistractionState::eType state = - hmi_apis::Common_DriverDistractionState::DD_ON; + Run_SendNotificationIfLockScreenDismissalMissed) { + const auto state = hmi_apis::Common_DriverDistractionState::DD_ON; MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; @@ -143,17 +172,20 @@ TEST_F(HMIOnDriverDistractionNotificationTest, policy::CheckPermissionResult result; result.hmi_level_permitted = policy::kRpcAllowed; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_interface_)); - EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) - .WillOnce(GetArg3(&result)); + ON_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) + .WillByDefault(GetArg3(&result)); + + MessageSharedPtr command_result; EXPECT_CALL(mock_rpc_service_, - ManageMobileCommand( - CheckNotificationParams( - am::mobile_api::FunctionID::OnDriverDistractionID, state), - Command::CommandSource::SOURCE_SDL)); + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&command_result), Return(true))); command->Run(); + + auto& msg_params = + (*command_result)[application_manager::strings::msg_params]; + EXPECT_FALSE(msg_params.keyExists( + application_manager::mobile_notification::lock_screen_dismissal_enabled)); } } // namespace on_driver_distraction_notification -- cgit v1.2.1 From 82b2a6145dce6774182495e1c4b42119dfb6d4d3 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 18 Apr 2019 16:39:38 +0300 Subject: Send OnDriverDistraction notification in case if LockScreenDismissal state was changes after policy update. --- .../application_manager/policies/policy_handler.h | 4 +- .../src/application_manager_impl.cc | 66 +++++++++++++--------- .../src/policies/policy_handler.cc | 9 +++ .../policy/policy_regular/policy/policy_listener.h | 5 ++ .../policy_external/policy/mock_policy_listener.h | 1 + .../policy_regular/policy/mock_policy_listener.h | 1 + .../include/policy/policy_manager_impl.h | 11 ++++ .../policy_external/src/policy_manager_impl.cc | 13 +++++ .../policy_regular/src/policy_manager_impl.cc | 3 +- 9 files changed, 83 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index 68ab57ff64..cda3b5c1ed 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -662,6 +662,8 @@ class PolicyHandler : public PolicyHandlerInterface, void OnDeviceSwitching(const std::string& device_id_from, const std::string& device_id_to) FINAL; + void OnLockScreenDismissalStateChanged() FINAL; + protected: /** * Starts next retry exchange policy table @@ -808,7 +810,6 @@ class PolicyHandler : public PolicyHandlerInterface, std::vector CollectAppPermissions( const uint32_t connection_key); - private: static const std::string kLibrary; /** @@ -818,7 +819,6 @@ class PolicyHandler : public PolicyHandlerInterface, */ void GetRegisteredLinks(std::map& out_links) const; - private: mutable sync_primitives::RWLock policy_manager_lock_; std::shared_ptr policy_manager_; void* dl_handle_; diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index ae10478e5e..94278790e7 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -3907,42 +3907,54 @@ void ApplicationManagerImpl::SendDriverDistractionState( LOG4CXX_WARN(logger_, "DriverDistractionState is INVALID_ENUM"); return; } - smart_objects::SmartObjectSPtr on_driver_distraction = - std::make_shared(); - - (*on_driver_distraction)[strings::params][strings::message_type] = - static_cast(application_manager::MessageType::kNotification); - (*on_driver_distraction)[strings::params][strings::function_id] = - mobile_api::FunctionID::OnDriverDistractionID; - (*on_driver_distraction)[strings::msg_params][mobile_notification::state] = - driver_distraction_state(); - const auto lock_screen_dismissal = - policy_handler_->LockScreenDismissalEnabledState(); - if (lock_screen_dismissal && - hmi_apis::Common_DriverDistractionState::DD_ON == - driver_distraction_state()) { - (*on_driver_distraction) - [strings::msg_params] - [mobile_notification::lock_screen_dismissal_enabled] = - *lock_screen_dismissal; - } + auto create_notification = [application, this]() { + auto notification = std::make_shared(); + auto& msg_params = (*notification)[strings::msg_params]; + auto& params = (*notification)[strings::params]; + + params[strings::message_type] = + static_cast(application_manager::MessageType::kNotification); + params[strings::function_id] = + static_cast(mobile_apis::FunctionID::OnDriverDistractionID); + msg_params[mobile_notification::state] = driver_distraction_state(); + const auto lock_screen_dismissal = + policy_handler_->LockScreenDismissalEnabledState(); + + if (lock_screen_dismissal && + hmi_apis::Common_DriverDistractionState::DD_ON == + driver_distraction_state()) { + msg_params[mobile_notification::lock_screen_dismissal_enabled] = + *lock_screen_dismissal; + } - (*on_driver_distraction)[strings::params][strings::connection_key] = - application->app_id(); + params[strings::connection_key] = application->app_id(); + return notification; + }; - const std::string function_id = MessageHelper::StringifiedFunctionID( - static_cast( - (*on_driver_distraction)[strings::params][strings::function_id] - .asUInt())); const RPCParams params; + const std::string function_id = MessageHelper::StringifiedFunctionID( + mobile_api::FunctionID::OnDriverDistractionID); const mobile_apis::Result::eType check_result = CheckPolicyPermissions(application, function_id, params); if (mobile_api::Result::SUCCESS == check_result) { - rpc_service_->ManageMobileCommand(on_driver_distraction, + rpc_service_->ManageMobileCommand(create_notification(), commands::Command::SOURCE_SDL); } else { - application->PushMobileMessage(on_driver_distraction); + MobileMessageQueue messages; + application->SwapMobileMessageQueue(messages); + messages.erase( + std::remove_if( + messages.begin(), + messages.end(), + [](smart_objects::SmartObjectSPtr message) { + return (*message)[strings::params][strings::function_id] + .asUInt() == + mobile_apis::FunctionID::OnDriverDistractionID; + }), + messages.end()); + application->SwapMobileMessageQueue(messages); + application->PushMobileMessage(create_notification()); } } diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 72424b74f9..033df7071f 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -826,6 +826,15 @@ void PolicyHandler::OnDeviceSwitching(const std::string& device_id_from, policy_manager_->OnDeviceSwitching(device_id_from, device_id_to); } +void PolicyHandler::OnLockScreenDismissalStateChanged() { + LOG4CXX_AUTO_TRACE(logger_); + const auto accessor = application_manager_.applications(); + const auto apps = accessor.GetData(); + for (auto& app : apps) { + application_manager_.SendDriverDistractionState(app); + } +} + void PolicyHandler::OnGetStatusUpdate(const uint32_t correlation_id) { LOG4CXX_AUTO_TRACE(logger_); POLICY_LIB_CHECK_VOID(); diff --git a/src/components/include/policy/policy_regular/policy/policy_listener.h b/src/components/include/policy/policy_regular/policy/policy_listener.h index 0907e42142..d017f97f63 100644 --- a/src/components/include/policy/policy_regular/policy/policy_listener.h +++ b/src/components/include/policy/policy_regular/policy/policy_listener.h @@ -157,6 +157,11 @@ class PolicyListener { virtual void OnUpdateHMIStatus(const std::string& device_id, const std::string& policy_app_id, const std::string& hmi_level) = 0; + + /** + * @brief Notify Connected mobile apps about changing state LockScreenDismissal + */ + virtual void OnLockScreenDismissalStateChanged() = 0; }; } // namespace policy #endif // SRC_COMPONENTS_INCLUDE_POLICY_POLICY_REGULAR_POLICY_POLICY_LISTENER_H_ diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h b/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h index 1e42423a03..e6ee086b31 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h +++ b/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h @@ -103,6 +103,7 @@ class MockPolicyListener : public ::policy::PolicyListener { void(const std::string& device_id, const std::string& policy_app_id, const std::string& hmi_level)); + MOCK_METHOD0(OnLockScreenDismissalStateChanged, void()); }; } // namespace policy_test diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h index f409100a49..7958bd3304 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h @@ -96,6 +96,7 @@ class MockPolicyListener : public ::policy::PolicyListener { void(const std::string& device_id, const std::string& policy_app_id, const std::string& hmi_level)); + MOCK_METHOD0(OnLockScreenDismissalStateChanged, void()); }; } // namespace policy_test 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 1ea85ff6d5..6888e38740 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 @@ -852,6 +852,17 @@ class PolicyManagerImpl : public PolicyManager { const std::shared_ptr update, const std::shared_ptr snapshot); + /** + * @brief Compares current policies to the updated one. + * Trigger actions in case if certain fields after udate was changes. + * This function should be called after PT update. + * Actions require already updated policy table + * @param update Shared pointer to policy table udpate + * @param snapshot Shared pointer to old copy of policy table + */ + void CheckPermissionsChangesAfterUpdate(const policy_table::Table& update, + const policy_table::Table& snapshot); + /** * @brief Processes results from policy table update analysis done by * CheckPermissionsChanges() by filling ApplicationsPoliciesActions struct 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 f56758f0f8..4cefa11dd8 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -491,6 +491,8 @@ bool PolicyManagerImpl::LoadPT(const std::string& file, ProcessAppPolicyCheckResults( results, pt_update->policy_table.app_policies_section.apps); + CheckPermissionsChangesAfterUpdate(*pt_update, *policy_table_snapshot); + listener_->OnCertificateUpdated( *(pt_update->policy_table.module_config.certificate)); @@ -538,6 +540,17 @@ CheckAppPolicyResults PolicyManagerImpl::CheckPermissionsChanges( return out_results; } +void PolicyManagerImpl::CheckPermissionsChangesAfterUpdate( + const policy_table::Table& update, const policy_table::Table& snapshot) { + const auto new_lock_screen_dismissal_enabled = + update.policy_table.module_config.lock_screen_dismissal_enabled; + const auto old_lock_screen_dismissal_enabled = + snapshot.policy_table.module_config.lock_screen_dismissal_enabled; + if (new_lock_screen_dismissal_enabled != old_lock_screen_dismissal_enabled) { + listener()->OnLockScreenDismissalStateChanged(); + } +} + void PolicyManagerImpl::ProcessAppPolicyCheckResults( const CheckAppPolicyResults& results, const policy_table::ApplicationPolicies& app_policies) { 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 ae32908100..c6db002980 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -356,6 +356,7 @@ bool PolicyManagerImpl::LoadPT(const std::string& file, ForcePTExchange(); return false; } + CheckPermissionsChangesAfterUpdate(*pt_update, *policy_table_snapshot); listener_->OnCertificateUpdated( *(pt_update->policy_table.module_config.certificate)); @@ -390,7 +391,7 @@ bool PolicyManagerImpl::LoadPT(const std::string& file, void PolicyManagerImpl::CheckPermissionsChanges( const std::shared_ptr pt_update, const std::shared_ptr snapshot) { - LOG4CXX_INFO(logger_, "Checking incoming permissions."); + LOG4CXX_AUTO_TRACE(logger_); // Replace predefined policies with its actual setting, e.g. "123":"default" // to actual values of default section -- cgit v1.2.1 From 596514c10ae2d89eda79d8f2390f0e45c7c333dd Mon Sep 17 00:00:00 2001 From: igapchuck Date: Fri, 17 May 2019 15:02:10 +0300 Subject: Update after rebase on develop --- .../include/policy/policy_regular/policy/policy_listener.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/components/include/policy/policy_regular/policy/policy_listener.h b/src/components/include/policy/policy_regular/policy/policy_listener.h index d017f97f63..f12bb2e85f 100644 --- a/src/components/include/policy/policy_regular/policy/policy_listener.h +++ b/src/components/include/policy/policy_regular/policy/policy_listener.h @@ -159,8 +159,9 @@ class PolicyListener { const std::string& hmi_level) = 0; /** - * @brief Notify Connected mobile apps about changing state LockScreenDismissal - */ + * @brief Notify Connected mobile apps about changing state + * LockScreenDismissal + */ virtual void OnLockScreenDismissalStateChanged() = 0; }; } // namespace policy -- cgit v1.2.1 From c1cced8d10c5fa8b509a7502a5873360fa66aca5 Mon Sep 17 00:00:00 2001 From: igapchuck Date: Wed, 26 Jun 2019 14:51:49 +0300 Subject: Add lock_screen_dismissal_warning to API and policy. lock_screen_dismissal_warning parameter should be in consumer_friendly_messages section in sdl_preloaded_pt. --- src/appMain/sdl_preloaded_pt.json | 7 +++++++ src/components/interfaces/MOBILE_API.xml | 8 ++++++++ 2 files changed, 15 insertions(+) (limited to 'src') diff --git a/src/appMain/sdl_preloaded_pt.json b/src/appMain/sdl_preloaded_pt.json index 3888650ed2..88bcafcd82 100644 --- a/src/appMain/sdl_preloaded_pt.json +++ b/src/appMain/sdl_preloaded_pt.json @@ -1920,6 +1920,13 @@ } } }, + "LockScreenDismissalWarning":{ + "languages":{ + "en-us":{ + "textBody": "Swipe down to dismiss, acknowledging that you are not the driver" + } + } + }, "Notifications": { "languages": { "de-de": { diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml index 970a4805fb..3072b3fb5b 100644 --- a/src/components/interfaces/MOBILE_API.xml +++ b/src/components/interfaces/MOBILE_API.xml @@ -7561,6 +7561,14 @@ that they are not the driver. + + + Warning message to be displayed on the lock screen when dismissal is enabled. + This warning should be used to ensure that the user is not the driver of the vehicle, + ex. `Swipe down to dismiss, acknowledging that you are not the driver.`. + This parameter must be present if "lockScreenDismissalEnabled" is set to true. + + -- cgit v1.2.1 From 2187d3b081785547d0a80555ea4828adf19ee2c6 Mon Sep 17 00:00:00 2001 From: igapchuck Date: Thu, 27 Jun 2019 14:23:15 +0300 Subject: Add lock_screen_dismissal_warning to Policy Interface --- .../application_manager/policies/policy_handler.h | 2 ++ .../src/policies/policy_handler.cc | 7 +++++ .../policies/policy_handler_interface.h | 2 ++ .../policy/policy_external/policy/policy_manager.h | 9 +++++++ .../policy/policy_regular/policy/policy_manager.h | 8 ++++++ .../policies/mock_policy_handler_interface.h | 2 ++ .../policy_external/policy/mock_cache_manager.h | 12 +++++---- .../policy_external/policy/mock_policy_manager.h | 2 ++ .../policy_regular/policy/mock_cache_manager.h | 10 ++++--- .../policy_regular/policy/mock_policy_manager.h | 2 ++ .../policy_external/include/policy/cache_manager.h | 5 +++- .../include/policy/cache_manager_interface.h | 11 +++++++- .../include/policy/policy_manager_impl.h | 3 +++ .../policy/policy_external/src/cache_manager.cc | 24 ++++++++++++++++- .../policy_external/src/policy_manager_impl.cc | 7 +++++ .../policy_regular/include/policy/cache_manager.h | 5 +++- .../include/policy/cache_manager_interface.h | 10 ++++++- .../include/policy/policy_manager_impl.h | 3 +++ .../policy/policy_regular/src/cache_manager.cc | 31 +++++++++++++++++++++- .../policy_regular/src/policy_manager_impl.cc | 6 +++++ 20 files changed, 146 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index cda3b5c1ed..d0280f91f2 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -205,6 +205,8 @@ class PolicyHandler : public PolicyHandlerInterface, void OnExceededTimeout() OVERRIDE; void OnSystemReady() OVERRIDE; const boost::optional LockScreenDismissalEnabledState() const OVERRIDE; + virtual const boost::optional LockScreenDismissalWarningMessage( + const std::string& language) const OVERRIDE; void PTUpdatedAt(Counters counter, int value) OVERRIDE; void add_listener(PolicyHandlerObserver* listener) OVERRIDE; void remove_listener(PolicyHandlerObserver* listener) OVERRIDE; diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 033df7071f..cac09bd5f3 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1589,6 +1589,13 @@ const boost::optional PolicyHandler::LockScreenDismissalEnabledState() return policy_manager_->LockScreenDismissalEnabledState(); } +const boost::optional +PolicyHandler::LockScreenDismissalWarningMessage( + const std::string& language) const { + POLICY_LIB_CHECK(boost::optional()); + return policy_manager_->LockScreenDismissalWarningMessage(language); +} + void PolicyHandler::PTUpdatedAt(Counters counter, int value) { POLICY_LIB_CHECK_VOID(); policy_manager_->PTUpdatedAt(counter, value); diff --git a/src/components/include/application_manager/policies/policy_handler_interface.h b/src/components/include/application_manager/policies/policy_handler_interface.h index a743b92185..835ddedd28 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -126,6 +126,8 @@ class PolicyHandlerInterface { virtual void OnSystemReady() = 0; virtual const boost::optional LockScreenDismissalEnabledState() const = 0; + virtual const boost::optional LockScreenDismissalWarningMessage( + const std::string& language) const = 0; virtual void PTUpdatedAt(Counters counter, int value) = 0; virtual void add_listener(PolicyHandlerObserver* listener) = 0; virtual void remove_listener(PolicyHandlerObserver* listener) = 0; diff --git a/src/components/include/policy/policy_external/policy/policy_manager.h b/src/components/include/policy/policy_external/policy/policy_manager.h index 6a80e6615e..aecc4b607a 100644 --- a/src/components/include/policy/policy_external/policy/policy_manager.h +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -174,6 +174,15 @@ class PolicyManager : public usage_statistics::StatisticsManager { virtual const boost::optional LockScreenDismissalEnabledState() const = 0; + /** + * @brief Returns lock screen warning message. In case when specified language + * is absent in policy table will be returned message on default language + * ("en-us"). Otherwise returns uninitialized boost::optional + * @return std::string Lock screen warning message + */ + virtual const boost::optional LockScreenDismissalWarningMessage( + const std::string& language) const = 0; + /** * @brief Increments counter of ignition cycles */ diff --git a/src/components/include/policy/policy_regular/policy/policy_manager.h b/src/components/include/policy/policy_regular/policy/policy_manager.h index eee7986948..713f71dcdb 100644 --- a/src/components/include/policy/policy_regular/policy/policy_manager.h +++ b/src/components/include/policy/policy_regular/policy/policy_manager.h @@ -175,6 +175,14 @@ class PolicyManager : public usage_statistics::StatisticsManager { virtual const boost::optional LockScreenDismissalEnabledState() const = 0; + /** + * @brief Returns lock screen warning message + * @param language_code Specific language for which need message + * @return std::string Lock screen warning message + */ + virtual const boost::optional LockScreenDismissalWarningMessage( + const std::string& language) const = 0; + /** * @brief Increments counter of ignition cycles */ diff --git a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h index 7ba29a625d..342debca0a 100644 --- a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h +++ b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h @@ -111,6 +111,8 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { MOCK_METHOD0(OnSystemReady, void()); MOCK_CONST_METHOD0(LockScreenDismissalEnabledState, const boost::optional()); + MOCK_CONST_METHOD1(LockScreenDismissalWarningMessage, + const boost::optional(const std::string&)); MOCK_METHOD2(PTUpdatedAt, void(policy::Counters counter, int value)); MOCK_METHOD1(add_listener, void(policy::PolicyHandlerObserver* listener)); MOCK_METHOD1(remove_listener, void(policy::PolicyHandlerObserver* listener)); diff --git a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h index ab5c34f91d..0a6bef45dd 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h @@ -112,6 +112,8 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { bool(const std::string& policy_app_id)); MOCK_CONST_METHOD0(LockScreenDismissalEnabledState, const boost::optional()); + MOCK_CONST_METHOD1(LockScreenDismissalWarningMessage, + const boost::optional(const std::string&)); MOCK_CONST_METHOD1(GetDeviceConsent, DeviceConsent(const std::string& device_id)); MOCK_METHOD2(SetDeviceConsent, @@ -122,11 +124,11 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { MOCK_CONST_METHOD1(GetCachedDeviceConsent, DeviceConsent(const std::string& device_id)); MOCK_METHOD1(SetVINValue, bool(const std::string& value)); - MOCK_METHOD3(GetUserFriendlyMsg, - std::vector( - const std::vector& msg_codes, - const std::string& language, - const std::string& active_hmi_language)); + MOCK_CONST_METHOD3(GetUserFriendlyMsg, + std::vector( + const std::vector& msg_codes, + const std::string& language, + const std::string& active_hmi_language)); MOCK_METHOD2(GetUpdateUrls, void(const std::string& service_type, EndpointUrls& out_end_points)); diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h index be346c49ff..309e357235 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h @@ -79,6 +79,8 @@ class MockPolicyManager : public PolicyManager { MOCK_METHOD1(KmsChanged, void(int kilometers)); MOCK_CONST_METHOD0(LockScreenDismissalEnabledState, const boost::optional()); + MOCK_CONST_METHOD1(LockScreenDismissalWarningMessage, + const boost::optional(const std::string&)); MOCK_METHOD0(IncrementIgnitionCycles, void()); MOCK_METHOD0(ForcePTExchange, std::string()); MOCK_METHOD0(ForcePTExchangeAtUserRequest, std::string()); diff --git a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h index 13cc45cfe2..c296701e34 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h @@ -93,11 +93,13 @@ class MockCacheManagerInterface : public CacheManagerInterface { const std::string& hybrid_app_preference)); MOCK_CONST_METHOD0(LockScreenDismissalEnabledState, const boost::optional()); + MOCK_CONST_METHOD1(LockScreenDismissalWarningMessage, + const boost::optional(const std::string&)); MOCK_METHOD1(SetVINValue, bool(const std::string& value)); - MOCK_METHOD2(GetUserFriendlyMsg, - std::vector( - const std::vector& msg_codes, - const std::string& language)); + MOCK_CONST_METHOD2(GetUserFriendlyMsg, + std::vector( + const std::vector& msg_codes, + const std::string& language)); MOCK_CONST_METHOD2( GetAppServiceParameters, void(const std::string& policy_app_id, diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h index c440c26208..a670e99bef 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h @@ -80,6 +80,8 @@ class MockPolicyManager : public PolicyManager { MOCK_METHOD1(KmsChanged, void(int kilometers)); MOCK_CONST_METHOD0(LockScreenDismissalEnabledState, const boost::optional()); + MOCK_CONST_METHOD1(LockScreenDismissalWarningMessage, + const boost::optional(const std::string&)); MOCK_METHOD0(IncrementIgnitionCycles, void()); MOCK_METHOD0(ForcePTExchange, std::string()); MOCK_METHOD0(ForcePTExchangeAtUserRequest, std::string()); 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 144061e58b..19a475371d 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -161,6 +161,9 @@ class CacheManager : public CacheManagerInterface { const boost::optional LockScreenDismissalEnabledState() const OVERRIDE; + const boost::optional LockScreenDismissalWarningMessage( + const std::string& language) const OVERRIDE; + /** * @brief Get a list of enabled cloud applications * @param enabled_apps List filled with the policy app id of each enabled @@ -286,7 +289,7 @@ class CacheManager : public CacheManagerInterface { std::vector GetUserFriendlyMsg( const std::vector& msg_codes, const std::string& language, - const std::string& active_hmi_language); + const std::string& active_hmi_language) const; /** * @brief GetLockScreenIcon allows to obtain lock screen icon url; 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 10e3ddde8e..0cbbb6df1f 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 @@ -279,6 +279,15 @@ class CacheManagerInterface { virtual const boost::optional LockScreenDismissalEnabledState() const = 0; + /** + * @brief Returns lock screen warning message. In case when specified language + * is absent in policy table will be returned message on default language + * ("en-us"). Otherwise returns uninitialized boost::optional + * @return std::string Lock screen warning message + */ + virtual const boost::optional LockScreenDismissalWarningMessage( + const std::string& language) const = 0; + /** * @brief Allows to update 'vin' field in module_meta table. * @@ -300,7 +309,7 @@ class CacheManagerInterface { virtual std::vector GetUserFriendlyMsg( const std::vector& msg_codes, const std::string& language, - const std::string& active_hmi_language) = 0; + const std::string& active_hmi_language) const = 0; /** * @brief Get list of URL to send PTS to 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 6888e38740..9dd2b3c6ec 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 @@ -150,6 +150,9 @@ class PolicyManagerImpl : public PolicyManager { const boost::optional LockScreenDismissalEnabledState() const OVERRIDE; + const boost::optional LockScreenDismissalWarningMessage( + const std::string& language) const OVERRIDE; + /** * @brief Increments counter of ignition cycles */ diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index 6e0c868ed8..4170e7aaa6 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -1573,10 +1573,32 @@ const boost::optional CacheManager::LockScreenDismissalEnabledState() return empty; } +const boost::optional +CacheManager::LockScreenDismissalWarningMessage( + const std::string& language) const { + LOG4CXX_AUTO_TRACE(logger_); + boost::optional empty; + CACHE_MANAGER_CHECK(empty); + + const std::string lock_screen_dismissal_warning_message = + "LockScreenDismissalWarning"; + sync_primitives::AutoLock auto_lock(cache_lock_); + + std::vector msg_codes{lock_screen_dismissal_warning_message}; + + const auto messages = GetUserFriendlyMsg(msg_codes, language, "en-us"); + + if (messages.empty() || messages[0].text_body.empty()) { + return empty; + } + + return boost::optional(messages[0].text_body); +} + std::vector CacheManager::GetUserFriendlyMsg( const std::vector& msg_codes, const std::string& language, - const std::string& active_hmi_language) { + const std::string& active_hmi_language) const { LOG4CXX_AUTO_TRACE(logger_); std::vector result; CACHE_MANAGER_CHECK(result); 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 4cefa11dd8..42b67734ae 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -1757,6 +1757,13 @@ const boost::optional PolicyManagerImpl::LockScreenDismissalEnabledState() return cache_->LockScreenDismissalEnabledState(); } +const boost::optional +PolicyManagerImpl::LockScreenDismissalWarningMessage( + const std::string& language) const { + LOG4CXX_AUTO_TRACE(logger_); + return cache_->LockScreenDismissalWarningMessage(language); +} + void PolicyManagerImpl::IncrementIgnitionCycles() { cache_->IncrementIgnitionCycles(); } 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 392956c784..1c28b596c0 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -148,6 +148,8 @@ class CacheManager : public CacheManagerInterface { const boost::optional LockScreenDismissalEnabledState() const OVERRIDE; + const boost::optional LockScreenDismissalWarningMessage( + const std::string& language) const OVERRIDE; /** * @brief Get a list of enabled cloud applications * @param enabled_apps List filled with the policy app id of each enabled @@ -269,7 +271,8 @@ class CacheManager : public CacheManagerInterface { * @return Array of appropriate messages parameters */ std::vector GetUserFriendlyMsg( - const std::vector& msg_codes, const std::string& language); + const std::vector& msg_codes, + const std::string& language) const; /** * @brief Get list of URLs related to particular service 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 a59cb4522d..e8f2644bc5 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 @@ -265,6 +265,14 @@ class CacheManagerInterface { virtual const boost::optional LockScreenDismissalEnabledState() const = 0; + /** + * @brief Returns lock screen warning message. In case when specified language + * is absent in policy table will be returned message on default language + * ("en-us"). Otherwise returns uninitialized boost::optional + * @return std::string Lock screen warning message + */ + virtual const boost::optional LockScreenDismissalWarningMessage( + const std::string& language_code) const = 0; /** * @brief Allows to update 'vin' field in module_meta table. * @@ -285,7 +293,7 @@ class CacheManagerInterface { */ virtual std::vector GetUserFriendlyMsg( const std::vector& msg_codes, - const std::string& language) = 0; + const std::string& language) const = 0; /** * @brief Get list of URLs related to particular service 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 407b3510d6..13d19e1a41 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 @@ -164,6 +164,9 @@ class PolicyManagerImpl : public PolicyManager { const boost::optional LockScreenDismissalEnabledState() const OVERRIDE; + const boost::optional LockScreenDismissalWarningMessage( + const std::string& language) const OVERRIDE; + /** * @brief Increments counter of ignition cycles */ diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index ebc1e2315e..d121886765 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -872,8 +872,31 @@ const boost::optional CacheManager::LockScreenDismissalEnabledState() return empty; } +const boost::optional +CacheManager::LockScreenDismissalWarningMessage( + const std::string& language) const { + LOG4CXX_AUTO_TRACE(logger_); + boost::optional empty; + CACHE_MANAGER_CHECK(empty); + + const std::string lock_screen_dismissal_warning_message = + "LockScreenDismissalWarning"; + sync_primitives::AutoLock auto_lock(cache_lock_); + + std::vector msg_codes{lock_screen_dismissal_warning_message}; + + const auto messages = GetUserFriendlyMsg(msg_codes, language); + + if (messages.empty() || messages[0].text_body.empty()) { + return empty; + } + + return boost::optional(messages[0].text_body); +} + std::vector CacheManager::GetUserFriendlyMsg( - const std::vector& msg_codes, const std::string& language) { + const std::vector& msg_codes, + const std::string& language) const { LOG4CXX_AUTO_TRACE(logger_); std::vector result; CACHE_MANAGER_CHECK(result); @@ -919,6 +942,12 @@ std::vector CacheManager::GetUserFriendlyMsg( UserFriendlyMessage msg; msg.message_code = *it; + msg.tts = *message_string.tts; + msg.label = *message_string.label; + msg.line1 = *message_string.line1; + msg.line2 = *message_string.line2; + msg.text_body = *message_string.textBody; + result.push_back(msg); } 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 c6db002980..00a3d33379 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -1085,6 +1085,12 @@ const boost::optional PolicyManagerImpl::LockScreenDismissalEnabledState() return cache_->LockScreenDismissalEnabledState(); } +const boost::optional +PolicyManagerImpl::LockScreenDismissalWarningMessage( + const std::string& language) const { + return cache_->LockScreenDismissalWarningMessage(language); +} + void PolicyManagerImpl::IncrementIgnitionCycles() { cache_->IncrementIgnitionCycles(); } -- cgit v1.2.1 From 6b7ecc6160f3511beea866b32fd6a083528f9919 Mon Sep 17 00:00:00 2001 From: igapchuck Date: Fri, 28 Jun 2019 14:11:34 +0300 Subject: Process lock_screen_dismissal_warning logic --- .../include/application_manager/message_helper.h | 8 +++++ .../application_manager/policies/policy_handler.h | 2 +- .../application_manager/smart_object_keys.h | 1 + .../hmi/on_driver_distraction_notification.cc | 39 ++++++++++++++++++---- .../src/application_manager_impl.cc | 17 +++++++++- .../src/message_helper/message_helper.cc | 9 +++++ .../application_manager/src/smart_object_keys.cc | 1 + .../application_manager/mock_message_helper.h | 2 ++ .../test/mock_message_helper.cc | 6 ++++ 9 files changed, 77 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index 2671278442..98992a20d5 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -725,6 +725,14 @@ class MessageHelper { static std::string CommonLanguageToString( hmi_apis::Common_Language::eType language); + /** + * @brief Converts mobile language to string representation + * @param language Mobile UI language + * @return Mobile language string representation + */ + static std::string MobileLanguageToString( + mobile_apis::Language::eType language); + /** * @brief Converts string to mobile language enum value * @param language language as string diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index d0280f91f2..917f8be559 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -205,7 +205,7 @@ class PolicyHandler : public PolicyHandlerInterface, void OnExceededTimeout() OVERRIDE; void OnSystemReady() OVERRIDE; const boost::optional LockScreenDismissalEnabledState() const OVERRIDE; - virtual const boost::optional LockScreenDismissalWarningMessage( + const boost::optional LockScreenDismissalWarningMessage( const std::string& language) const OVERRIDE; void PTUpdatedAt(Counters counter, int value) OVERRIDE; void add_listener(PolicyHandlerObserver* listener) OVERRIDE; diff --git a/src/components/application_manager/include/application_manager/smart_object_keys.h b/src/components/application_manager/include/application_manager/smart_object_keys.h index a24e624536..69e00f5838 100644 --- a/src/components/application_manager/include/application_manager/smart_object_keys.h +++ b/src/components/application_manager/include/application_manager/smart_object_keys.h @@ -481,6 +481,7 @@ extern const char* state; extern const char* syncp_timeout; extern const char* syncp_url; extern const char* lock_screen_dismissal_enabled; +extern const char* lock_screen_dismissal_warning; } // namespace mobile_notification namespace hmi_levels { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_driver_distraction_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_driver_distraction_notification.cc index 0e3a66aad7..4229369acc 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_driver_distraction_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_driver_distraction_notification.cc @@ -59,12 +59,35 @@ struct OnDriverDistractionProcessor { void operator()(ApplicationSharedPtr application) { if (application) { - (*on_driver_distraction_so_)[strings::params][strings::connection_key] = - application->app_id(); + // Create modifiable copy of base message + smart_objects::SmartObject message = *on_driver_distraction_so_; + message[strings::params][strings::connection_key] = application->app_id(); const RPCParams params; policy::CheckPermissionResult result; application_manager_.GetPolicyHandler().CheckPermissions( application, stringified_function_id_, params, result); + auto& msg_params = message[strings::msg_params]; + const bool is_lock_screen_dismissal_exists = msg_params.keyExists( + mobile_notification::lock_screen_dismissal_enabled); + + if (is_lock_screen_dismissal_exists && + msg_params[mobile_notification::lock_screen_dismissal_enabled] + .asBool()) { + const auto language = + MessageHelper::MobileLanguageToString(application->ui_language()); + + const auto warning_message = + application_manager_.GetPolicyHandler() + .LockScreenDismissalWarningMessage(language); + // Only allow lock screen dismissal if a warning message is available + if (warning_message && !warning_message->empty()) { + msg_params[mobile_notification::lock_screen_dismissal_warning] = + *warning_message; + } else { + msg_params[mobile_notification::lock_screen_dismissal_enabled] = + false; + } + } if (result.hmi_level_permitted != policy::kRpcAllowed) { MobileMessageQueue messages; application->SwapMobileMessageQueue(messages); @@ -72,15 +95,19 @@ struct OnDriverDistractionProcessor { std::remove_if( messages.begin(), messages.end(), - [this](smart_objects::SmartObjectSPtr message) { + [](smart_objects::SmartObjectSPtr message) { return (*message)[strings::params][strings::function_id] - .asString() == stringified_function_id_; + .asUInt() == + mobile_api::FunctionID::OnDriverDistractionID; }), messages.end()); - application->PushMobileMessage(on_driver_distraction_so_); + application->SwapMobileMessageQueue(messages); + application->PushMobileMessage( + std::make_shared(message)); return; } - command_.SendNotificationToMobile(on_driver_distraction_so_); + command_.SendNotificationToMobile( + std::make_shared(message)); } } diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 94278790e7..317ad2933f 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -3924,8 +3924,23 @@ void ApplicationManagerImpl::SendDriverDistractionState( if (lock_screen_dismissal && hmi_apis::Common_DriverDistractionState::DD_ON == driver_distraction_state()) { + bool dismissal_enabled = *lock_screen_dismissal; + if (dismissal_enabled) { + const auto language = + MessageHelper::MobileLanguageToString(application->ui_language()); + + const auto warning_message = + policy_handler_->LockScreenDismissalWarningMessage(language); + // Only allow lock screen dismissal if a warning message is available + if (warning_message && !warning_message->empty()) { + msg_params[mobile_notification::lock_screen_dismissal_warning] = + *warning_message; + } else { + dismissal_enabled = false; + } + } msg_params[mobile_notification::lock_screen_dismissal_enabled] = - *lock_screen_dismissal; + dismissal_enabled; } params[strings::connection_key] = application->app_id(); diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc index 8dc57b96b0..d2e911f227 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -332,6 +332,15 @@ std::string MessageHelper::CommonLanguageToString( return std::string(); } +std::string MessageHelper::MobileLanguageToString( + mobile_apis::Language::eType language) { + using namespace ns_smart_device_link::ns_smart_objects; + const char* str = 0; + EnumConversionHelper::EnumToCString(language, + &str); + return str ? str : std::string(); +} + smart_objects::SmartObjectSPtr MessageHelper::CreateMessageForHMI( hmi_apis::messageType::eType message_type, const uint32_t correlation_id) { using namespace smart_objects; diff --git a/src/components/application_manager/src/smart_object_keys.cc b/src/components/application_manager/src/smart_object_keys.cc index 3c0db278b6..411d0a3e8a 100644 --- a/src/components/application_manager/src/smart_object_keys.cc +++ b/src/components/application_manager/src/smart_object_keys.cc @@ -442,6 +442,7 @@ const char* state = "state"; const char* syncp_timeout = "Timeout"; const char* syncp_url = "URL"; const char* lock_screen_dismissal_enabled = "lockScreenDismissalEnabled"; +const char* lock_screen_dismissal_warning = "lockScreenDismissalWarning"; } // namespace mobile_notification namespace hmi_levels { diff --git a/src/components/application_manager/test/include/application_manager/mock_message_helper.h b/src/components/application_manager/test/include/application_manager/mock_message_helper.h index 819ead8d8b..29afd36e52 100644 --- a/src/components/application_manager/test/include/application_manager/mock_message_helper.h +++ b/src/components/application_manager/test/include/application_manager/mock_message_helper.h @@ -168,6 +168,8 @@ class MockMessageHelper { hmi_apis::Common_LightName::eType(const std::string& lightName)); MOCK_METHOD1(CommonLanguageToString, std::string(hmi_apis::Common_Language::eType)); + MOCK_METHOD1(MobileLanguageToString, + std::string(mobile_apis::Language::eType)); MOCK_METHOD2(CreateModuleInfoSO, smart_objects::SmartObjectSPtr(uint32_t function_id, ApplicationManager& app_mngr)); diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc index 522ef3dbd5..3284224237 100644 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -366,6 +366,11 @@ std::string MessageHelper::CommonLanguageToString( return MockMessageHelper::message_helper_mock()->CommonLanguageToString(lang); } +std::string MessageHelper::MobileLanguageToString( + mobile_apis::Language::eType lang) { + return MockMessageHelper::message_helper_mock()->MobileLanguageToString(lang); +} + smart_objects::SmartObjectSPtr MessageHelper::GetBCActivateAppRequestToHMI( ApplicationConstSharedPtr app, const policy::PolicyHandlerInterface& policy_handler, @@ -589,4 +594,5 @@ void MessageHelper::BroadcastCapabilityUpdate( MockMessageHelper::message_helper_mock()->BroadcastCapabilityUpdate( msg_params, app_mngr); } + } // namespace application_manager -- cgit v1.2.1 From f0928e7c0023ca77011c9906edb0accc1962480a Mon Sep 17 00:00:00 2001 From: igapchuck Date: Fri, 28 Jun 2019 15:35:08 +0300 Subject: Unit tests LockScreenDismissalWarning --- .../test/commands/hmi/hmi_notifications_test.cc | 32 ++++ .../hmi/on_driver_distraction_notification_test.cc | 174 ++++++++++++++++++++- 2 files changed, 203 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc index 88be43b4b3..2f8f5c2849 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc @@ -192,6 +192,14 @@ const int32_t kMobileProtocolType_ = 0; const int32_t kProtocolVersion_ = 3; const uint32_t kCorrelationId_ = 1939u; const uint32_t kAppId_ = 2014u; +const std::string kDefaultLanguage = "en-us"; +const mobile_apis::Language::eType kMobileLanguage = + mobile_apis::Language::EN_US; + +// LSDW - lock screen dismissal warning +const std::string kLockScreenDismissalWarningMessage_en = + "Swipe down to dismiss, acknowledging that you are not the driver"; +const uint32_t kConnectionKey = 2u; } // namespace class HMICommandsNotificationsTest @@ -240,6 +248,9 @@ class HMICommandsNotificationsTest .WillByDefault(ReturnRef(mock_event_dispatcher_)); ON_CALL(app_mngr_, application_by_hmi_app(_)).WillByDefault(Return(app_)); ON_CALL(*app_ptr_, app_id()).WillByDefault(Return(kAppId_)); + ON_CALL(app_mngr_, application(kConnectionKey)).WillByDefault(Return(app_)); + ON_CALL(mock_message_helper_, MobileLanguageToString(kMobileLanguage)) + .WillByDefault(Return(kDefaultLanguage)); } am::ApplicationSharedPtr ConfigureApp(NiceMock** app_mock, @@ -259,6 +270,8 @@ class HMICommandsNotificationsTest .WillByDefault(Return(vc)); ON_CALL(**app_mock, IsAudioApplication()) .WillByDefault(Return(media || navi || vc)); + ON_CALL(**app_mock, ui_language()) + .WillByDefault(ReturnRef(kMobileLanguage)); return app; } #if defined(OS_POSIX) @@ -1793,6 +1806,7 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) { hmi_apis::Common_DriverDistractionState::DD_ON; MessageSharedPtr message = CreateMessage(); (*message)[am::strings::msg_params][am::hmi_notification::state] = state; + (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; std::shared_ptr command = CreateCommand(message); @@ -1804,6 +1818,12 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) { ON_CALL(mock_policy_handler_, LockScreenDismissalEnabledState()) .WillByDefault(Return(OptionalBool(true))); + std::string required_language = "en-us"; + ON_CALL(mock_policy_handler_, + LockScreenDismissalWarningMessage(required_language)) + .WillByDefault(Return( + boost::optional(kLockScreenDismissalWarningMessage_en))); + ON_CALL(app_mngr_, applications()).WillByDefault(Return(applications_)); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); @@ -1816,6 +1836,7 @@ TEST_F(HMICommandsNotificationsTest, const auto state = hmi_apis::Common_DriverDistractionState::DD_ON; MessageSharedPtr message = CreateMessage(); (*message)[am::strings::msg_params][am::hmi_notification::state] = state; + (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; std::shared_ptr command = CreateCommand(message); @@ -1827,6 +1848,11 @@ TEST_F(HMICommandsNotificationsTest, typedef boost::optional OptionalBool; ON_CALL(mock_policy_handler_, LockScreenDismissalEnabledState()) .WillByDefault(Return(OptionalBool(true))); + std::string required_language = "en-us"; + ON_CALL(mock_policy_handler_, + LockScreenDismissalWarningMessage(required_language)) + .WillByDefault(Return( + boost::optional(kLockScreenDismissalWarningMessage_en))); ON_CALL(app_mngr_, applications()).WillByDefault(Return(applications_)); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); @@ -1839,6 +1865,7 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationValidApp) { hmi_apis::Common_DriverDistractionState::DD_ON; MessageSharedPtr message = CreateMessage(); (*message)[am::strings::msg_params][am::mobile_notification::state] = state; + (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; std::shared_ptr command = CreateCommand(message); @@ -1849,6 +1876,11 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationValidApp) { typedef boost::optional OptionalBool; ON_CALL(mock_policy_handler_, LockScreenDismissalEnabledState()) .WillByDefault(Return(OptionalBool(true))); + std::string required_language = "en-us"; + ON_CALL(mock_policy_handler_, + LockScreenDismissalWarningMessage(required_language)) + .WillByDefault(Return( + boost::optional(kLockScreenDismissalWarningMessage_en))); ON_CALL(app_mngr_, applications()).WillByDefault(Return(applications_)); policy::CheckPermissionResult result; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc index 38c21cfbc4..5e0083d395 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc @@ -52,10 +52,12 @@ namespace hmi_commands_test { namespace on_driver_distraction_notification { using ::testing::_; +using ::testing::DoAll; using ::testing::Eq; using ::testing::NiceMock; using ::testing::Return; using ::testing::SaveArg; +using ::testing::SetArgumentPointee; namespace am = ::application_manager; using am::commands::MessageSharedPtr; @@ -63,6 +65,17 @@ using sdl_rpc_plugin::commands::hmi::OnDriverDistractionNotification; using namespace am::commands; using test::components::commands_test::MobileResultCodeIs; +namespace { +const std::string kDefaultLanguage = "en-us"; +const mobile_apis::Language::eType kMobileLanguage = + mobile_apis::Language::EN_US; + +// LSDW - lock screen dismissal warning +const std::string kLockScreenDismissalWarningMessage_en = + "Swipe down to dismiss, acknowledging that you are not the driver"; +const uint32_t kConnectionKey = 2u; +} // namespace + class HMIOnDriverDistractionNotificationTest : public CommandsTest { public: @@ -77,6 +90,15 @@ class HMIOnDriverDistractionNotificationTest typedef std::shared_ptr NotificationPtr; typedef boost::optional OptionalBool; + void SetUp() OVERRIDE { + ON_CALL(*mock_app_, ui_language()) + .WillByDefault(ReturnRef(kMobileLanguage)); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(mock_message_helper_, MobileLanguageToString(kMobileLanguage)) + .WillByDefault(Return(kDefaultLanguage)); + } + MockAppPtr mock_app_; std::shared_ptr app_set_lock_; am::ApplicationSet app_set_; @@ -108,11 +130,21 @@ ACTION_P(GetArg3, result) { arg3 = *result; } +ACTION_P(SetMessage, lockScreenDismissalWarning) { + smart_objects::SmartObject& notification = arg0; + + notification[application_manager::strings::msg_params] + [application_manager::mobile_notification:: + lock_screen_dismissal_warning] = lockScreenDismissalWarning; +} + TEST_F(HMIOnDriverDistractionNotificationTest, Run_SendNotificationToMobile_SUCCESS) { const auto state = hmi_apis::Common_DriverDistractionState::DD_ON; MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; + (*commands_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; NotificationPtr command( CreateCommand(commands_msg)); @@ -122,17 +154,34 @@ TEST_F(HMIOnDriverDistractionNotificationTest, ON_CALL(mock_policy_handler_interface_, LockScreenDismissalEnabledState()) .WillByDefault(Return(OptionalBool(true))); + ON_CALL(mock_policy_handler_interface_, LockScreenDismissalWarningMessage(_)) + .WillByDefault(Return(kLockScreenDismissalWarningMessage_en)); + policy::CheckPermissionResult result; result.hmi_level_permitted = policy::kRpcAllowed; EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) .WillOnce(GetArg3(&result)); + MessageSharedPtr message_to_mobile( + CreateMessage(smart_objects::SmartType_Map)); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand( CheckNotificationParams( am::mobile_api::FunctionID::OnDriverDistractionID, state), - Command::CommandSource::SOURCE_SDL)); + Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&message_to_mobile), Return(true))); command->Run(); + + ASSERT_TRUE((*message_to_mobile)[am::strings::msg_params].keyExists( + am::mobile_notification::lock_screen_dismissal_warning)); + + auto LSDW_message = + (*message_to_mobile) + [am::strings::msg_params] + [am::mobile_notification::lock_screen_dismissal_warning] + .asString(); + + EXPECT_EQ(kLockScreenDismissalWarningMessage_en, LSDW_message); } TEST_F(HMIOnDriverDistractionNotificationTest, @@ -140,22 +189,41 @@ TEST_F(HMIOnDriverDistractionNotificationTest, const auto state = hmi_apis::Common_DriverDistractionState::DD_ON; MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; + (*commands_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; NotificationPtr command( CreateCommand(commands_msg)); ON_CALL(mock_policy_handler_interface_, LockScreenDismissalEnabledState()) - .WillByDefault(Return(OptionalBool(true))); + .WillByDefault(Return(boost::optional(true))); + + ON_CALL(mock_policy_handler_interface_, LockScreenDismissalWarningMessage(_)) + .WillByDefault(Return(kLockScreenDismissalWarningMessage_en)); policy::CheckPermissionResult result; result.hmi_level_permitted = policy::kRpcDisallowed; EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) .WillOnce(GetArg3(&result)); + + MessageSharedPtr pushed_message(CreateMessage(smart_objects::SmartType_Map)); EXPECT_CALL(*mock_app_, PushMobileMessage(CheckNotificationParams( - am::mobile_api::FunctionID::OnDriverDistractionID, state))); + am::mobile_api::FunctionID::OnDriverDistractionID, state))) + .WillOnce(SaveArg<0>(&pushed_message)); EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); command->Run(); + + ASSERT_TRUE((*pushed_message)[am::strings::msg_params].keyExists( + am::mobile_notification::lock_screen_dismissal_warning)); + + auto lock_screen_dismissal_warning_message = + (*pushed_message)[am::strings::msg_params] + [am::mobile_notification::lock_screen_dismissal_warning] + .asString(); + + EXPECT_EQ(kLockScreenDismissalWarningMessage_en, + lock_screen_dismissal_warning_message); } TEST_F(HMIOnDriverDistractionNotificationTest, @@ -186,8 +254,108 @@ TEST_F(HMIOnDriverDistractionNotificationTest, (*command_result)[application_manager::strings::msg_params]; EXPECT_FALSE(msg_params.keyExists( application_manager::mobile_notification::lock_screen_dismissal_enabled)); + EXPECT_FALSE(msg_params.keyExists( + application_manager::mobile_notification::lock_screen_dismissal_warning)); } +// LSDW - lock screen dimissal +TEST_F(HMIOnDriverDistractionNotificationTest, + Run_SendNotificationToMobile_LSDWMessageIsAbsent_SUCCESS) { + const auto state = hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); + (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; + (*commands_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + NotificationPtr command( + CreateCommand(commands_msg)); + + EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); + + ON_CALL(mock_policy_handler_interface_, LockScreenDismissalEnabledState()) + .WillByDefault(Return(OptionalBool(false))); + + // LockScreenDismissalWarning won't be added to message if value of + // LockScreenDismissalEnabledState is false + std::string required_language = "en-us"; + EXPECT_CALL(mock_policy_handler_interface_, + LockScreenDismissalWarningMessage(required_language)) + .Times(0); + + policy::CheckPermissionResult result; + result.hmi_level_permitted = policy::kRpcAllowed; + EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) + .WillOnce(GetArg3(&result)); + + MessageSharedPtr message_to_mobile( + CreateMessage(smart_objects::SmartType_Map)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + CheckNotificationParams( + am::mobile_api::FunctionID::OnDriverDistractionID, state), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&message_to_mobile), Return(true))); + command->Run(); + + EXPECT_FALSE((*message_to_mobile)[am::strings::msg_params].keyExists( + am::mobile_notification::lock_screen_dismissal_warning)); +} + +TEST_F(HMIOnDriverDistractionNotificationTest, + Run_SendNotificationToMobile_SpecifiedLanguageIsAbsent_SUCCESS) { + const auto state = hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); + (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; + (*commands_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + NotificationPtr command( + CreateCommand(commands_msg)); + + EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); + + ON_CALL(mock_policy_handler_interface_, LockScreenDismissalEnabledState()) + .WillByDefault(Return(OptionalBool(true))); + + ON_CALL(mock_policy_handler_interface_, LockScreenDismissalWarningMessage(_)) + .WillByDefault(Return(kLockScreenDismissalWarningMessage_en)); + + // In case when specified language is absent in policy table, will added + // message on default language (en-us) + const mobile_apis::Language::eType mobile_language = + mobile_apis::Language::FR_FR; + std::string required_language = "FR-FR"; + ON_CALL(*mock_app_, ui_language()).WillByDefault(ReturnRef(mobile_language)); + ON_CALL(mock_message_helper_, MobileLanguageToString(mobile_language)) + .WillByDefault(Return(required_language)); + + policy::CheckPermissionResult result; + result.hmi_level_permitted = policy::kRpcAllowed; + EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) + .WillOnce(GetArg3(&result)); + + MessageSharedPtr message_to_mobile( + CreateMessage(smart_objects::SmartType_Map)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + CheckNotificationParams( + am::mobile_api::FunctionID::OnDriverDistractionID, state), + Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&message_to_mobile), Return(true))); + command->Run(); + + ASSERT_TRUE((*message_to_mobile)[am::strings::msg_params].keyExists( + am::mobile_notification::lock_screen_dismissal_warning)); + + auto lock_screen_dismissal_warning_message = + (*message_to_mobile) + [am::strings::msg_params] + [am::mobile_notification::lock_screen_dismissal_warning] + .asString(); + + EXPECT_EQ(kLockScreenDismissalWarningMessage_en, + lock_screen_dismissal_warning_message); +} } // namespace on_driver_distraction_notification } // namespace hmi_commands_test } // namespace commands_test -- cgit v1.2.1 From 2c83332223342252286f7d33520b83070259ef20 Mon Sep 17 00:00:00 2001 From: igapchuck Date: Wed, 3 Jul 2019 13:39:31 +0300 Subject: Fix not saving consumer friendly messages into DB --- .../policy/policy_regular/src/sql_pt_queries.cc | 5 +++-- .../policy_regular/src/sql_pt_representation.cc | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src') 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 ab57ab989f..b3816d37f8 100644 --- a/src/components/policy/policy_regular/src/sql_pt_queries.cc +++ b/src/components/policy/policy_regular/src/sql_pt_queries.cc @@ -675,8 +675,9 @@ const std::string kInsertLanguage = "INSERT OR IGNORE INTO `language` (`code`) VALUES (?)"; const std::string kInsertMessageString = - "INSERT INTO `message` (`language_code`, `message_type_name`) " - "VALUES (?, ?)"; + "INSERT INTO `message` (`language_code`, `message_type_name`, `tts`, " + "`label`, `line1`, `line2`, `textBody`) " + "VALUES (?, ?, ?, ?, ?, ?, ?)"; const std::string kUpdateModuleConfig = "UPDATE `module_config` SET `preloaded_pt` = ?, " 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 bcd3322b0d..8ac04ba5f3 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -1524,6 +1524,25 @@ bool SQLPTRepresentation::SaveMessageString( query.Bind(0, lang); query.Bind(1, type); + if (strings.tts.is_valid() && strings.tts.is_initialized()) { + query.Bind(2, (*strings.tts)); + } + + if (strings.label.is_valid() && strings.label.is_initialized()) { + query.Bind(3, (*strings.label)); + } + + if (strings.line1.is_valid() && strings.line1.is_initialized()) { + query.Bind(4, *(strings.line1)); + } + + if (strings.line2.is_valid() && strings.line2.is_initialized()) { + query.Bind(5, (*strings.line2)); + } + + if (strings.textBody.is_valid() && strings.textBody.is_initialized()) { + query.Bind(6, (*strings.textBody)); + } if (!query.Exec() || !query.Reset()) { LOG4CXX_WARN(logger_, "Incorrect insert into message."); -- cgit v1.2.1