diff options
36 files changed, 474 insertions, 51 deletions
diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 4b1f8a4601..e88c954c18 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -1138,6 +1138,14 @@ class ApplicationManagerImpl private: /** + * @brief Removes service status record for service that failed to start + * @param app Application whose service status record should be removed + * @param Service type which status record should be removed + */ + bool HandleRejectedServiceStatus( + ApplicationSharedPtr app, + const hmi_apis::Common_ServiceType::eType service_type); + /** * @brief PullLanguagesInfo allows to pull information about languages. * * @param app_data entry to parse diff --git a/src/components/application_manager/include/application_manager/policies/custom_vehicle_data_provider.h b/src/components/application_manager/include/application_manager/policies/custom_vehicle_data_provider.h index edd0a29c48..307f0b93df 100644 --- a/src/components/application_manager/include/application_manager/policies/custom_vehicle_data_provider.h +++ b/src/components/application_manager/include/application_manager/policies/custom_vehicle_data_provider.h @@ -19,6 +19,13 @@ class VehicleDataItemProvider { */ virtual const std::vector<rpc::policy_table_interface_base::VehicleDataItem> GetVehicleDataItems() const = 0; + + /** + * @brief Gets vehicle data items removed by policies + * @return Structure with vehicle data items + */ + virtual std::vector<rpc::policy_table_interface_base::VehicleDataItem> + GetRemovedVehicleDataItems() const = 0; }; } // namespace policy 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 61cf2cf480..e4d4cd7fa2 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 @@ -704,6 +704,9 @@ class PolicyHandler : public PolicyHandlerInterface, const std::vector<rpc::policy_table_interface_base::VehicleDataItem> GetVehicleDataItems() const OVERRIDE; + std::vector<rpc::policy_table_interface_base::VehicleDataItem> + GetRemovedVehicleDataItems() const OVERRIDE; + void OnLockScreenDismissalStateChanged() FINAL; protected: diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager.h index b34a9f84b8..9cac76b954 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager.h @@ -41,6 +41,15 @@ class CustomVehicleDataManager { virtual void OnPolicyEvent(plugin_manager::PolicyEvent policy_event) = 0; virtual bool IsValidCustomVehicleDataName(const std::string& name) const = 0; + + /** + * @brief Checks whether custom vehicle data name was removed after the last + * PTU or not + * @param name vehicle item name to check + * @return true if vehicle data with this name was removed after the last PTU + */ + virtual bool IsRemovedCustomVehicleDataName( + const std::string& name) const = 0; }; } // namespace vehicle_info_plugin #endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_VEHICLE_INFO_PLUGIN_INCLUDE_VEHICLE_INFO_PLUGIN_CUSTOM_VEHICLE_DATA_MANAGER_H_ diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager_impl.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager_impl.h index 701bb1ba74..239c4edb90 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager_impl.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/custom_vehicle_data_manager_impl.h @@ -42,6 +42,8 @@ class CustomVehicleDataManagerImpl : public CustomVehicleDataManager { bool IsValidCustomVehicleDataName(const std::string& name) const OVERRIDE; + bool IsRemovedCustomVehicleDataName(const std::string& name) const OVERRIDE; + private: class RPCParams { public: @@ -83,6 +85,8 @@ class CustomVehicleDataManagerImpl : public CustomVehicleDataManager { const OptionalDataItem FindSchemaByNameNonRecursive( const std::string& name) const; + const OptionalDataItem FindRemovedSchemaByNameNonRecursive( + const std::string& name) const; const OptionalDataItem FindSchemaByKeyNonRecursive( const std::string& key) const; const OptionalDataItem FindSchemaByNameRecursive( diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h index 3f6c078522..f0f68af298 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/vehicle_info_plugin.h @@ -72,6 +72,7 @@ class VehicleInfoPlugin : public plugins::RPCPlugin { VehicleInfoAppExtension& ext); private: + void UnsubscribeFromRemovedVDItems(); smart_objects::SmartObjectSPtr GetUnsubscribeIVIRequest( const std::vector<std::string>& ivi_names); void DeleteSubscriptions(app_mngr::ApplicationSharedPtr app); diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc index 334c876d76..ecd6be207b 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc @@ -77,6 +77,12 @@ bool CustomVehicleDataManagerImpl::IsValidCustomVehicleDataName( return schema.is_initialized(); } +bool CustomVehicleDataManagerImpl::IsRemovedCustomVehicleDataName( + const std::string& name) const { + const auto& schema = FindRemovedSchemaByNameNonRecursive(name); + return schema.is_initialized(); +} + void CustomVehicleDataManagerImpl::CreateMobileMessageParams( smart_objects::SmartObject& msg_params) { using namespace application_manager; @@ -174,6 +180,12 @@ smart_objects::SmartObject CustomVehicleDataManagerImpl::CreateHMIMessageParams( auto schema = FindSchemaByNameNonRecursive(name); if (schema.is_initialized()) { fill_param(fill_hmi_params, *schema, &out_params); + continue; + } + + auto removed_schema = FindRemovedSchemaByNameNonRecursive(name); + if (removed_schema.is_initialized()) { + fill_param(fill_hmi_params, *removed_schema, &out_params); } } @@ -497,6 +509,21 @@ CustomVehicleDataManagerImpl::FindSchemaByNameNonRecursive( return FindSchema(oem_items, SearchMethod::NON_RECURSIVE, compare_by_name); } +const OptionalDataItem +CustomVehicleDataManagerImpl::FindRemovedSchemaByNameNonRecursive( + const std::string& name) const { + LOG4CXX_AUTO_TRACE(logger_); + + const auto& removed_oem_items = + vehicle_data_provider_.GetRemovedVehicleDataItems(); + auto compare_by_name = [&name](const policy_table::VehicleDataItem& item) { + return (name == std::string(item.name)); + }; + + return FindSchema( + removed_oem_items, SearchMethod::NON_RECURSIVE, compare_by_name); +} + const OptionalDataItem CustomVehicleDataManagerImpl::FindSchemaByNameRecursive( const std::string& name) const { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc index d6d1c69461..40da7501c1 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc @@ -81,6 +81,7 @@ app_mngr::CommandFactory& VehicleInfoPlugin::GetCommandFactory() { } void VehicleInfoPlugin::OnPolicyEvent(plugins::PolicyEvent event) { + UnsubscribeFromRemovedVDItems(); custom_vehicle_data_manager_->OnPolicyEvent(event); } @@ -96,6 +97,43 @@ void VehicleInfoPlugin::OnApplicationEvent( } } +void VehicleInfoPlugin::UnsubscribeFromRemovedVDItems() { + typedef std::vector<std::string> StringsVector; + + auto get_items_to_unsubscribe = [this]() -> StringsVector { + StringsVector output_items_list; + auto applications = application_manager_->applications(); + for (auto& app : applications.GetData()) { + auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); + auto subscription_names = ext.Subscriptions(); + for (auto& subscription_name : subscription_names) { + if (custom_vehicle_data_manager_->IsRemovedCustomVehicleDataName( + subscription_name)) { + ext.unsubscribeFromVehicleInfo(subscription_name); + if (!helpers::in_range(output_items_list, subscription_name)) { + LOG4CXX_DEBUG(logger_, + "Vehicle data item " + << subscription_name + << " has been removed by policy"); + output_items_list.push_back(subscription_name); + } + } + } + } + return output_items_list; + }; + + const StringsVector items_to_unsubscribe = get_items_to_unsubscribe(); + + if (items_to_unsubscribe.empty()) { + LOG4CXX_DEBUG(logger_, "There is no data to unsubscribe"); + return; + } + + auto message = GetUnsubscribeIVIRequest(items_to_unsubscribe); + application_manager_->GetRPCService().ManageHMICommand(message); +} + void VehicleInfoPlugin::ProcessResumptionSubscription( application_manager::Application& app, VehicleInfoAppExtension& ext) { LOG4CXX_AUTO_TRACE(logger_); @@ -103,9 +141,15 @@ void VehicleInfoPlugin::ProcessResumptionSubscription( smart_objects::SmartObject(smart_objects::SmartType_Map); msg_params[strings::app_id] = app.app_id(); const auto& subscriptions = ext.Subscriptions(); + if (subscriptions.empty()) { + LOG4CXX_DEBUG(logger_, "No vehicle data to subscribe. Exiting"); + return; + } + for (const auto& item : subscriptions) { msg_params[item] = true; } + smart_objects::SmartObjectSPtr request = application_manager::MessageHelper::CreateModuleInfoSO( hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData, @@ -151,6 +195,8 @@ smart_objects::SmartObjectSPtr VehicleInfoPlugin::GetUnsubscribeIVIRequest( if (key_name.empty()) { // the name hasn't been found in vehicle data types if (custom_vehicle_data_manager_->IsValidCustomVehicleDataName( + ivi_name) || + custom_vehicle_data_manager_->IsRemovedCustomVehicleDataName( ivi_name)) { key_name = ivi_name; } diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/custom_vehicle_data_manager_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/custom_vehicle_data_manager_test.cc index 2ef2d285ab..7d65d989bf 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/custom_vehicle_data_manager_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/custom_vehicle_data_manager_test.cc @@ -60,6 +60,8 @@ class CustomVehicleDataManagerTest : public ::testing::Test { ON_CALL(mock_custom_vehicle_data_provider_, GetVehicleDataItems()) .WillByDefault(Return(items)); + ON_CALL(mock_custom_vehicle_data_provider_, GetRemovedVehicleDataItems()) + .WillByDefault(Return(policy_table::VehicleDataItems())); custom_vd_manager_.reset(new CustomVehicleDataManagerImpl( mock_custom_vehicle_data_provider_, mock_rpc_service_)); } diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/mock_custom_vehicle_data_manager.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/mock_custom_vehicle_data_manager.h index 472568d378..9a7435f980 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/mock_custom_vehicle_data_manager.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/include/vehicle_info_plugin/mock_custom_vehicle_data_manager.h @@ -18,6 +18,8 @@ class MockCustomVehicleDataManager : public CustomVehicleDataManager { MOCK_METHOD1(OnPolicyEvent, void(plugin_manager::PolicyEvent policy_event)); MOCK_CONST_METHOD1(IsValidCustomVehicleDataName, bool(const std::string& name)); + MOCK_CONST_METHOD1(IsRemovedCustomVehicleDataName, + bool(const std::string& name)); }; } // namespace vehicle_info_plugin diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 4cd1a7764f..8044e8b6cd 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -2068,6 +2068,51 @@ void ApplicationManagerImpl::ProcessServiceStatusUpdate( service_type, service_event, reason, app_id); rpc_service_->ManageHMICommand(notification); + + if (hmi_apis::Common_ServiceEvent::REQUEST_REJECTED == service_event && + HandleRejectedServiceStatus(app, service_type)) { + state_ctrl_.SetRegularState(app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + mobile_apis::HMILevel::HMI_NONE, + true); + } +} + +bool ApplicationManagerImpl::HandleRejectedServiceStatus( + ApplicationSharedPtr app, + const hmi_apis::Common_ServiceType::eType service_type) { + LOG4CXX_AUTO_TRACE(logger_); + if (!app) { + LOG4CXX_WARN(logger_, "Received invalid app"); + return false; + } + + switch (service_type) { + case hmi_apis::Common_ServiceType::VIDEO: + case hmi_apis::Common_ServiceType::AUDIO: { + { + sync_primitives::AutoLock lock(navi_service_status_lock_); + auto app_services = navi_service_status_.find(app->app_id()); + if (navi_service_status_.end() != app_services) { + navi_service_status_.erase(app_services); + } + } + LOG4CXX_DEBUG(logger_, + "The start of service" + << service_type << " for appID: " << app + << " is failed. Service info has been removed"); + return true; + } + case hmi_apis::Common_ServiceType::RPC: { + connection_handler().SendEndService(app->app_id(), + protocol_handler::ServiceType::kRpc); + LOG4CXX_DEBUG(logger_, "RPC service for appID: " << app << " is stopped"); + return true; + } + default: + LOG4CXX_DEBUG(logger_, "Unknown service type: " << service_type); + return false; + } } void ApplicationManagerImpl::OnSecondaryTransportStartedCallback( @@ -3365,6 +3410,7 @@ void ApplicationManagerImpl::EndNaviServices(uint32_t app_id) { connection_handler().SendEndService(app_id, ServiceType::kAudio); app->StopStreamingForce(ServiceType::kAudio); } + DisallowStreaming(app_id); navi_app_to_stop_.push_back(app_id); diff --git a/src/components/application_manager/src/hmi_interfaces_impl.cc b/src/components/application_manager/src/hmi_interfaces_impl.cc index d0e888efb2..0c33ea4b11 100644 --- a/src/components/application_manager/src/hmi_interfaces_impl.cc +++ b/src/components/application_manager/src/hmi_interfaces_impl.cc @@ -156,7 +156,6 @@ generate_function_to_interface_convert_map() { convert_map[UI_OnDriverDistraction] = HmiInterfaces::HMI_INTERFACE_UI; convert_map[UI_SetAppIcon] = HmiInterfaces::HMI_INTERFACE_UI; convert_map[UI_SetDisplayLayout] = HmiInterfaces::HMI_INTERFACE_UI; - convert_map[UI_ShowCustomForm] = HmiInterfaces::HMI_INTERFACE_UI; convert_map[UI_OnKeyboardInput] = HmiInterfaces::HMI_INTERFACE_UI; convert_map[UI_OnTouchEvent] = HmiInterfaces::HMI_INTERFACE_UI; convert_map[UI_Slider] = HmiInterfaces::HMI_INTERFACE_UI; diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index b0a4c4586d..09dcb2c7ad 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -2325,6 +2325,11 @@ policy::PolicyHandler::GetVehicleDataItems() const { return policy_manager_->GetVehicleDataItems(); } +std::vector<rpc::policy_table_interface_base::VehicleDataItem> +policy::PolicyHandler::GetRemovedVehicleDataItems() const { + return policy_manager_->GetRemovedVehicleDataItems(); +} + #ifdef EXTERNAL_PROPRIETARY_MODE const MetaInfo PolicyHandler::GetMetaInfo() const { POLICY_LIB_CHECK(MetaInfo()); diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc index ff1a9b047d..152d577cda 100644 --- a/src/components/application_manager/test/application_manager_impl_test.cc +++ b/src/components/application_manager/test/application_manager_impl_test.cc @@ -39,12 +39,14 @@ #include "application_manager/application.h" #include "application_manager/application_impl.h" #include "application_manager/application_manager_impl.h" +#include "application_manager/hmi_state.h" #include "application_manager/mock_app_service_manager.h" #include "application_manager/mock_application.h" #include "application_manager/mock_application_manager_settings.h" #include "application_manager/mock_resumption_data.h" #include "application_manager/mock_rpc_plugin_manager.h" #include "application_manager/mock_rpc_service.h" +#include "application_manager/mock_state_controller.h" #include "application_manager/policies/mock_policy_handler_interface.h" #include "application_manager/resumption/resume_ctrl_impl.h" #include "application_manager/test/include/application_manager/mock_message_helper.h" @@ -88,6 +90,7 @@ using ::testing::SaveArg; using ::testing::SetArgPointee; using ::testing::SetArgReferee; +using test::components::application_manager_test::MockStateController; using test::components::policy_test::MockPolicyHandlerInterface; using namespace application_manager; @@ -98,6 +101,7 @@ ACTION_P6(InvokeMemberFuncWithArg4, ptr, memberFunc, a, b, c, d) { } namespace { +const uint32_t kCorrelationID = 54321u; const std::string kDirectoryName = "./test_storage"; const uint32_t kTimeout = 10000u; connection_handler::DeviceHandle kDeviceId = 12345u; @@ -170,8 +174,21 @@ class ApplicationManagerImplTest protected: void SetUp() OVERRIDE { CreateAppManager(); + ON_CALL(mock_state_ctrl_, + SetRegularState(_, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + mobile_apis::HMILevel::HMI_NONE, + true)); ON_CALL(*mock_app_ptr_, app_id()).WillByDefault(Return(kConnectionKey)); ON_CALL(*mock_app_ptr_, device()).WillByDefault(Return(kDeviceId)); + + HmiStatePtr hmi_state(std::make_shared<HmiState>( + mock_app_ptr_, mock_app_mngr_, HmiState::STATE_ID_REGULAR)); + + ON_CALL(*mock_app_ptr_, + RegularHmiState(mobile_apis::PredefinedWindows::DEFAULT_WINDOW)) + .WillByDefault(Return(hmi_state)); + ON_CALL(mock_session_observer_, GetDataOnSessionKey(_, _, _, _)) .WillByDefault(DoAll(SetArgPointee<3u>(kDeviceId), Return(0))); ON_CALL(mock_connection_handler_, GetDataOnSessionKey(_, _, _, &kDeviceId)) @@ -195,6 +212,9 @@ class ApplicationManagerImplTest smart_objects::SmartType_Map); ON_CALL(*mock_message_helper_, CreateModuleInfoSO(_, _)) .WillByDefault(Return(request)); + ON_CALL(*mock_message_helper_, GetBCCloseApplicationRequestToHMI(_, _)) + .WillByDefault(Return(std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map))); ON_CALL(*mock_policy_handler_, GetStatisticManager()) .WillByDefault(Return(mock_statistics_manager_)); } @@ -221,13 +241,30 @@ class ApplicationManagerImplTest app_manager_impl_.reset(new am::ApplicationManagerImpl( mock_application_manager_settings_, mock_policy_settings_)); - mock_app_ptr_ = std::shared_ptr<MockApplication>(new MockApplication()); + mock_app_ptr_ = std::shared_ptr<NiceMock<MockApplication> >( + new NiceMock<MockApplication>()); app_manager_impl_->set_protocol_handler(&mock_protocol_handler_); app_manager_impl_->SetMockPolicyHandler(mock_policy_handler_); ASSERT_TRUE(app_manager_impl_.get()); ASSERT_TRUE(mock_app_ptr_.get()); } + application_manager::commands::MessageSharedPtr CreateCloseAppMessage() { + using namespace application_manager; + + smart_objects::SmartObjectSPtr message = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + (*message)[application_manager::strings::params] + [application_manager::strings::function_id] = + hmi_apis::FunctionID::BasicCommunication_CloseApplication; + (*message)[strings::params][strings::message_type] = MessageType::kRequest; + (*message)[strings::params][strings::correlation_id] = kCorrelationID; + (*message)[strings::msg_params][strings::app_id] = kAppId; + + return message; + } + void AddMockApplication() { app_manager_impl_->AddMockApplication(mock_app_ptr_); } @@ -273,6 +310,7 @@ class ApplicationManagerImplTest NiceMock<policy_test::MockPolicySettings> mock_policy_settings_; std::shared_ptr<NiceMock<resumption_test::MockResumptionData> > mock_storage_; + MockStateController mock_state_ctrl_; MockRPCService* mock_rpc_service_; resumption_test::MockLastState mock_last_state_; NiceMock<con_test::MockConnectionHandler> mock_connection_handler_; @@ -284,7 +322,7 @@ class ApplicationManagerImplTest MockAppServiceManager* mock_app_service_manager_; application_manager::MockMessageHelper* mock_message_helper_; - std::shared_ptr<MockApplication> mock_app_ptr_; + std::shared_ptr<NiceMock<MockApplication> > mock_app_ptr_; NiceMock<protocol_handler_test::MockProtocolHandler> mock_protocol_handler_; std::shared_ptr<NiceMock<usage_statistics_test::MockStatisticsManager> > mock_statistics_manager_; @@ -344,11 +382,16 @@ TEST_P(ApplicationManagerImplTest, ON_CALL(*mock_app_ptr_, app_id()).WillByDefault(Return(kConnectionKey)); + auto close_message = CreateCloseAppMessage(); + ON_CALL(*mock_message_helper_, GetBCCloseApplicationRequestToHMI(_, _)) + .WillByDefault(Return(close_message)); ON_CALL(*mock_message_helper_, CreateOnServiceUpdateNotification(_, _, _, _)) .WillByDefault(Return(notification_)); - EXPECT_CALL(*mock_rpc_service_, ManageHMICommand(notification_, _)) - .WillOnce(Return(true)); + ON_CALL(*mock_rpc_service_, ManageHMICommand(notification_, _)) + .WillByDefault(Return(true)); + ON_CALL(*mock_rpc_service_, ManageHMICommand(close_message, _)) + .WillByDefault(Return(true)); app_manager_impl_->ProcessServiceStatusUpdate(kConnectionKey, GetParam().service_type_, diff --git a/src/components/application_manager/test/state_controller/state_controller_test.cc b/src/components/application_manager/test/state_controller/state_controller_test.cc index 0fe40366d6..9799dbcac2 100644 --- a/src/components/application_manager/test/state_controller/state_controller_test.cc +++ b/src/components/application_manager/test/state_controller/state_controller_test.cc @@ -71,6 +71,8 @@ using ::testing::ReturnRef; using ::testing::SaveArg; using ::testing::Truly; +using application_manager::MockMessageHelper; + namespace test { namespace components { namespace state_controller_test { @@ -154,7 +156,6 @@ class StateControllerImplTest : public ::testing::Test { ~StateControllerImplTest() { Mock::VerifyAndClearExpectations(&message_helper_mock_); } - NiceMock<application_manager_test::MockApplicationManager> app_manager_mock_; NiceMock<application_manager_test::MockRPCService> mock_rpc_service_; NiceMock<policy_test::MockPolicyHandlerInterface> policy_interface_; @@ -1014,7 +1015,6 @@ class StateControllerImplTest : public ::testing::Test { ON_CALL(app_manager_mock_, event_dispatcher()) .WillByDefault(ReturnRef(mock_event_dispatcher_)); state_ctrl_ = std::make_shared<am::StateControllerImpl>(app_manager_mock_); - ON_CALL(app_manager_mock_, applications()) .WillByDefault(Return(applications_)); ConfigureApps(); @@ -1027,6 +1027,22 @@ class StateControllerImplTest : public ::testing::Test { delete conn_handler; } + application_manager::commands::MessageSharedPtr CreateCloseAppMessage() { + using namespace application_manager; + + smart_objects::SmartObjectSPtr message = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + (*message)[application_manager::strings::params] + [application_manager::strings::function_id] = + hmi_apis::FunctionID::BasicCommunication_CloseApplication; + (*message)[strings::params][strings::message_type] = MessageType::kRequest; + (*message)[strings::params][strings::correlation_id] = kCorrID; + (*message)[strings::msg_params][strings::app_id] = kHMIAppID; + + return message; + } + void SetConnection() { conn_handler = new connection_handler::ConnectionHandlerImpl( mock_connection_handler__settings, mock_transport_manager); @@ -1231,6 +1247,12 @@ class StateControllerImplTest : public ::testing::Test { using smart_objects::SmartObject; namespace FunctionID = hmi_apis::FunctionID; + ON_CALL(message_helper_mock_, GetBCCloseApplicationRequestToHMI(_, _)) + .WillByDefault(Return(CreateCloseAppMessage())); + ON_CALL(app_manager_mock_, GetRPCService()) + .WillByDefault(ReturnRef(mock_rpc_service_)); + ON_CALL(mock_rpc_service_, ManageHMICommand(_, _)) + .WillByDefault(Return(true)); EXPECT_CALL(app_mock, CurrentHmiState(kDefaultWindowId)) .WillRepeatedly(Return(NoneNotAudibleState())); @@ -2587,14 +2609,20 @@ TEST_F(StateControllerImplTest, TEST_F(StateControllerImplTest, SetRegularStateWithNewHmiLvl) { using namespace mobile_apis; + auto message = CreateCloseAppMessage(); + ON_CALL(message_helper_mock_, GetBCCloseApplicationRequestToHMI(_, _)) + .WillByDefault(Return(message)); + ON_CALL(app_manager_mock_, GetRPCService()) + .WillByDefault(ReturnRef(mock_rpc_service_)); + ON_CALL(mock_rpc_service_, ManageHMICommand(_, _)) + .WillByDefault(Return(true)); + + ON_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)) + .WillByDefault(Return(NoneNotAudibleState())); + ON_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) + .WillByDefault(Return(NoneNotAudibleState())); HMILevel::eType set_lvl = HMILevel::HMI_NONE; - EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)) - .WillOnce(Return(BackgroundState())); - - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) - .WillOnce(Return(BackgroundState())) - .WillOnce(Return(BackgroundState())); state_ctrl_->SetRegularState(simple_app_, kDefaultWindowId, set_lvl); @@ -2605,6 +2633,7 @@ TEST_F(StateControllerImplTest, SetRegularStateWithNewHmiLvl) { EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillOnce(Return(BackgroundState())) .WillOnce(Return(BackgroundState())); + state_ctrl_->SetRegularState(simple_app_, kDefaultWindowId, set_lvl); set_lvl = HMILevel::HMI_FULL; 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 f608b62057..248bbfe16c 100644 --- a/src/components/include/policy/policy_external/policy/policy_manager.h +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -589,6 +589,13 @@ class PolicyManager : public usage_statistics::StatisticsManager, const = 0; /** + * @brief Gets vehicle data items removed by policies + * @return Structure with vehicle data items + */ + virtual std::vector<rpc::policy_table_interface_base::VehicleDataItem> + GetRemovedVehicleDataItems() const = 0; + + /** * @brief Gets copy of current policy table data * @return policy_table as json object */ 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 7ec407bb34..ee1f5fa98f 100644 --- a/src/components/include/policy/policy_regular/policy/policy_manager.h +++ b/src/components/include/policy/policy_regular/policy/policy_manager.h @@ -564,6 +564,13 @@ class PolicyManager : public usage_statistics::StatisticsManager, const = 0; /** + * @brief Gets removed vehicle data items + * @return Structure with vehicle data items + */ + virtual std::vector<policy_table::VehicleDataItem> + GetRemovedVehicleDataItems() const = 0; + + /** * @brief Gets copy of current policy table data * @return policy_table as json object */ diff --git a/src/components/include/test/application_manager/policies/mock_custom_vehicle_data_provider.h b/src/components/include/test/application_manager/policies/mock_custom_vehicle_data_provider.h index b6533521ed..ba077122ce 100644 --- a/src/components/include/test/application_manager/policies/mock_custom_vehicle_data_provider.h +++ b/src/components/include/test/application_manager/policies/mock_custom_vehicle_data_provider.h @@ -13,6 +13,9 @@ class MockCustomVehicleDataProvider : public policy::VehicleDataItemProvider { MOCK_CONST_METHOD0( GetVehicleDataItems, const std::vector<rpc::policy_table_interface_base::VehicleDataItem>()); + MOCK_CONST_METHOD0( + GetRemovedVehicleDataItems, + std::vector<rpc::policy_table_interface_base::VehicleDataItem>()); }; } // namespace policy_test 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 deb405cbde..f74526148a 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 @@ -73,6 +73,9 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { MOCK_CONST_METHOD0( GetVehicleDataItems, const std::vector<rpc::policy_table_interface_base::VehicleDataItem>()); + MOCK_CONST_METHOD0( + GetRemovedVehicleDataItems, + std::vector<rpc::policy_table_interface_base::VehicleDataItem>()); #ifdef EXTERNAL_PROPRIETARY_MODE MOCK_METHOD3(OnSnapshotCreated, 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 35b01d20c1..b74ddbd13c 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 @@ -79,6 +79,8 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { MOCK_CONST_METHOD0(GetPolicyTableData, Json::Value()); MOCK_CONST_METHOD0(GetVehicleDataItems, const std::vector<policy_table::VehicleDataItem>()); + MOCK_CONST_METHOD0(GetRemovedVehicleDataItems, + std::vector<policy_table::VehicleDataItem>()); MOCK_CONST_METHOD1(GetEnabledCloudApps, void(std::vector<std::string>& enabled_apps)); MOCK_CONST_METHOD7(GetCloudAppParameters, 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 99d671e4ef..8e6cc2666d 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 @@ -224,6 +224,8 @@ class MockPolicyManager : public PolicyManager { MOCK_CONST_METHOD0(GetPolicyTableData, Json::Value()); MOCK_CONST_METHOD0(GetVehicleDataItems, const std::vector<policy_table::VehicleDataItem>()); + MOCK_CONST_METHOD0(GetRemovedVehicleDataItems, + std::vector<policy_table::VehicleDataItem>()); MOCK_CONST_METHOD1(GetEnabledCloudApps, void(std::vector<std::string>& enabled_apps)); MOCK_CONST_METHOD7(GetCloudAppParameters, 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 d3da4d74c3..e592caf3bc 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 @@ -65,6 +65,8 @@ class MockCacheManagerInterface : public CacheManagerInterface { MOCK_CONST_METHOD0(GetPolicyTableData, Json::Value()); MOCK_CONST_METHOD0(GetVehicleDataItems, const std::vector<policy_table::VehicleDataItem>()); + MOCK_CONST_METHOD0(GetRemovedVehicleDataItems, + std::vector<policy_table::VehicleDataItem>()); MOCK_CONST_METHOD1(GetEnabledCloudApps, void(std::vector<std::string>& enabled_apps)); MOCK_CONST_METHOD7(GetCloudAppParameters, 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 d711b50bab..927f5ba5cc 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 @@ -219,6 +219,8 @@ class MockPolicyManager : public PolicyManager { MOCK_CONST_METHOD0(GetPolicyTableData, Json::Value()); MOCK_CONST_METHOD0(GetVehicleDataItems, const std::vector<policy_table::VehicleDataItem>()); + MOCK_CONST_METHOD0(GetRemovedVehicleDataItems, + std::vector<policy_table::VehicleDataItem>()); MOCK_CONST_METHOD1(GetEnabledCloudApps, void(std::vector<std::string>& enabled_apps)); MOCK_CONST_METHOD7(GetCloudAppParameters, diff --git a/src/components/interfaces/HMI_API.xml b/src/components/interfaces/HMI_API.xml index 9b385c97cd..d105d2e3e8 100644 --- a/src/components/interfaces/HMI_API.xml +++ b/src/components/interfaces/HMI_API.xml @@ -5432,39 +5432,6 @@ </function> <function name="SetAppIcon" messagetype="response"> </function> - <function name="ShowCustomForm" messagetype="request"> - <description>Used to show a custom form; it can be a parent or child screen. If no parent screen is designated, it is set as a parent screen.</description> - <param name="customFormID" type="String" maxlength="500" mandatory="true"> - <description> - Predefined or dynamically created screen layout. - Currently only predefined forms are defined. - Predefined layouts include: - "DEFAULT" - Default media / non-media screen - "ONSCREEN_PRESETS" - Custom root media screen containing app-defined onscreen presets. - "KEYBOARD_SEARCH" - Custom template containing app-configured on-screen keyboard with active search updating; user also can trigger voice search. - "NAV_FULLSCREEN_MAP" - Custom root template screen containing full screen map with navigation controls. - "NAV_POI_MENU" - Custom template containing app-defined POI options. - "NAV_SEARCH_RESULTS" - Custom template containing a list of app-defined search results - "NAV_POI_INFO" - Custom template containing app-defined POI information (and potentially map data). - </description> - </param> - <param name="parentFormID" type="String" maxlength="500" defvalue="DEFAULT" mandatory="false"> - <description> - Parent screen of predefined form to display. - Currently only predefined forms are defined. - If not provided, then set to "DEFAULT". - Predefined layouts include: - "DEFAULT" - Default media / non-media screen - "ONSCREEN_PRESETS" - Custom root media screen containing app-defined onscreen presets. - "NAV_FULLSCREEN_MAP" - Custom template containing full screen map with navigation controls. - </description> - </param> - </function> - <function name="ShowCustomForm" messagetype="response"> - <param name="info" type="String" maxlength="1000" mandatory="false" platform="documentation"> - <description>Provides additional human readable info regarding the result.</description> - </param> - </function> <function name="OnKeyboardInput" messagetype="notification"> <description>On-screen keyboard event.</description> <description>Can be full string or individual keypresses depending on keyboard mode.</description> diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml index 3ab704ddb0..2a09cc6b57 100644 --- a/src/components/interfaces/MOBILE_API.xml +++ b/src/components/interfaces/MOBILE_API.xml @@ -6858,6 +6858,7 @@ <element name="GENERIC_ERROR"/> <element name="REJECTED"/> <element name="DISALLOWED"/> + <element name="UNSUPPORTED_RESOURCE"/> </param> <param name="info" type="String" maxlength="1000" mandatory="false" platform="documentation"> 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 acc7a7da51..1bac72e2c6 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -166,6 +166,9 @@ class CacheManager : public CacheManagerInterface { virtual const std::vector<policy_table::VehicleDataItem> GetVehicleDataItems() const OVERRIDE; + std::vector<policy_table::VehicleDataItem> GetRemovedVehicleDataItems() + const OVERRIDE; + /** * @brief Gets copy of current policy table data * @return policy_table as json object @@ -893,6 +896,24 @@ class CacheManager : public CacheManagerInterface { */ void CheckSnapshotInitialization(); + /** + * @brief Calculates difference between two provided custom vehicle data items + * @param items_before list of vehicle data items before PTU was applied + * @param items_after list of vehicle data items after PTU was applied + * @return list with calculated difference or empty list if two input lists + * are equal + */ + policy_table::VehicleDataItems CalculateCustomVdItemsDiff( + const policy_table::VehicleDataItems& items_before, + const policy_table::VehicleDataItems& items_after) const; + + /** + * @brief Sets the custom vehicle data items + * @param removed_items list of vehicle data items to set + */ + void SetRemovedCustomVdItems( + const policy_table::VehicleDataItems& removed_items); + void PersistData(); /** @@ -938,6 +959,7 @@ class CacheManager : public CacheManagerInterface { bool update_required; typedef std::set<std::string> UnpairedDevices; UnpairedDevices is_unpaired_; + policy_table::VehicleDataItems removed_custom_vd_items_; mutable sync_primitives::RecursiveLock cache_lock_; sync_primitives::Lock unpaired_lock_; 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 ff09ed608d..2cb5f8fe33 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 @@ -175,6 +175,13 @@ class CacheManagerInterface { const = 0; /** + * @brief Gets vehicle data items removed after the last PTU + * @return List of removed vehicle data items + */ + virtual std::vector<policy_table::VehicleDataItem> + GetRemovedVehicleDataItems() const = 0; + + /** * @brief Get a list of enabled cloud applications * @param enabled_apps List filled with the policy app id of each enabled * cloud application diff --git a/src/components/policy/policy_external/include/policy/policy_manager_impl.h b/src/components/policy/policy_external/include/policy/policy_manager_impl.h index 60d70a9283..b1c22ab9e6 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 @@ -655,6 +655,9 @@ class PolicyManagerImpl : public PolicyManager { const std::vector<policy_table::VehicleDataItem> GetVehicleDataItems() const OVERRIDE; + std::vector<policy_table::VehicleDataItem> GetRemovedVehicleDataItems() + 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/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index 3e1538ab04..e1015ea574 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -269,7 +269,8 @@ CacheManager::CacheManager() : CacheManagerInterface() , pt_(new policy_table::Table) , backup_(new SQLPTExtRepresentation()) - , update_required(false) { + , update_required(false) + , removed_custom_vd_items_() { InitBackupThread(); } @@ -758,6 +759,12 @@ bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) { // Apply update for vehicle data if (update_pt.policy_table.vehicle_data.is_initialized()) { + policy_table::VehicleDataItems custom_items_before_apply; + if (pt_->policy_table.vehicle_data->schema_items.is_initialized()) { + custom_items_before_apply = + CollectCustomVDItems(*pt_->policy_table.vehicle_data->schema_items); + } + if (!update_pt.policy_table.vehicle_data->schema_items.is_initialized() || update_pt.policy_table.vehicle_data->schema_items->empty()) { pt_->policy_table.vehicle_data->schema_items = @@ -771,6 +778,12 @@ bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) { pt_->policy_table.vehicle_data->schema_items = rpc::Optional<policy_table::VehicleDataItems>(custom_items); } + + policy_table::VehicleDataItems custom_items_after_apply = + *pt_->policy_table.vehicle_data->schema_items; + const auto& items_diff = CalculateCustomVdItemsDiff( + custom_items_before_apply, custom_items_after_apply); + SetRemovedCustomVdItems(items_diff); } ResetCalculatedPermissions(); @@ -1430,6 +1443,12 @@ CacheManager::GetVehicleDataItems() const { return std::vector<policy_table::VehicleDataItem>(); } +std::vector<policy_table::VehicleDataItem> +CacheManager::GetRemovedVehicleDataItems() const { + CACHE_MANAGER_CHECK(std::vector<policy_table::VehicleDataItem>()); + return removed_custom_vd_items_; +} + Json::Value CacheManager::GetPolicyTableData() const { return pt_->policy_table.ToJsonValue(); } @@ -1922,6 +1941,46 @@ void CacheManager::CheckSnapshotInitialization() { } } +policy_table::VehicleDataItems CacheManager::CalculateCustomVdItemsDiff( + const policy_table::VehicleDataItems& items_before, + const policy_table::VehicleDataItems& items_after) const { + LOG4CXX_AUTO_TRACE(logger_); + if (items_before.empty()) { + LOG4CXX_DEBUG(logger_, "No custom VD items found in policy"); + return policy_table::VehicleDataItems(); + } + + if (items_after.empty()) { + LOG4CXX_DEBUG(logger_, + "All custom VD items were removed after policy update"); + return items_before; + } + + policy_table::VehicleDataItems removed_items; + for (auto& item_to_search : items_before) { + auto item_predicate = + [&item_to_search](const policy_table::VehicleDataItem& item_to_check) { + return item_to_search.name == item_to_check.name; + }; + + auto it = + std::find_if(items_after.begin(), items_after.end(), item_predicate); + if (items_after.end() == it) { + removed_items.push_back(item_to_search); + } + } + + LOG4CXX_DEBUG(logger_, + "Found " << removed_items.size() << " removed VD items"); + return removed_items; +} + +void CacheManager::SetRemovedCustomVdItems( + const policy_table::VehicleDataItems& removed_items) { + LOG4CXX_AUTO_TRACE(logger_); + removed_custom_vd_items_ = removed_items; +} + void CacheManager::PersistData() { LOG4CXX_AUTO_TRACE(logger_); if (backup_.use_count() != 0) { diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index b9eed0be4e..6868b9060c 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -804,6 +804,11 @@ PolicyManagerImpl::GetVehicleDataItems() const { return cache_->GetVehicleDataItems(); } +std::vector<policy_table::VehicleDataItem> +PolicyManagerImpl::GetRemovedVehicleDataItems() const { + return cache_->GetRemovedVehicleDataItems(); +} + Json::Value PolicyManagerImpl::GetPolicyTableData() const { return cache_->GetPolicyTableData(); } 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 9b0413d7ce..6bd2c4840b 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -154,6 +154,9 @@ class CacheManager : public CacheManagerInterface { virtual const std::vector<policy_table::VehicleDataItem> GetVehicleDataItems() const; + std::vector<policy_table::VehicleDataItem> GetRemovedVehicleDataItems() + const OVERRIDE; + const boost::optional<bool> LockScreenDismissalEnabledState() const OVERRIDE; const boost::optional<std::string> LockScreenDismissalWarningMessage( @@ -919,6 +922,24 @@ class CacheManager : public CacheManagerInterface { */ void CheckSnapshotInitialization(); + /** + * @brief Calculates difference between two provided custom vehicle data items + * @param items_before list of vehicle data items before PTU was applied + * @param items_after list of vehicle data items after PTU was applied + * @return list with calculated difference or empty list if two input lists + * are equal + */ + policy_table::VehicleDataItems CalculateCustomVdItemsDiff( + const policy_table::VehicleDataItems& items_before, + const policy_table::VehicleDataItems& items_after) const; + + /** + * @brief Sets the custom vehicle data items + * @param removed_items list of vehicle data items to set + */ + void SetRemovedCustomVdItems( + const policy_table::VehicleDataItems& removed_items); + void PersistData(); /** @@ -945,6 +966,7 @@ class CacheManager : public CacheManagerInterface { bool update_required; typedef std::set<std::string> UnpairedDevices; UnpairedDevices is_unpaired_; + policy_table::VehicleDataItems removed_custom_vd_items_; mutable sync_primitives::RecursiveLock cache_lock_; sync_primitives::Lock unpaired_lock_; 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 bd03896bfb..a1b4af0f39 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 @@ -162,6 +162,13 @@ class CacheManagerInterface { const = 0; /** + * @brief Gets vehicle data items removed after the last PTU + * @return List of removed vehicle data items + */ + virtual std::vector<policy_table::VehicleDataItem> + GetRemovedVehicleDataItems() const = 0; + + /** * @brief Get a list of enabled cloud applications * @param enabled_apps List filled with the policy app id of each enabled * cloud application diff --git a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h index 178de4a8f0..fc6ec369dc 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 @@ -663,6 +663,9 @@ class PolicyManagerImpl : public PolicyManager { const std::vector<policy_table::VehicleDataItem> GetVehicleDataItems() const OVERRIDE; + std::vector<policy_table::VehicleDataItem> GetRemovedVehicleDataItems() + const OVERRIDE; + /** * @brief Gets copy of current policy table data * @return policy_table as json object diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index 166a79b89d..9c73d88e63 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -107,6 +107,7 @@ CacheManager::CacheManager() , pt_(new policy_table::Table) , backup_(new SQLPTRepresentation()) , update_required(false) + , removed_custom_vd_items_() , settings_(nullptr) { LOG4CXX_AUTO_TRACE(logger_); backuper_ = new BackgroundBackuper(this); @@ -304,6 +305,12 @@ bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) { // Apply update for vehicle data if (update_pt.policy_table.vehicle_data.is_initialized()) { + policy_table::VehicleDataItems custom_items_before_apply; + if (pt_->policy_table.vehicle_data->schema_items.is_initialized()) { + custom_items_before_apply = + CollectCustomVDItems(*pt_->policy_table.vehicle_data->schema_items); + } + if (!update_pt.policy_table.vehicle_data->schema_items.is_initialized() || update_pt.policy_table.vehicle_data->schema_items->empty()) { pt_->policy_table.vehicle_data->schema_items = @@ -317,9 +324,12 @@ bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) { pt_->policy_table.vehicle_data->schema_items = rpc::Optional<policy_table::VehicleDataItems>(custom_items); } - if (update_pt.policy_table.vehicle_data->schema_version.is_initialized() && - update_pt.policy_table.vehicle_data->schema_items.is_initialized()) { - } + + policy_table::VehicleDataItems custom_items_after_apply = + *pt_->policy_table.vehicle_data->schema_items; + const auto& items_diff = CalculateCustomVdItemsDiff( + custom_items_before_apply, custom_items_after_apply); + SetRemovedCustomVdItems(items_diff); } ResetCalculatedPermissions(); @@ -727,6 +737,12 @@ CacheManager::GetVehicleDataItems() const { return std::vector<policy_table::VehicleDataItem>(); } +std::vector<policy_table::VehicleDataItem> +CacheManager::GetRemovedVehicleDataItems() const { + CACHE_MANAGER_CHECK(std::vector<policy_table::VehicleDataItem>()); + return removed_custom_vd_items_; +} + Json::Value CacheManager::GetPolicyTableData() const { return pt_->policy_table.ToJsonValue(); } @@ -1226,6 +1242,46 @@ void CacheManager::CheckSnapshotInitialization() { } } +policy_table::VehicleDataItems CacheManager::CalculateCustomVdItemsDiff( + const policy_table::VehicleDataItems& items_before, + const policy_table::VehicleDataItems& items_after) const { + LOG4CXX_AUTO_TRACE(logger_); + if (items_before.empty()) { + LOG4CXX_DEBUG(logger_, "No custom VD items found in policy"); + return policy_table::VehicleDataItems(); + } + + if (items_after.empty()) { + LOG4CXX_DEBUG(logger_, + "All custom VD items were removed after policy update"); + return items_before; + } + + policy_table::VehicleDataItems removed_items; + for (auto& item_to_search : items_before) { + auto item_predicate = + [&item_to_search](const policy_table::VehicleDataItem& item_to_check) { + return item_to_search.name == item_to_check.name; + }; + + auto it = + std::find_if(items_after.begin(), items_after.end(), item_predicate); + if (items_after.end() == it) { + removed_items.push_back(item_to_search); + } + } + + LOG4CXX_DEBUG(logger_, + "Found " << removed_items.size() << " removed VD items"); + return removed_items; +} + +void CacheManager::SetRemovedCustomVdItems( + const policy_table::VehicleDataItems& removed_items) { + LOG4CXX_AUTO_TRACE(logger_); + removed_custom_vd_items_ = removed_items; +} + void CacheManager::PersistData() { LOG4CXX_AUTO_TRACE(logger_); if (backup_.use_count() != 0) { 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 4c3f0763bc..2fef8de1d8 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -721,6 +721,11 @@ PolicyManagerImpl::GetVehicleDataItems() const { return cache_->GetVehicleDataItems(); } +std::vector<policy_table::VehicleDataItem> +PolicyManagerImpl::GetRemovedVehicleDataItems() const { + return cache_->GetRemovedVehicleDataItems(); +} + Json::Value PolicyManagerImpl::GetPolicyTableData() const { return cache_->GetPolicyTableData(); } diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc index 61b9afd7bc..3b216c273c 100644 --- a/src/components/protocol_handler/src/protocol_handler_impl.cc +++ b/src/components/protocol_handler/src/protocol_handler_impl.cc @@ -1816,8 +1816,15 @@ void ProtocolHandlerImpl::NotifySessionStarted( LOG4CXX_WARN(logger_, "Refused by session_observer to create service " << static_cast<int32_t>(service_type) << " type."); + const auto session_id = packet->session_id(); + const auto connection_key = + session_observer_.KeyFromPair(context.connection_id_, session_id); + service_status_update_handler_->OnServiceUpdate( + connection_key, + context.service_type_, + ServiceStatus::SERVICE_START_FAILED); SendStartSessionNAck(context.connection_id_, - packet->session_id(), + session_id, protocol_version, packet->service_type(), rejected_params); |