diff options
author | JackLivio <jack@livio.io> | 2018-07-16 10:49:26 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-16 10:49:26 -0400 |
commit | d0cb486decd9dec7be5492e1000f1c4ed28c8cc5 (patch) | |
tree | 4ff40e4384efd05dd3aeac9f177b658060e10f79 | |
parent | 45109a01ccfd5176c4eba28bcbcfb5bf9148b46c (diff) | |
parent | 8cfa86d9e6288cbce752c585712af8c56103b885 (diff) | |
download | sdl_core-d0cb486decd9dec7be5492e1000f1c4ed28c8cc5.tar.gz |
Merge pull request #2306 from smartdevicelink/feature/onRcStatus_allowed
Update OnRCStatus with a new allowed parameter
8 files changed, 260 insertions, 20 deletions
diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h index 98da8bc27d..20bd438494 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h @@ -56,6 +56,19 @@ enum eType { FREE = 0, BUSY }; } /** + * Defines triggers for OnRCStatus notification sending + */ +namespace NotificationTrigger { +/** + * @brief The eType + * APP_REGISTRATION RC app registation event + * RC_STATE_CHANGING enabling/disabling RC on HMI event + * MODULE_ALLOCATION module allocation/deallocation event + */ +enum eType { APP_REGISTRATION = 0, MODULE_ALLOCATION, RC_STATE_CHANGING }; +} + +/** * @brief Resources defines list of resources */ typedef std::vector<std::string> Resources; @@ -146,9 +159,16 @@ class ResourceAllocationManager { /** * @brief Create and send OnRCStatusNotification to mobile and HMI - * @param application + * @param event trigger for notification sending + * @param application - app that should receive notification + * in case of registration; in cases of RC enabling/disabling + * or module allocation - application is just empty shared ptr, + * because in these cases all registered RC apps should + * receive a notification */ - virtual void SendOnRCStatusNotification() = 0; + virtual void SendOnRCStatusNotifications( + NotificationTrigger::eType event, + application_manager::ApplicationSharedPtr application) = 0; virtual bool is_rc_enabled() const = 0; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h index 4c72e9ea2c..d6124a026b 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h @@ -118,7 +118,9 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { RCAppExtensionPtr GetApplicationExtention( application_manager::ApplicationSharedPtr application) FINAL; - void SendOnRCStatusNotification() FINAL; + void SendOnRCStatusNotifications( + NotificationTrigger::eType event, + application_manager::ApplicationSharedPtr application) FINAL; bool is_rc_enabled() const FINAL; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc index dda59ea296..ca96b1cf97 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc @@ -150,8 +150,8 @@ void RCOnRemoteControlSettingsNotification::Run() { } else { LOG4CXX_DEBUG(logger_, "Disallowing RC Functionality"); DisallowRCFunctionality(); - resource_allocation_manager_.set_rc_enabled(false); resource_allocation_manager_.ResetAllAllocations(); + resource_allocation_manager_.set_rc_enabled(false); } } diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc index a001e4734f..4378f1ea48 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc @@ -91,9 +91,8 @@ void RCRPCPlugin::OnApplicationEvent( switch (event) { case plugins::kApplicationRegistered: { application->AddExtension(new RCAppExtension(kRCPluginID)); - if (resource_allocation_manager_->is_rc_enabled()) { - resource_allocation_manager_->SendOnRCStatusNotification(); - } + resource_allocation_manager_->SendOnRCStatusNotifications( + NotificationTrigger::APP_REGISTRATION, application); break; } case plugins::kApplicationExit: { diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc index 1d2dbf8997..2ac31e7662 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc @@ -174,7 +174,11 @@ void ResourceAllocationManagerImpl::ProcessApplicationPolicyUpdate() { if (rc_extention) { rc_extention->UnsubscribeFromInteriorVehicleData(*module); } - SendOnRCStatusNotification(); + } + if (!disallowed_modules.empty()) { + SendOnRCStatusNotifications( + NotificationTrigger::MODULE_ALLOCATION, + utils::SharedPtr<application_manager::Application>()); } } } @@ -234,7 +238,6 @@ void ConstructOnRCStatusNotificationParams( using smart_objects::SmartType_Map; using smart_objects::SmartType_Array; LOG4CXX_AUTO_TRACE(logger_); - auto modules_inserter = [](SmartObject& result_modules) { return [&result_modules](const std::string& module_name) { smart_objects::SmartObject module_data = @@ -257,6 +260,7 @@ void ConstructOnRCStatusNotificationParams( modules_inserter(free_modules)(module); } } + msg_params[message_params::kAllocatedModules] = allocated_modules; msg_params[message_params::kFreeModules] = free_modules; } @@ -269,8 +273,17 @@ ResourceAllocationManagerImpl::CreateOnRCStatusNotificationToMobile( auto msg_to_mobile = MessageHelper::CreateNotification( mobile_apis::FunctionID::OnRCStatusID, app->app_id()); auto& msg_params = (*msg_to_mobile)[application_manager::strings::msg_params]; - ConstructOnRCStatusNotificationParams( - msg_params, allocated_resources_, all_supported_modules(), app->app_id()); + if (is_rc_enabled()) { + ConstructOnRCStatusNotificationParams(msg_params, + allocated_resources_, + all_supported_modules(), + app->app_id()); + } else { + msg_params[message_params::kAllocatedModules] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + msg_params[message_params::kFreeModules] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + } return msg_to_mobile; } @@ -292,17 +305,33 @@ void ResourceAllocationManagerImpl::SetResourceAquired( const std::string& module_type, const uint32_t app_id) { LOG4CXX_AUTO_TRACE(logger_); allocated_resources_[module_type] = app_id; - SendOnRCStatusNotification(); + SendOnRCStatusNotifications( + NotificationTrigger::MODULE_ALLOCATION, + utils::SharedPtr<application_manager::Application>()); } -void ResourceAllocationManagerImpl::SendOnRCStatusNotification() { +void ResourceAllocationManagerImpl::SendOnRCStatusNotifications( + NotificationTrigger::eType event, + application_manager::ApplicationSharedPtr application) { LOG4CXX_AUTO_TRACE(logger_); - auto rc_apps = RCRPCPlugin::GetRCApplications(app_mngr_); - for (const auto& rc_app : rc_apps) { - auto msg_to_mobile = CreateOnRCStatusNotificationToMobile(rc_app); + smart_objects::SmartObjectSPtr msg_to_mobile; + smart_objects::SmartObjectSPtr msg_to_hmi; + if (NotificationTrigger::APP_REGISTRATION == event) { + DCHECK(application); + msg_to_mobile = CreateOnRCStatusNotificationToMobile(application); + (*msg_to_mobile)[application_manager::strings::msg_params] + [message_params::kAllowed] = is_rc_enabled(); rpc_service_.SendMessageToMobile(msg_to_mobile); - auto msg_to_hmi = CreateOnRCStatusNotificationToHmi(rc_app); - rpc_service_.SendMessageToHMI(msg_to_hmi); + } else { + auto rc_apps = RCRPCPlugin::GetRCApplications(app_mngr_); + for (const auto& rc_app : rc_apps) { + msg_to_mobile = CreateOnRCStatusNotificationToMobile(rc_app); + (*msg_to_mobile)[application_manager::strings::msg_params] + [message_params::kAllowed] = is_rc_enabled(); + rpc_service_.SendMessageToMobile(msg_to_mobile); + msg_to_hmi = CreateOnRCStatusNotificationToHmi(rc_app); + rpc_service_.SendMessageToHMI(msg_to_hmi); + } } } @@ -312,6 +341,9 @@ bool ResourceAllocationManagerImpl::is_rc_enabled() const { void ResourceAllocationManagerImpl::set_rc_enabled(const bool value) { is_rc_enabled_ = value; + SendOnRCStatusNotifications( + NotificationTrigger::RC_STATE_CHANGING, + utils::SharedPtr<application_manager::Application>()); } void ResourceAllocationManagerImpl::SetResourceFree( @@ -476,7 +508,9 @@ void ResourceAllocationManagerImpl::OnApplicationEvent( ReleaseResource(*module, application->app_id()); } if (!acquired_modules.empty()) { - SendOnRCStatusNotification(); + SendOnRCStatusNotifications( + NotificationTrigger::MODULE_ALLOCATION, + utils::SharedPtr<application_manager::Application>()); } Apps app_list; app_list.push_back(application); diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h index df0daad0b9..d74e8fcb65 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h @@ -65,7 +65,9 @@ class MockResourceAllocationManager rc_rpc_plugin::RCAppExtensionPtr( application_manager::ApplicationSharedPtr application)); MOCK_METHOD0(ResetAllAllocations, void()); - MOCK_METHOD0(SendOnRCStatusNotification, void()); + MOCK_METHOD2(SendOnRCStatusNotifications, + void(rc_rpc_plugin::NotificationTrigger::eType, + application_manager::ApplicationSharedPtr application)); MOCK_CONST_METHOD0(is_rc_enabled, bool()); MOCK_METHOD1(set_rc_enabled, void(const bool value)); }; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc index 1c38c2788d..4bbf2b02dc 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc @@ -34,6 +34,7 @@ #include "rc_rpc_plugin/resource_allocation_manager_impl.h" #include "rc_rpc_plugin/rc_rpc_plugin.h" +#include "rc_rpc_plugin/rc_module_constants.h" #include "application_manager/mock_application.h" #include "application_manager/mock_application_manager.h" #include "application_manager/mock_rpc_service.h" @@ -69,8 +70,10 @@ const std::string kModuleType2 = "RADIO"; const int32_t kConnectionKey = 5; const int32_t kCorrelationId = 5; const uint32_t kAppId1 = 11u; +const uint32_t kHMIAppId1 = 1u; const uint32_t kAppId2 = 22u; const std::string policy_app_id_1_ = "policy_id_1"; +const uint32_t kSizeOfModules = 2u; } namespace rc_rpc_plugin_test { @@ -503,4 +506,179 @@ TEST_F(RAManagerTest, GetAccessMode_ExpectedSameAsHadSet) { ra_manager.GetAccessMode()); } +TEST_F(RAManagerTest, OnRCStatus_AppRegistation_RC_allowed) { + // Arrange + ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ON_CALL((*mock_app_1_), is_remote_control_supported()) + .WillByDefault(Return(true)); + ON_CALL((*mock_app_1_), hmi_app_id()).WillByDefault(Return(kHMIAppId1)); + + application_manager::commands::MessageSharedPtr message_to_mob; + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, false)) + .WillOnce(SaveArg<0>(&message_to_mob)); + application_manager::commands::MessageSharedPtr message_to_hmi; + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + // Act + ra_manager.SendOnRCStatusNotifications(NotificationTrigger::APP_REGISTRATION, + mock_app_1_); + + auto msg_to_mob_params = + (*message_to_mob)[application_manager::strings::msg_params]; + + // Assert + EXPECT_EQ(msg_to_mob_params[message_params::kAllowed].asBool(), true); + EXPECT_EQ( + msg_to_mob_params[message_params::kAllocatedModules].asArray()->size(), + 0u); + EXPECT_EQ(msg_to_mob_params[message_params::kFreeModules].asArray()->size(), + kSizeOfModules); +} + +TEST_F(RAManagerTest, OnRCStatus_AppRegistation_RC_disallowed) { + // Arrange + ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ra_manager.set_rc_enabled(false); + + ON_CALL((*mock_app_1_), is_remote_control_supported()) + .WillByDefault(Return(true)); + + application_manager::commands::MessageSharedPtr message_to_mob; + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, false)) + .WillOnce(SaveArg<0>(&message_to_mob)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + // Act + ra_manager.SendOnRCStatusNotifications(NotificationTrigger::APP_REGISTRATION, + mock_app_1_); + + auto msg_to_mob_params = + (*message_to_mob)[application_manager::strings::msg_params]; + // Assert + EXPECT_EQ(msg_to_mob_params[message_params::kAllowed].asBool(), false); + EXPECT_EQ( + msg_to_mob_params[message_params::kAllocatedModules].asArray()->size(), + 0u); + EXPECT_EQ(msg_to_mob_params[message_params::kFreeModules].asArray()->size(), + 0u); +} + +TEST_F(RAManagerTest, OnRCStatus_RCStateChanging_RC_disabling) { + // Arrange + ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ON_CALL((*mock_app_1_), is_remote_control_supported()) + .WillByDefault(Return(true)); + ON_CALL((*mock_app_1_), hmi_app_id()).WillByDefault(Return(kHMIAppId1)); + + application_manager::commands::MessageSharedPtr message_to_mob; + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, false)) + .WillOnce(SaveArg<0>(&message_to_mob)); + application_manager::commands::MessageSharedPtr message_to_hmi; + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)) + .WillOnce(SaveArg<0>(&message_to_hmi)); + + // Act + ra_manager.set_rc_enabled(false); + + auto msg_to_mob_params = + (*message_to_mob)[application_manager::strings::msg_params]; + auto msg_to_hmi_params = + (*message_to_hmi)[application_manager::strings::msg_params]; + // Assert + EXPECT_EQ(msg_to_mob_params[message_params::kAllowed].asBool(), false); + EXPECT_EQ( + msg_to_mob_params[message_params::kAllocatedModules].asArray()->size(), + 0u); + EXPECT_EQ(msg_to_mob_params[message_params::kFreeModules].asArray()->size(), + 0u); + EXPECT_EQ( + msg_to_hmi_params[message_params::kAllocatedModules].asArray()->size(), + 0u); + EXPECT_EQ(msg_to_hmi_params[message_params::kFreeModules].asArray()->size(), + kSizeOfModules); + EXPECT_EQ(msg_to_hmi_params[application_manager::strings::app_id].asInt(), + kHMIAppId1); +} + +TEST_F(RAManagerTest, OnRCStatus_RCStateChanging_RC_enabling) { + // Arrange + ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + ON_CALL((*mock_app_1_), is_remote_control_supported()) + .WillByDefault(Return(true)); + ON_CALL((*mock_app_1_), hmi_app_id()).WillByDefault(Return(kHMIAppId1)); + + application_manager::commands::MessageSharedPtr message_to_mob; + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, false)) + .WillOnce(SaveArg<0>(&message_to_mob)); + application_manager::commands::MessageSharedPtr message_to_hmi; + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)) + .WillOnce(SaveArg<0>(&message_to_hmi)); + + // Act + ra_manager.set_rc_enabled(true); + + auto msg_to_mob_params = + (*message_to_mob)[application_manager::strings::msg_params]; + auto msg_to_hmi_params = + (*message_to_hmi)[application_manager::strings::msg_params]; + // Assert + EXPECT_EQ(msg_to_mob_params[message_params::kAllowed].asBool(), true); + EXPECT_EQ( + msg_to_mob_params[message_params::kAllocatedModules].asArray()->size(), + 0u); + EXPECT_EQ(msg_to_mob_params[message_params::kFreeModules].asArray()->size(), + kSizeOfModules); + EXPECT_EQ( + msg_to_hmi_params[message_params::kAllocatedModules].asArray()->size(), + 0u); + EXPECT_EQ(msg_to_hmi_params[message_params::kFreeModules].asArray()->size(), + kSizeOfModules); + EXPECT_EQ(msg_to_hmi_params[application_manager::strings::app_id].asInt(), + kHMIAppId1); +} + +TEST_F(RAManagerTest, OnRCStatus_ModuleAllocation) { + // Arrange + ResourceAllocationManagerImpl ra_manager(mock_app_mngr_, mock_rpc_service_); + + ON_CALL((*mock_app_1_), is_remote_control_supported()) + .WillByDefault(Return(true)); + ON_CALL((*mock_app_1_), hmi_app_id()).WillByDefault(Return(kHMIAppId1)); + + EXPECT_EQ(rc_rpc_plugin::AcquireResult::ALLOWED, + ra_manager.AcquireResource(kModuleType1, kAppId1)); + + application_manager::commands::MessageSharedPtr message_to_mob; + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, false)) + .WillOnce(SaveArg<0>(&message_to_mob)); + + application_manager::commands::MessageSharedPtr message_to_hmi; + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)) + .WillOnce(SaveArg<0>(&message_to_hmi)); + + // Act + ra_manager.SendOnRCStatusNotifications( + NotificationTrigger::MODULE_ALLOCATION, + utils::SharedPtr<application_manager::Application>()); + + auto msg_to_mob_params = + (*message_to_mob)[application_manager::strings::msg_params]; + auto msg_to_hmi_params = + (*message_to_hmi)[application_manager::strings::msg_params]; + // Assert + EXPECT_EQ(msg_to_mob_params[message_params::kAllowed].asBool(), true); + EXPECT_EQ( + msg_to_mob_params[message_params::kAllocatedModules].asArray()->size(), + 1u); + EXPECT_EQ(msg_to_mob_params[message_params::kFreeModules].asArray()->size(), + kSizeOfModules - 1u); + EXPECT_EQ( + msg_to_hmi_params[message_params::kAllocatedModules].asArray()->size(), + 1u); + EXPECT_EQ(msg_to_hmi_params[message_params::kFreeModules].asArray()->size(), + kSizeOfModules - 1u); + EXPECT_EQ(msg_to_hmi_params[application_manager::strings::app_id].asInt(), + kHMIAppId1); +} + } // namespace rc_rpc_plugin diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml index a751447bd3..2766bb48d0 100644 --- a/src/components/interfaces/MOBILE_API.xml +++ b/src/components/interfaces/MOBILE_API.xml @@ -6345,6 +6345,11 @@ <function name="OnRCStatus" functionID="OnRCStatusID" messagetype="notification"> <description>Issued by SDL to notify the application about remote control status change on SDL</description> + <param name="allowed" type="Boolean" mandatory="false"> + <description> + If "true" - RC is allowed; if "false" - RC is disallowed. + </description> + </param> <param name="allocatedModules" type="ModuleData" minsize="0" maxsize="100" array="true" mandatory="true"> <description>Contains a list (zero or more) of module types that are allocated to the application.</description> </param> |