diff options
30 files changed, 631 insertions, 32 deletions
diff --git a/src/components/application_manager/include/application_manager/commands/mobile/system_request.h b/src/components/application_manager/include/application_manager/commands/mobile/system_request.h index 0b8533aeab..25accb1db2 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/system_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/system_request.h @@ -34,6 +34,7 @@ #ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_SYSTEM_REQUEST_H_ #define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_SYSTEM_REQUEST_H_ +#include <string> #include "application_manager/commands/command_request_impl.h" namespace NsSmartDeviceLink { @@ -85,6 +86,7 @@ private: private: static uint32_t index; + std::string processing_file_; DISALLOW_COPY_AND_ASSIGN(SystemRequest); }; 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 5310b6f2b5..73d3cced0d 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 @@ -318,12 +318,29 @@ class PolicyHandler : /** * @brief Handler on applications search started */ - virtual void OnAppsSearchStarted(); + void OnAppsSearchStarted(); /** * @brief Handler on applications search completed */ - virtual void OnAppsSearchCompleted(); + void OnAppsSearchCompleted(); + + /** + * @brief Checks if certain request type is allowed for application + * @param policy_app_id Unique applicaion id + * @param type Request type + * @return true, if allowed, otherwise - false + */ + bool IsRequestTypeAllowed(const std::string& policy_app_id, + mobile_apis::RequestType::eType type) const; + + /** + * @brief Gets application request types + * @param policy_app_id Unique application id + * @return request types + */ + const std::vector<std::string> GetAppRequestTypes( + const std::string& policy_app_id) const; //TODO(AKutsan) REMOVE THIS UGLY HOTFIX virtual void Increment(usage_statistics::GlobalCounterId type); diff --git a/src/components/application_manager/src/commands/hmi/on_system_request_notification.cc b/src/components/application_manager/src/commands/hmi/on_system_request_notification.cc index a77bd24766..c412f11c61 100644 --- a/src/components/application_manager/src/commands/hmi/on_system_request_notification.cc +++ b/src/components/application_manager/src/commands/hmi/on_system_request_notification.cc @@ -63,6 +63,7 @@ void OnSystemRequestNotification::Run() { const std::string app_id = msg_params[strings::app_id].asString(); LOG4CXX_DEBUG(logger_, "Received OnSystemRequest for " << app_id ); + ApplicationSharedPtr app; if (strings::default_app_id == app_id) { PolicyHandler* policy_handler = PolicyHandler::instance(); uint32_t selected_app_id = policy_handler->GetAppIdForSending(); @@ -72,23 +73,29 @@ void OnSystemRequestNotification::Run() { return; } ApplicationManagerImpl* app_mgr = ApplicationManagerImpl::instance(); - ApplicationSharedPtr selected_app = app_mgr->application(selected_app_id); - if (!selected_app.valid()) { - LOG4CXX_ERROR(logger_, "PolicyHandler selected invalid app_id"); - return; - } - params[strings::connection_key] = selected_app_id; + app = app_mgr->application(selected_app_id); } else { - ApplicationSharedPtr app = - ApplicationManagerImpl::instance()->application_by_policy_id(app_id); - if (!app.valid()) { - LOG4CXX_WARN(logger_, "Application with id " << app_id - << " is not registered."); - return; - } - params[strings::connection_key] = app->app_id(); + app = ApplicationManagerImpl::instance()->application_by_policy_id(app_id); + } + + if (!app.valid()) { + LOG4CXX_WARN(logger_, "Application with connection key " << app_id << + "is not registered."); + return; + } + + const mobile_apis::RequestType::eType request_type = + static_cast<mobile_apis::RequestType::eType>( + (*message_)[strings::msg_params][strings::request_type].asInt()); + + if (!policy::PolicyHandler::instance()->IsRequestTypeAllowed( + app->mobile_app_id(), request_type)) { + LOG4CXX_WARN(logger_, "Request type " << request_type + <<" is not allowed by policies"); + return; } + params[strings::connection_key] = app->app_id(); SendNotificationToMobile(message_); } diff --git a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc index 20211e9e75..4b0b088b2e 100644 --- a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc +++ b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc @@ -465,13 +465,13 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( resumption = resumer.IsApplicationSaved(application->mobile_app_id()); } - MessageHelper::SendOnAppRegisteredNotificationToHMI(*(application.get()), - resumption, - need_restore_vr); MessageHelper::SendChangeRegistrationRequestToHMI(application); SendResponse(true, result, add_info.c_str(), &response_params); + MessageHelper::SendOnAppRegisteredNotificationToHMI(*(application.get()), + resumption, + need_restore_vr); if (result != mobile_apis::Result::RESUME_FAILED) { resumer.StartResumption(application, hash_id); } else { diff --git a/src/components/application_manager/src/commands/mobile/system_request.cc b/src/components/application_manager/src/commands/mobile/system_request.cc index 0378e7c454..54a470b15b 100644 --- a/src/components/application_manager/src/commands/mobile/system_request.cc +++ b/src/components/application_manager/src/commands/mobile/system_request.cc @@ -37,6 +37,7 @@ Copyright (c) 2013, Ford Motor Company #include "application_manager/commands/mobile/system_request.h" #include "application_manager/application_manager_impl.h" #include "application_manager/application_impl.h" +#include "application_manager/policies/policy_handler.h" #include "interfaces/MOBILE_API.h" #include "config_profile/profile.h" #include "utils/file_system.h" @@ -139,10 +140,22 @@ void SystemRequest::Run() { return; } } else { - if (!(file_system::CreateFile(full_file_path))) { - SendResponse(false, mobile_apis::Result::GENERIC_ERROR); + if (!policy::PolicyHandler::instance()->IsRequestTypeAllowed( + application->mobile_app_id(), request_type)) { + SendResponse(false, mobile_apis::Result::DISALLOWED); + return; + } + std::string app_file_path = + profile::Profile::instance()->app_storage_folder(); + std::string app_full_file_path = app_file_path + "/" + file_name; + + const AppFile* file = application->GetFile(app_full_file_path); + if (!file || !file->is_download_complete || + !file_system::MoveFile(app_full_file_path, full_file_path)) { + SendResponse(false, mobile_apis::Result::REJECTED); return; } + processing_file_ = full_file_path; } smart_objects::SmartObject msg_params = smart_objects::SmartObject( @@ -182,6 +195,10 @@ void SystemRequest::on_event(const event_engine::Event& event) { return; } + if (!processing_file_.empty()) { + file_system::DeleteFile(processing_file_); + processing_file_.clear(); + } SendResponse(result, result_code, NULL, &(message[strings::msg_params])); break; } diff --git a/src/components/application_manager/src/message_helper.cc b/src/components/application_manager/src/message_helper.cc index 51f5f39594..6c12f804ee 100644 --- a/src/components/application_manager/src/message_helper.cc +++ b/src/components/application_manager/src/message_helper.cc @@ -328,6 +328,24 @@ void MessageHelper::SendOnAppRegisteredNotificationToHMI( message[strings::msg_params][strings::application][strings::app_type] = *app_type; } + if (application_impl.IsRegistered()) { + std::vector<std::string> request_types = + policy::PolicyHandler::instance()->GetAppRequestTypes( + application_impl.mobile_app_id()); + + message[strings::msg_params][strings::application][strings::request_type] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + smart_objects::SmartObject& request_array = + message[strings::msg_params][strings::application][strings::request_type]; + + uint32_t index = 0; + std::vector<std::string>::const_iterator it = request_types.begin(); + for (; request_types.end() != it; ++it) { + request_array[index] = *it; + ++index; + } + } if (application_impl.vr_synonyms()) { message[strings::msg_params][strings::vr_synonyms] = *(application_impl .vr_synonyms()); @@ -2051,13 +2069,13 @@ void MessageHelper::FillAppRevokedPermissions( void MessageHelper::SendOnAppPermissionsChangedNotification( uint32_t connection_key, const policy::AppPermissions& permissions) { - smart_objects::SmartObjectSPtr notification = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + using namespace smart_objects; + SmartObjectSPtr notification = new SmartObject(SmartType_Map); if (!notification) { return; } - smart_objects::SmartObject& message = *notification; + SmartObject& message = *notification; message[strings::params][strings::function_id] = hmi_apis::FunctionID::SDL_OnAppPermissionChanged; @@ -2088,6 +2106,14 @@ void MessageHelper::SendOnAppPermissionsChangedNotification( message[strings::msg_params]["priority"] = GetPriorityCode( permissions.priority); } + if (permissions.requestTypeChanged) { + SmartObject request_types_array = SmartObject(SmartType_Array); + for (uint16_t index = 0; index < permissions.requestType.size(); ++index) { + request_types_array[index] = permissions.requestType[index]; + } + message[strings::msg_params][strings::request_type] = + request_types_array; + } ApplicationManagerImpl::instance()->ManageHMICommand(notification); } diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index fe9d14df16..cc0fd5d835 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -58,6 +58,41 @@ namespace policy { using namespace application_manager; +namespace { +using namespace mobile_apis; +typedef std::map<RequestType::eType, std::string> RequestTypeMap; +RequestTypeMap TypeToString = { + {RequestType::INVALID_ENUM, "INVALID_ENUM"}, + {RequestType::HTTP, "HTTP"}, + {RequestType::FILE_RESUME, "FILE_RESUME"}, + {RequestType::AUTH_REQUEST, "AUTH_REQUEST"}, + {RequestType::AUTH_CHALLENGE, "AUTH_CHALLENGE"}, + {RequestType::AUTH_ACK, "AUTH_ACK"}, + {RequestType::PROPRIETARY, "PROPRIETARY"}, + {RequestType::QUERY_APPS, "QUERY_APPS"}, + {RequestType::LAUNCH_APP, "LAUNCH_APP"}, + {RequestType::LOCK_SCREEN_ICON_URL, "LOCK_SCREEN_ICON_URL"}, + {RequestType::TRAFFIC_MESSAGE_CHANNEL, "TRAFFIC_MESSAGE_CHANNEL"}, + {RequestType::DRIVER_PROFILE, "DRIVER_PROFILE"}, + {RequestType::VOICE_SEARCH, "VOICE_SEARCH"}, + {RequestType::NAVIGATION, "NAVIGATION"}, + {RequestType::PHONE,"PHONE"}, + {RequestType::CLIMATE, "CLIMATE"}, + {RequestType::SETTINGS, "SETTINGS"}, + {RequestType::VEHICLE_DIAGNOSTICS, "VEHICLE_DIAGNOSTICS"}, + {RequestType::EMERGENCY, "EMERGENCY"}, + {RequestType::MEDIA, "MEDIA"}, + {RequestType::FOTA, "FOTA"} +}; + +const std::string RequestTypeToString(RequestType::eType type) { + RequestTypeMap::const_iterator it = TypeToString.find(type); + if (TypeToString.end() != it) { + return (*it).second; + } + return ""; +} +} #define POLICY_LIB_CHECK(return_value) {\ sync_primitives::AutoReadLock lock(policy_manager_lock_); \ if (!policy_manager_) {\ @@ -702,6 +737,11 @@ void PolicyHandler::OnPendingPermissionChange( policy_manager_->RemovePendingPermissionChanges(policy_app_id); } + if (permissions.requestTypeChanged) { + MessageHelper:: + SendOnAppPermissionsChangedNotification(app->app_id(), permissions); + policy_manager_->RemovePendingPermissionChanges(policy_app_id); + } } bool PolicyHandler::SendMessageToSDK(const BinaryMessage& pt_string, @@ -1255,6 +1295,38 @@ void policy::PolicyHandler::OnAppsSearchCompleted() { policy_manager_->OnAppsSearchCompleted(); } +bool PolicyHandler::IsRequestTypeAllowed( + const std::string& policy_app_id, + mobile_apis::RequestType::eType type) const { + POLICY_LIB_CHECK(false); + using namespace mobile_apis; + + + std::string stringified_type = RequestTypeToString(type); + if (stringified_type.empty()) { + LOG4CXX_ERROR(logger_, "Unknown request type."); + return false; + } + + std::vector<std::string> request_types = + policy_manager_->GetAppRequestTypes(policy_app_id); + + // If no request types are assigned to app - any is allowed + if (request_types.empty()) { + return true; + } + + std::vector<std::string>::const_iterator it = + std::find(request_types.begin(), request_types.end(), stringified_type); + return request_types.end() != it; +} + +const std::vector<std::string> PolicyHandler::GetAppRequestTypes( + const std::string& policy_app_id) const { + POLICY_LIB_CHECK(std::vector<std::string>()); + return policy_manager_->GetAppRequestTypes(policy_app_id); +} + void PolicyHandler::Increment(usage_statistics::GlobalCounterId type) { POLICY_LIB_CHECK(); policy_manager_->Increment(type); diff --git a/src/components/interfaces/HMI_API.xml b/src/components/interfaces/HMI_API.xml index f6b916788e..59d98c2fce 100644 --- a/src/components/interfaces/HMI_API.xml +++ b/src/components/interfaces/HMI_API.xml @@ -978,6 +978,20 @@ <element name="AUTH_CHALLENGE" /> <element name="AUTH_ACK" /> <element name="PROPRIETARY" /> + <element name="QUERY_APPS" /> + <element name="LAUNCH_APP" /> + <element name="LOCK_SCREEN_ICON_URL" /> + <element name="TRAFFIC_MESSAGE_CHANNEL" /> + <element name="DRIVER_PROFILE" /> + <element name="VOICE_SEARCH" /> + <element name="NAVIGATION" /> + <element name="PHONE" /> + <element name="CLIMATE" /> + <element name="SETTINGS" /> + <element name="VEHICLE_DIAGNOSTICS" /> + <element name="EMERGENCY" /> + <element name="MEDIA" /> + <element name="FOTA" /> </enum> <enum name="ECallConfirmationStatus"> @@ -1331,6 +1345,13 @@ <description>Indicates whether application should be dimmed on the screen.</description> <description>Applicable only for apps received through QueryApps and still not registered.</description> </param> + <param name="requestType" type="Common.RequestType" minsize="0" maxsize="100" array="true" mandatory="false"> + <description>The list of SystemRequest's RequestTypes allowed by policies for the named application</description> + <description>(the app's SystemRequest sent with RequestType out of this list will get 'disallowed' response from SDL).</description> + <description>If SDL sends an empty array - any RequestType is allowed for this app.</description> + <description>If SDL omits this parameter - none RequestType is allowed for this app</description> + <description>(either this is a pre-registered app or such is dictated by policies).</description> + </param> </struct> <struct name="MenuParams"> @@ -3886,6 +3907,12 @@ <param name="priority" type="Common.AppPriority" mandatory="false"> <description>Send to HMI so that it can coordinate order of requests/notifications correspondingly.</description> </param> + <param name="requestType" type="Common.RequestType" minsize="0" maxsize="100" array="true" mandatory="false"> + <description>The list of SystemRequest's RequestTypes allowed by policies for the named application (the app's SystemRequest sent with RequestType out of this list will get 'disallowed' response from SDL). + If SDL sends an empty array - any RequestType is allowed for this app. + If SDL omits this parameter - nothing is changed for RequestType in the policies + </description> + </param> </function> <function name="OnSDLConsentNeeded" messagetype="notification"> diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml index 9106ef2f00..e3a7bd7058 100644 --- a/src/components/interfaces/MOBILE_API.xml +++ b/src/components/interfaces/MOBILE_API.xml @@ -2119,6 +2119,18 @@ <element name="PROPRIETARY" /> <element name="QUERY_APPS" /> <element name="LAUNCH_APP" /> + <element name="LOCK_SCREEN_ICON_URL" /> + <element name="TRAFFIC_MESSAGE_CHANNEL" /> + <element name="DRIVER_PROFILE" /> + <element name="VOICE_SEARCH" /> + <element name="NAVIGATION" /> + <element name="PHONE" /> + <element name="CLIMATE" /> + <element name="SETTINGS" /> + <element name="VEHICLE_DIAGNOSTICS" /> + <element name="EMERGENCY" /> + <element name="MEDIA" /> + <element name="FOTA" /> </enum> <enum name="AppHMIType"> @@ -4626,6 +4638,13 @@ <element name="REJECTED"/> <element name="INVALID_CERT"/> <element name="EXPIRED_CERT"/> + <element name="UNSUPPORTED_REQUEST"/> + <element name="UNSUPPORTED_RESOURCE"/> + <element name="DISALLOWED"/> + <element name="ABORTED"/> + <element name="WARNINGS"/> + <element name="TIMED_OUT"/> + <element name="IGNORED"/> </param> </function> diff --git a/src/components/interfaces/QT_HMI_API.xml b/src/components/interfaces/QT_HMI_API.xml index 1960707fb7..a70ba36dfd 100644 --- a/src/components/interfaces/QT_HMI_API.xml +++ b/src/components/interfaces/QT_HMI_API.xml @@ -923,6 +923,20 @@ <element name="AUTH_CHALLENGE"/> <element name="AUTH_ACK"/> <element name="PROPRIETARY"/> + <element name="QUERY_APPS" /> + <element name="LAUNCH_APP" /> + <element name="LOCK_SCREEN_ICON_URL" /> + <element name="TRAFFIC_MESSAGE_CHANNEL" /> + <element name="DRIVER_PROFILE" /> + <element name="VOICE_SEARCH" /> + <element name="NAVIGATION" /> + <element name="PHONE" /> + <element name="CLIMATE" /> + <element name="SETTINGS" /> + <element name="VEHICLE_DIAGNOSTICS" /> + <element name="EMERGENCY" /> + <element name="MEDIA" /> + <element name="FOTA" /> </enum> <enum name="ECallConfirmationStatus"> <description>Reflects the status of the eCall Notification.</description> @@ -1255,6 +1269,13 @@ <description>Indicates whether application should be dimmed on the screen.</description> <description>Applicable only for apps received through QueryApps and still not registered.</description> </param> + <param name="requestType" type="Common.RequestType" minsize="0" maxsize="100" array="true" mandatory="false"> + <description>The list of SystemRequest's RequestTypes allowed by policies for the named application</description> + <description>(the app's SystemRequest sent with RequestType out of this list will get 'disallowed' response from SDL).</description> + <description>If SDL sends an empty array - any RequestType is allowed for this app.</description> + <description>If SDL omits this parameter - none RequestType is allowed for this app</description> + <description>(either this is a pre-registered app or such is dictated by policies).</description> + </param> </struct> <struct name="MenuParams"> <param name="parentID" type="Integer" minvalue="0" maxvalue="2000000000" mandatory="false"> @@ -4081,6 +4102,12 @@ <param name="priority" type="Common.AppPriority" mandatory="false"> <description>Send to HMI so that it can coordinate order of requests/notifications correspondingly.</description> </param> + <param name="requestType" type="Common.RequestType" minsize="0" maxsize="100" array="true" mandatory="false"> + <description>The list of SystemRequest's RequestTypes allowed by policies for the named application (the app's SystemRequest sent with RequestType out of this list will get 'disallowed' response from SDL). + If SDL sends an empty array - any RequestType is allowed for this app. + If SDL omits this parameter - nothing is changed for RequestType in the policies + </description> + </param> </function> <function name="OnSDLConsentNeeded" messagetype="notification" provider="sdl"> <description>Send from SDL to HMI to notify that data consent is needed for device either because PT update or Retry strategy.</description> diff --git a/src/components/policy/src/policy/include/policy/cache_manager.h b/src/components/policy/src/policy/include/policy/cache_manager.h index e8099afab0..b957679552 100644 --- a/src/components/policy/src/policy/include/policy/cache_manager.h +++ b/src/components/policy/src/policy/include/policy/cache_manager.h @@ -552,6 +552,13 @@ class CacheManager : public CacheManagerInterface { */ static int32_t GenerateHash(const std::string& str_to_hash); + /** + * @brief Gets request types for application + * @param policy_app_id Unique application id + * @param request_types Request types of application + */ + void GetAppRequestTypes(const std::string& policy_app_id, + std::vector<std::string>& request_types) const; private: std::string currentDateTime(); struct AppHMITypeToString { diff --git a/src/components/policy/src/policy/include/policy/cache_manager_interface.h b/src/components/policy/src/policy/include/policy/cache_manager_interface.h index 78468f4f15..24296c6853 100644 --- a/src/components/policy/src/policy/include/policy/cache_manager_interface.h +++ b/src/components/policy/src/policy/include/policy/cache_manager_interface.h @@ -566,6 +566,15 @@ class CacheManagerInterface { const std::string& device_id, const std::string& policy_app_id, policy::Permissions& permission) = 0; + + /** + * @brief Gets request types for application + * @param policy_app_id Unique application id + * @param request_types Request types of application + */ + virtual void GetAppRequestTypes( + const std::string& policy_app_id, + std::vector<std::string>& request_types) const = 0; }; typedef utils::SharedPtr<CacheManagerInterface> CacheManagerInterfaceSPtr; diff --git a/src/components/policy/src/policy/include/policy/policy_helper.h b/src/components/policy/src/policy/include/policy/policy_helper.h index 3991819c34..c3fcce6b2b 100644 --- a/src/components/policy/src/policy/include/policy/policy_helper.h +++ b/src/components/policy/src/policy/include/policy/policy_helper.h @@ -92,7 +92,8 @@ struct CheckAppPolicy { RESULT_PERMISSIONS_REVOKED, RESULT_CONSENT_NEEDED, RESULT_CONSENT_NOT_REQIURED, - RESULT_PERMISSIONS_REVOKED_AND_CONSENT_NEEDED + RESULT_PERMISSIONS_REVOKED_AND_CONSENT_NEEDED, + RESULT_REQUEST_TYPE_CHANGED }; void SetPendingPermissions(const AppPoliciesValueType& app_policy, @@ -121,6 +122,9 @@ struct CheckAppPolicy { */ bool IsConsentRequired(const std::string& app_id, const std::string& group_name) const; + bool IsRequestTypeChanged(const AppPoliciesValueType& app_policy) const; + + private: PolicyManagerImpl* pm_; const utils::SharedPtr<policy_table::Table> update_; const utils::SharedPtr<policy_table::Table> snapshot_; diff --git a/src/components/policy/src/policy/include/policy/policy_manager.h b/src/components/policy/src/policy/include/policy/policy_manager.h index b135501867..5b45630a60 100644 --- a/src/components/policy/src/policy/include/policy/policy_manager.h +++ b/src/components/policy/src/policy/include/policy/policy_manager.h @@ -395,6 +395,13 @@ class PolicyManager : public usage_statistics::StatisticsManager { * @brief Handler on applications search completed */ virtual void OnAppsSearchCompleted() = 0; + /** + * @brief Gets request types for application + * @param policy_app_id Unique application id + * @return request_types Request types of application + */ + virtual const std::vector<std::string> GetAppRequestTypes( + const std::string policy_app_id) const = 0; protected: /** diff --git a/src/components/policy/src/policy/include/policy/policy_manager_impl.h b/src/components/policy/src/policy/include/policy/policy_manager_impl.h index b93027bdd0..cf3e6c20fb 100644 --- a/src/components/policy/src/policy/include/policy/policy_manager_impl.h +++ b/src/components/policy/src/policy/include/policy/policy_manager_impl.h @@ -166,6 +166,8 @@ class PolicyManagerImpl : public PolicyManager { virtual void OnAppsSearchCompleted(); + virtual const std::vector<std::string> GetAppRequestTypes( + const std::string policy_app_id) const; protected: virtual utils::SharedPtr<policy_table::Table> Parse( const BinaryMessage& pt_content); diff --git a/src/components/policy/src/policy/include/policy/policy_types.h b/src/components/policy/src/policy/include/policy/policy_types.h index bd4de72984..61d06db5ba 100644 --- a/src/components/policy/src/policy/include/policy/policy_types.h +++ b/src/components/policy/src/policy/include/policy/policy_types.h @@ -223,7 +223,8 @@ struct AppPermissions { isAppPermissionsRevoked(false), appRevoked(false), appPermissionsConsentNeeded(false), - appUnauthorized(false) { + appUnauthorized(false), + requestTypeChanged(false) { } std::string application_id; @@ -235,6 +236,8 @@ struct AppPermissions { bool isSDLAllowed; std::string priority; DeviceParams deviceInfo; + bool requestTypeChanged; + std::vector<std::string> requestType; }; /** diff --git a/src/components/policy/src/policy/include/policy/sql_pt_queries.h b/src/components/policy/src/policy/include/policy/sql_pt_queries.h index a8a3affd0b..267ce5eebc 100644 --- a/src/components/policy/src/policy/include/policy/sql_pt_queries.h +++ b/src/components/policy/src/policy/include/policy/sql_pt_queries.h @@ -62,6 +62,7 @@ extern const std::string kSelectAppPolicies; extern const std::string kSelectAppGroups; extern const std::string kSelectNicknames; extern const std::string kSelectAppTypes; +extern const std::string kSelectRequestTypes; extern const std::string kSelectSecondsBetweenRetries; extern const std::string kSelectIgnitionCycles; extern const std::string kSelectKilometers; @@ -74,6 +75,7 @@ extern const std::string kInsertApplication; extern const std::string kInsertAppGroup; extern const std::string kInsertNickname; extern const std::string kInsertAppType; +extern const std::string kInsertRequestType; extern const std::string kInsertMessageType; extern const std::string kInsertLanguage; extern const std::string kInsertMessageString; diff --git a/src/components/policy/src/policy/include/policy/sql_pt_representation.h b/src/components/policy/src/policy/include/policy/sql_pt_representation.h index ebc233d902..851424eb16 100644 --- a/src/components/policy/src/policy/include/policy/sql_pt_representation.h +++ b/src/components/policy/src/policy/include/policy/sql_pt_representation.h @@ -106,6 +106,8 @@ class SQLPTRepresentation : public virtual PTRepresentation { policy_table::Strings* app_groups) const; bool GatherAppType(const std::string& app_id, policy_table::AppHMITypes* app_types) const; + bool GatherRequestType(const std::string& app_id, + policy_table::RequestTypes* request_types) const; bool GatherNickName(const std::string& app_id, policy_table::Strings* nicknames) const; @@ -138,6 +140,8 @@ class SQLPTRepresentation : public virtual PTRepresentation { const policy_table::Strings& nicknames); bool SaveAppType(const std::string& app_id, const policy_table::AppHMITypes& types); + bool SaveRequestType(const std::string& app_id, + const policy_table::RequestTypes& types); public: bool UpdateRequired() const; diff --git a/src/components/policy/src/policy/policy_table/table_struct/enums.cc b/src/components/policy/src/policy/policy_table/table_struct/enums.cc index a0203b7f42..5ba1efe52c 100644 --- a/src/components/policy/src/policy/policy_table/table_struct/enums.cc +++ b/src/components/policy/src/policy/policy_table/table_struct/enums.cc @@ -292,6 +292,143 @@ bool EnumFromJsonString(const std::string& literal, AppHMIType* result) { } } +bool IsValidEnum(RequestType val) { + switch(val) { + case RT_HTTP : return true; + case RT_FILE_RESUME : return true; + case RT_AUTH_REQUEST: return true; + case RT_AUTH_CHALLENGE: return true; + case RT_AUTH_ACK: return true; + case RT_PROPRIETARY: return true; + case RT_QUERY_APPS: return true; + case RT_LAUNCH_APP: return true; + case RT_LOCK_SCREEN_ICON_URL: return true; + case RT_TRAFFIC_MESSAGE_CHANNEL: return true; + case RT_DRIVER_PROFILE: return true; + case RT_VOICE_SEARCH: return true; + case RT_NAVIGATION: return true; + case RT_PHONE: return true; + case RT_CLIMATE: return true; + case RT_SETTINGS: return true; + case RT_VEHICLE_DIAGNOSTICS: return true; + case RT_EMERGENCY: return true; + case RT_MEDIA: return true; + case RT_FOTA: return true; + default: return false; + } +} + +const char*EnumToJsonString(RequestType val) { + switch(val) { + case RT_HTTP : return "HTTP"; + case RT_FILE_RESUME : return "FILE_RESUME"; + case RT_AUTH_REQUEST: return "AUTH_REQUEST"; + case RT_AUTH_CHALLENGE: return "AUTH_CHALLENGE"; + case RT_AUTH_ACK: return "AUTH_ACK"; + case RT_PROPRIETARY: return "PROPRIETARY"; + case RT_QUERY_APPS: return "QUERY_APPS"; + case RT_LAUNCH_APP: return "LAUNCH_APP"; + case RT_LOCK_SCREEN_ICON_URL: return "LOCK_SCREEN_ICON_URL"; + case RT_TRAFFIC_MESSAGE_CHANNEL: return "TRAFFIC_MESSAGE_CHANNEL"; + case RT_DRIVER_PROFILE: return "DRIVER_PROFILE"; + case RT_VOICE_SEARCH: return "VOICE_SEARCH"; + case RT_NAVIGATION: return "NAVIGATION"; + case RT_PHONE: return "PHONE"; + case RT_CLIMATE: return "CLIMATE"; + case RT_SETTINGS: return "SETTINGS"; + case RT_VEHICLE_DIAGNOSTICS: return "VEHICLE_DIAGNOSTICS"; + case RT_EMERGENCY: return "EMERGENCY"; + case RT_MEDIA: return "MEDIA"; + case RT_FOTA: return "FOTA"; + default: return ""; + } +} + +bool EnumFromJsonString(const std::string& literal, RequestType* result) { + if ("HTTP" == literal) { + *result = RT_HTTP; + return true; + } + if ("FILE_RESUME" == literal) { + *result = RT_FILE_RESUME; + return true; + } + if ("AUTH_REQUEST" == literal) { + *result = RT_AUTH_REQUEST; + return true; + } + if ("AUTH_CHALLENGE" == literal) { + *result = RT_AUTH_CHALLENGE; + return true; + } + if ("AUTH_ACK" == literal) { + *result = RT_AUTH_ACK; + return true; + } + if ("PROPRIETARY" == literal) { + *result = RT_PROPRIETARY; + return true; + } + if ("QUERY_APPS" == literal) { + *result = RT_QUERY_APPS; + return true; + } + if ("LAUNCH_APP" == literal) { + *result = RT_LAUNCH_APP; + return true; + } + if ("LOCK_SCREEN_ICON_URL" == literal) { + *result = RT_LOCK_SCREEN_ICON_URL; + return true; + } + if ("TRAFFIC_MESSAGE_CHANNEL" == literal) { + *result = RT_TRAFFIC_MESSAGE_CHANNEL; + return true; + } + if ("DRIVER_PROFILE" == literal) { + *result = RT_DRIVER_PROFILE; + return true; + } + if ("VOICE_SEARCH" == literal) { + *result = RT_VOICE_SEARCH; + return true; + } + if ("NAVIGATION" == literal) { + *result = RT_NAVIGATION; + return true; + } + if ("PHONE" == literal) { + *result = RT_PHONE; + return true; + } + if ("CLIMATE" == literal) { + *result = RT_CLIMATE; + return true; + } + if ("SETTINGS" == literal) { + *result = RT_SETTINGS; + return true; + } + if ("VEHICLE_DIAGNOSTICS" == literal) { + *result = RT_VEHICLE_DIAGNOSTICS; + return true; + } + if ("EMERGENCY" == literal) { + *result = RT_EMERGENCY; + return true; + } + if ("MEDIA" == literal) { + *result = RT_MEDIA; + return true; + } + if ("FOTA" == literal) { + *result = RT_FOTA; + return true; + } else { + return false; + } +} + const std::string kDefaultApp = "default"; const std::string kPreDataConsentApp = "pre_DataConsent"; const std::string kDeviceApp = "device"; diff --git a/src/components/policy/src/policy/policy_table/table_struct/enums.h b/src/components/policy/src/policy/policy_table/table_struct/enums.h index e437860c60..f003679e13 100644 --- a/src/components/policy/src/policy/policy_table/table_struct/enums.h +++ b/src/components/policy/src/policy/policy_table/table_struct/enums.h @@ -79,6 +79,34 @@ bool IsValidEnum(AppHMIType val); const char* EnumToJsonString(AppHMIType val); bool EnumFromJsonString(const std::string& literal, AppHMIType* result); + +enum RequestType { + RT_HTTP, + RT_FILE_RESUME, + RT_AUTH_REQUEST, + RT_AUTH_CHALLENGE, + RT_AUTH_ACK, + RT_PROPRIETARY, + RT_QUERY_APPS, + RT_LAUNCH_APP, + RT_LOCK_SCREEN_ICON_URL, + RT_TRAFFIC_MESSAGE_CHANNEL, + RT_DRIVER_PROFILE, + RT_VOICE_SEARCH, + RT_NAVIGATION, + RT_PHONE, + RT_CLIMATE, + RT_SETTINGS, + RT_VEHICLE_DIAGNOSTICS, + RT_EMERGENCY, + RT_MEDIA, + RT_FOTA +}; + +bool IsValidEnum(RequestType val); +const char* EnumToJsonString(RequestType val); +bool EnumFromJsonString(const std::string& literal, RequestType* result); + extern const std::string kDefaultApp; extern const std::string kPreDataConsentApp; extern const std::string kDeviceApp; diff --git a/src/components/policy/src/policy/policy_table/table_struct/types.cc b/src/components/policy/src/policy/policy_table/table_struct/types.cc index 92172e42a0..f1fbb125c2 100644 --- a/src/components/policy/src/policy/policy_table/table_struct/types.cc +++ b/src/components/policy/src/policy/policy_table/table_struct/types.cc @@ -37,6 +37,7 @@ ApplicationParams::ApplicationParams(const Json::Value* value__) groups(impl::ValueMember(value__, "groups")), nicknames(impl::ValueMember(value__, "nicknames")), AppHMIType(impl::ValueMember(value__, "AppHMIType")), + RequestType(impl::ValueMember(value__, "RequestType")), priority(impl::ValueMember(value__, "priority")), memory_kb(impl::ValueMember(value__, "memory_kb")), heart_beat_timeout_ms(impl::ValueMember(value__, "heart_beat_timeout_ms")), @@ -47,6 +48,7 @@ Json::Value ApplicationParams::ToJsonValue() const { impl::WriteJsonField("groups", groups, &result__); impl::WriteJsonField("nicknames", nicknames, &result__); impl::WriteJsonField("AppHMIType", AppHMIType, &result__); + impl::WriteJsonField("RequestType", RequestType, &result__); impl::WriteJsonField("priority", priority, &result__); impl::WriteJsonField("memory_kb", memory_kb, &result__); impl::WriteJsonField("heart_beat_timeout_ms", heart_beat_timeout_ms, &result__); @@ -63,6 +65,9 @@ bool ApplicationParams::is_valid() const { if (!AppHMIType.is_valid()) { return false; } + if (!RequestType.is_valid()) { + return false; + } if (! priority.is_valid()) { return false; } @@ -91,6 +96,9 @@ bool ApplicationParams::struct_empty() const { if (AppHMIType.is_initialized()) { return false; } + if (RequestType.is_initialized()) { + return false; + } if (priority.is_initialized()) { return false; } @@ -120,6 +128,9 @@ void ApplicationParams::ReportErrors(rpc::ValidationReport* report__) const { if (!AppHMIType.is_valid()) { AppHMIType.ReportErrors(&report__->ReportSubobject("AppHMIType")); } + if (!RequestType.is_valid()) { + RequestType.ReportErrors(&report__->ReportSubobject("RequestType")); + } if (!priority.is_valid()) { priority.ReportErrors(&report__->ReportSubobject("priority")); } @@ -137,6 +148,7 @@ void ApplicationParams::ReportErrors(rpc::ValidationReport* report__) const { void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) { CompositeType::SetPolicyTableType(pt_type); AppHMIType.SetPolicyTableType(pt_type); + RequestType.SetPolicyTableType(pt_type); groups.SetPolicyTableType(pt_type); priority.SetPolicyTableType(pt_type); memory_kb.SetPolicyTableType(pt_type); diff --git a/src/components/policy/src/policy/policy_table/table_struct/types.h b/src/components/policy/src/policy/policy_table/table_struct/types.h index 66c2b1ba06..946ddba39d 100644 --- a/src/components/policy/src/policy/policy_table/table_struct/types.h +++ b/src/components/policy/src/policy/policy_table/table_struct/types.h @@ -54,11 +54,14 @@ typedef Map< Rpcs, 1, 255 > FunctionalGroupings; typedef Map< DeviceParams, 0, 255 > DeviceData; +typedef Array< Enum<RequestType>, 0, 255 > RequestTypes; + struct ApplicationParams : CompositeType { public: Strings groups; Optional< Strings > nicknames; Optional< AppHMITypes > AppHMIType; + Optional< RequestTypes > RequestType; Enum<Priority> priority; Optional< Integer<uint16_t, 0, 65225> > memory_kb; Optional< Integer<uint16_t, 0, 65225> > heart_beat_timeout_ms; diff --git a/src/components/policy/src/policy/src/cache_manager.cc b/src/components/policy/src/policy/src/cache_manager.cc index 32cff5fb14..74ba2a82da 100644 --- a/src/components/policy/src/policy/src/cache_manager.cc +++ b/src/components/policy/src/policy/src/cache_manager.cc @@ -1039,6 +1039,27 @@ int32_t CacheManager::GenerateHash(const std::string& str_to_hash) { return result; } +void CacheManager::GetAppRequestTypes( + const std::string& policy_app_id, + std::vector<std::string>& request_types) const { + LOG4CXX_AUTO_TRACE(logger_); + CACHE_MANAGER_CHECK_VOID(); + policy_table::ApplicationPolicies::iterator policy_iter = + pt_->policy_table.app_policies.find(policy_app_id); + if (pt_->policy_table.app_policies.end() == policy_iter) { + LOG4CXX_DEBUG(logger_, "Can't find request types for app_id " + << policy_app_id); + return; + } + policy_table::RequestTypes::iterator it_request_type = + policy_iter->second.RequestType->begin(); + for (;it_request_type != policy_iter->second.RequestType->end(); + ++it_request_type) { + request_types.push_back(EnumToJsonString(*it_request_type)); + } + return; +} + CacheManager::BackgroundBackuper::BackgroundBackuper(CacheManager* cache_manager) : cache_manager_(cache_manager), stop_flag_(false), diff --git a/src/components/policy/src/policy/src/policy_helper.cc b/src/components/policy/src/policy/src/policy_helper.cc index efae9164bd..46eae2eb7a 100644 --- a/src/components/policy/src/policy/src/policy_helper.cc +++ b/src/components/policy/src/policy/src/policy_helper.cc @@ -328,6 +328,10 @@ bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) { } PermissionsCheckResult result = CheckPermissionsChanges(app_policy); + if (!IsPredefinedApp(app_policy) && IsRequestTypeChanged(app_policy)) { + SetPendingPermissions(app_policy, RESULT_REQUEST_TYPE_CHANGED); + NotifySystem(app_policy); + } if (RESULT_NO_CHANGES == result) { LOG4CXX_INFO(logger_, "Permissions for application:" << app_id << " wasn't changed."); @@ -378,6 +382,11 @@ void policy::CheckAppPolicy::SetPendingPermissions( permissions_diff.appRevokedPermissions = GetRevokedGroups(app_policy); RemoveRevokedConsents(app_policy, permissions_diff.appRevokedPermissions); break; + case RESULT_REQUEST_TYPE_CHANGED: + permissions_diff.priority.clear(); + permissions_diff.requestTypeChanged = true; + permissions_diff.requestType = pm_->GetAppRequestTypes(app_id); + break; default: return; } @@ -425,6 +434,28 @@ bool CheckAppPolicy::IsConsentRequired(const std::string& app_id, return it->second.user_consent_prompt.is_initialized() && !is_preconsented; } +bool CheckAppPolicy::IsRequestTypeChanged( + const AppPoliciesValueType& app_policy) const { + policy::AppPoliciesConstItr it = + snapshot_->policy_table.app_policies.find(app_policy.first); + if (it == snapshot_->policy_table.app_policies.end()) { + if (!app_policy.second.RequestType->empty()) { + return true; + } + return false; + } + if (it->second.RequestType->size() != app_policy.second.RequestType->size()) { + return true; + } + policy_table::RequestTypes diff; + std::set_difference(it->second.RequestType->begin(), + it->second.RequestType->end(), + app_policy.second.RequestType->begin(), + app_policy.second.RequestType->end(), + std::back_inserter(diff)); + return diff.size(); +} + FillNotificationData::FillNotificationData(Permissions& data, GroupConsent group_state, GroupConsent undefined_group_consent) : data_(data) { diff --git a/src/components/policy/src/policy/src/policy_manager_impl.cc b/src/components/policy/src/policy/src/policy_manager_impl.cc index 3e5fa915b6..a80b4adf9d 100644 --- a/src/components/policy/src/policy/src/policy_manager_impl.cc +++ b/src/components/policy/src/policy/src/policy_manager_impl.cc @@ -209,6 +209,8 @@ void PolicyManagerImpl::RequestPTUpdate() { Json::FastWriter writer; std::string message_string = writer.write(value); + LOG4CXX_DEBUG(logger_, "Snapshot contents is : " << message_string ); + BinaryMessage update(message_string.begin(), message_string.end()); @@ -263,6 +265,12 @@ void PolicyManagerImpl::OnAppsSearchCompleted() { } } +const std::vector<std::string> PolicyManagerImpl::GetAppRequestTypes( + const std::string policy_app_id) const { + std::vector<std::string> request_types; + cache_->GetAppRequestTypes(policy_app_id, request_types); + return request_types; +} void PolicyManagerImpl::CheckPermissions(const PTString& app_id, const PTString& hmi_level, const PTString& rpc, @@ -760,8 +768,8 @@ AppPermissions PolicyManagerImpl::GetAppPermissionsChanges( } else { permissions.appPermissionsConsentNeeded = IsConsentNeeded(policy_app_id); permissions.appRevoked = IsApplicationRevoked(policy_app_id); + GetPriority(permissions.application_id, &permissions.priority); } - GetPriority(permissions.application_id, &permissions.priority); return permissions; } diff --git a/src/components/policy/src/policy/src/sql_pt_queries.cc b/src/components/policy/src/policy/src/sql_pt_queries.cc index 9b783f8891..8b56dfbdf9 100644 --- a/src/components/policy/src/policy/src/sql_pt_queries.cc +++ b/src/components/policy/src/policy/src/sql_pt_queries.cc @@ -254,6 +254,14 @@ const std::string kCreateSchema = " FOREIGN KEY(`application_id`) " " REFERENCES `application`(`id`) " "); " + "CREATE TABLE IF NOT EXISTS `request_type`( " + " `request_type` VARCHAR(50) NOT NULL, " + " `application_id` VARCHAR(45) NOT NULL, " + " PRIMARY KEY(`request_type`,`application_id`), " + " CONSTRAINT `fk_app_type_application1` " + " FOREIGN KEY(`application_id`) " + " REFERENCES `application`(`id`) " + "); " "CREATE INDEX IF NOT EXISTS `app_type.fk_app_type_application1_idx` " " ON `app_type`(`application_id`); " "CREATE TABLE IF NOT EXISTS `consent_group`( " @@ -466,6 +474,9 @@ const std::string kInsertNickname = const std::string kInsertAppType = "INSERT OR IGNORE INTO `app_type` (`application_id`, `name`) VALUES (?, ?)"; +const std::string kInsertRequestType = + "INSERT OR IGNORE INTO `request_type` (`application_id`, `request_type`) VALUES (?, ?)"; + const std::string kUpdateVersion = "UPDATE `version` SET `number`= ?"; const std::string kInsertMessageType = @@ -570,6 +581,9 @@ const std::string kSelectNicknames = "SELECT DISTINCT `name` FROM `nickname` " const std::string kSelectAppTypes = "SELECT DISTINCT `name` FROM `app_type` " "WHERE `application_id` = ?"; +const std::string kSelectRequestTypes = + "SELECT DISTINCT `name` FROM `request_type` WHERE `application_id` = ?"; + const std::string kSelectSecondsBetweenRetries = "SELECT `value` FROM `seconds_between_retry` ORDER BY `index`"; diff --git a/src/components/policy/src/policy/src/sql_pt_representation.cc b/src/components/policy/src/policy/src/sql_pt_representation.cc index c350031528..6c679d0f2c 100644 --- a/src/components/policy/src/policy/src/sql_pt_representation.cc +++ b/src/components/policy/src/policy/src/sql_pt_representation.cc @@ -635,14 +635,16 @@ bool SQLPTRepresentation::GatherApplicationPolicies( if (!GatherAppGroup(app_id, ¶ms.groups)) { return false; } - // TODO(IKozyrenko): Check logic if optional container is missing if (!GatherNickName(app_id, &*params.nicknames)) { return false; } - // TODO(IKozyrenko): Check logic if optional container is missing if (!GatherAppType(app_id, &*params.AppHMIType)) { return false; } + if (!GatherRequestType(app_id, &*params.RequestType)) { + return false; + } + (*apps)[app_id] = params; } return true; @@ -862,15 +864,17 @@ bool SQLPTRepresentation::SaveSpecificAppPolicy( if (!SaveAppGroup(app.first, app.second.groups)) { return false; } - // TODO(IKozyrenko): Check logic if optional container is missing if (!SaveNickname(app.first, *app.second.nicknames)) { return false; } - // TODO(IKozyrenko): Check logic if optional container is missing if (!SaveAppType(app.first, *app.second.AppHMIType)) { return false; } + if (!SaveRequestType(app.first, *app.second.RequestType)) { + return false; + } + return true; } @@ -941,6 +945,28 @@ bool SQLPTRepresentation::SaveAppType(const std::string& app_id, return true; } +bool SQLPTRepresentation::SaveRequestType( + const std::string& app_id, + const policy_table::RequestTypes& types) { + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertRequestType)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for request types."); + return false; + } + + policy_table::RequestTypes::const_iterator it; + for (it = types.begin(); it != types.end(); ++it) { + query.Bind(0, app_id); + query.Bind(1, std::string(policy_table::EnumToJsonString(*it))); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into request types."); + return false; + } + } + + return true; +} + bool SQLPTRepresentation::SaveModuleMeta(const policy_table::ModuleMeta& meta) { // Section Module Meta is empty for SDL specific return true; @@ -1297,6 +1323,26 @@ bool SQLPTRepresentation::GatherAppType( return true; } +bool SQLPTRepresentation::GatherRequestType( + const std::string& app_id, + policy_table::RequestTypes* request_types) const { + dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kSelectRequestTypes)) { + LOG4CXX_WARN(logger_, "Incorrect select from request types."); + return false; + } + + query.Bind(0, app_id); + while (query.Next()) { + policy_table::RequestType type; + if (!policy_table::EnumFromJsonString(query.GetString(0), &type)) { + return false; + } + request_types->push_back(type); + } + return true; +} + bool SQLPTRepresentation::GatherNickName( const std::string& app_id, policy_table::Strings* nicknames) const { dbms::SQLQuery query(db()); diff --git a/src/components/policy/test/include/mock_cache_manager.h b/src/components/policy/test/include/mock_cache_manager.h index 0e3f562f29..e1189b8d04 100644 --- a/src/components/policy/test/include/mock_cache_manager.h +++ b/src/components/policy/test/include/mock_cache_manager.h @@ -174,6 +174,9 @@ class MockCacheManagerInterface : public CacheManagerInterface { void()); MOCK_CONST_METHOD1(HeartBeatTimeout, uint16_t(const std::string& app_id)); + MOCK_CONST_METHOD2(GetAppRequestTypes, + void(const std::string& policy_app_id, + std::vector<std::string>& request_types)); MOCK_METHOD1(GetHMIAppTypeAfterUpdate, void(std::map<std::string, StringArray>& app_hmi_types)); MOCK_METHOD0(ResetCalculatedPermissions, diff --git a/src/components/utils/include/utils/file_system.h b/src/components/utils/include/utils/file_system.h index 7b69527606..a132837ca0 100644 --- a/src/components/utils/include/utils/file_system.h +++ b/src/components/utils/include/utils/file_system.h @@ -241,6 +241,25 @@ bool CreateFile(const std::string& path); */ uint64_t GetFileModificationTime(const std::string& path); +/** + * @brief Copy file from source to destination + * + * @param src Source file path + * @param dst Destination file path + * @return if result success return true +*/ +bool CopyFile(const std::string& src, + const std::string& dst); + +/** + * @brief Move file from source to destination + * + * @param src Source file path + * @param dst Destination file path + * @return if result success return true +*/ +bool MoveFile(const std::string& src, + const std::string& dst); void remove_directory_content(const std::string& directory_name); } // namespace file_system diff --git a/src/components/utils/src/file_system.cc b/src/components/utils/src/file_system.cc index f290bce05b..f9e3bb2dbc 100644 --- a/src/components/utils/src/file_system.cc +++ b/src/components/utils/src/file_system.cc @@ -418,8 +418,33 @@ uint64_t file_system::GetFileModificationTime(const std::string& path) { struct stat info; stat(path.c_str(), &info); #ifndef __QNXNTO__ - return static_cast<uint64_t>(info.st_mtim.tv_sec); + return static_cast<uint64_t>(info.st_mtim.tv_nsec); #else return static_cast<uint64_t>(info.st_mtime); #endif } + +bool file_system::CopyFile(const std::string& src, + const std::string& dst) { + if (!FileExists(src) || FileExists(dst) || !CreateFile(dst)) { + return false; + } + std::vector<uint8_t> data; + if (!ReadBinaryFile(src, data) || !WriteBinaryFile(dst, data)) { + DeleteFile(dst); + return false; + } + return true; +} + +bool file_system::MoveFile(const std::string& src, + const std::string& dst) { + if (!CopyFile(src, dst)) { + return false; + } + if (!DeleteFile(src)) { + DeleteFile(dst); + return false; + } + return true; +} |