diff options
39 files changed, 1514 insertions, 31 deletions
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 c8f3bcf888..8ee5ff64f6 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 @@ -398,6 +398,55 @@ class PolicyHandler : public PolicyHandlerInterface, custom_str::CustomString GetAppName( const std::string& policy_app_id) OVERRIDE; + /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + void GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const OVERRIDE; + + /** + * @brief Checks if a given application is an enabled cloud application + * @param policy_app_id Unique application id + * @return true, if the application is an enabled cloud application, + * otherwise - false + */ + const bool CheckCloudAppEnabled( + const std::string& policy_app_id) const OVERRIDE; + + /** + * @brief Get cloud app policy information, all fields that aren't set for a + * given app will be filled with empty strings + * @param policy_app_id Unique application id + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud + * application + * @param certificate Filled with the certificate used to for creating a + * secure connection to the cloud application + * @param auth_token Filled with the token used for authentication when + * reconnecting to the cloud app + * @param cloud_transport_type Filled with the transport type used by the + * cloud application (ex. "WSS") + * @param hybrid_app_preference Filled with the hybrid app preference for the + * cloud application set by the user + */ + void GetCloudAppParameters(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const OVERRIDE; + + /** + * @brief Callback for when a SetCloudAppProperties message is received from a + * mobile app + * @param message The SetCloudAppProperties message + */ + void OnSetCloudAppProperties( + const smart_objects::SmartObject& message) OVERRIDE; + virtual void OnUpdateHMIAppType( std::map<std::string, StringArray> app_hmi_types) OVERRIDE; diff --git a/src/components/application_manager/include/application_manager/smart_object_keys.h b/src/components/application_manager/include/application_manager/smart_object_keys.h index 9b5f63809a..62192da391 100644 --- a/src/components/application_manager/include/application_manager/smart_object_keys.h +++ b/src/components/application_manager/include/application_manager/smart_object_keys.h @@ -188,6 +188,10 @@ extern const char* green; extern const char* blue; extern const char* display_layout; extern const char* icon_resumed; +extern const char* enabled; +extern const char* cloud_app_auth_token; +extern const char* cloud_transport_type; +extern const char* hybrid_app_preference; // PutFile extern const char* sync_file_name; diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 1b64c5d7b4..505f29e13b 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1845,6 +1845,86 @@ bool PolicyHandler::CheckSystemAction( return false; } +void PolicyHandler::GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const { + POLICY_LIB_CHECK_VOID(); + policy_manager_->GetEnabledCloudApps(enabled_apps); +} + +void PolicyHandler::GetCloudAppParameters( + const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const { + POLICY_LIB_CHECK_VOID(); + policy_manager_->GetCloudAppParameters(policy_app_id, + enabled, + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference); +} + +const bool PolicyHandler::CheckCloudAppEnabled( + const std::string& policy_app_id) const { + POLICY_LIB_CHECK(false); + bool enabled = false; + std::string endpoint; + std::string auth_token; + std::string certificate; + std::string cloud_transport_type; + std::string hybrid_app_preference; + policy_manager_->GetCloudAppParameters(policy_app_id, + enabled, + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference); + return enabled; +} + +void PolicyHandler::OnSetCloudAppProperties( + const smart_objects::SmartObject& message) { + POLICY_LIB_CHECK_VOID(); + if (!message.keyExists(strings::msg_params)) { + LOG4CXX_ERROR(logger_, + "Message does not contain mandatory section " + << strings::msg_params); + return; + } + const smart_objects::SmartObject& msg_params = message[strings::msg_params]; + if (!msg_params.keyExists(strings::app_id)) { + LOG4CXX_ERROR(logger_, + "Message does not contain mandatory parameter " + << strings::app_id); + return; + } + std::string policy_app_id(msg_params[strings::app_id].asString()); + if (msg_params.keyExists(strings::enabled)) { + policy_manager_->SetCloudAppEnabled(policy_app_id, + msg_params[strings::enabled].asBool()); + } + if (msg_params.keyExists(strings::cloud_app_auth_token)) { + policy_manager_->SetAppAuthToken( + policy_app_id, msg_params[strings::cloud_app_auth_token].asString()); + } + if (msg_params.keyExists(strings::cloud_transport_type)) { + policy_manager_->SetAppCloudTransportType( + policy_app_id, msg_params[strings::cloud_transport_type].asString()); + } + if (msg_params.keyExists(strings::hybrid_app_preference)) { + // const std::string hybrid_app_preference = + // EnumConversionHelper<HybridAppPreference>::EnumToString(msg_params[strings::hybrid_app_preference]); + // policy_manager_->SetHybridAppPreference( + // policy_app_id, hybrid_app_preference); + } +} + uint32_t PolicyHandler::HeartBeatTimeout(const std::string& app_id) const { POLICY_LIB_CHECK(0); return policy_manager_->HeartBeatTimeout(app_id); diff --git a/src/components/application_manager/src/smart_object_keys.cc b/src/components/application_manager/src/smart_object_keys.cc index e006b893f6..3e2951c553 100644 --- a/src/components/application_manager/src/smart_object_keys.cc +++ b/src/components/application_manager/src/smart_object_keys.cc @@ -155,6 +155,10 @@ const char* green = "green"; const char* blue = "blue"; const char* display_layout = "displayLayout"; const char* icon_resumed = "iconResumed"; +const char* enabled = "enabled"; +const char* cloud_app_auth_token = "cloudAppAuthToken"; +const char* cloud_transport_type = "cloudTransportType"; +const char* hybrid_app_preference = "hybridAppPreference"; // PutFile const char* sync_file_name = "syncFileName"; diff --git a/src/components/include/application_manager/policies/policy_handler_interface.h b/src/components/include/application_manager/policies/policy_handler_interface.h index ee9274ead7..8c8a12ced3 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -437,6 +437,57 @@ class PolicyHandlerInterface { * @return Structure with vehicle information */ virtual const VehicleInfo GetVehicleInfo() 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 + */ + virtual void GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const = 0; + + /** + * @brief Checks if a given application is an enabled cloud application + * @param policy_app_id Unique application id + * @return true if the application is an enabled cloud application, + * false otherwise + */ + virtual const bool CheckCloudAppEnabled( + const std::string& policy_app_id) const = 0; + + /** + * @brief Get cloud app policy information, all fields that aren't set for a + * given app will be filled with empty strings + * @param policy_app_id Unique application id + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud + * application + * @param certificate Filled with the certificate used to for creating a + * secure connection to the cloud application + * @param auth_token Filled with the token used for authentication when + * reconnecting to the cloud app + * @param cloud_transport_type Filled with the transport type used by the + * cloud application (ex. "WSS") + * @param hybrid_app_preference Filled with the hybrid app preference for the + * cloud application set by the user + */ + virtual void GetCloudAppParameters( + const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const = 0; + + /** + * @brief Callback for when a SetCloudAppProperties message is received from a + * mobile app + * @param message The SetCloudAppProperties message + */ + virtual void OnSetCloudAppProperties( + const smart_objects::SmartObject& message) = 0; + #ifdef EXTERNAL_PROPRIETARY_MODE /** * @brief Gets meta information 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 57f6d2f802..37c8a902f1 100644 --- a/src/components/include/policy/policy_external/policy/policy_manager.h +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -523,6 +523,70 @@ class PolicyManager : public usage_statistics::StatisticsManager { virtual const VehicleInfo GetVehicleInfo() 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 + */ + virtual void GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const = 0; + + /** + * @brief Get cloud app policy information, all fields that aren't set for a + * given app will be filled with empty strings + * @param policy_app_id Unique application id + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud + * application + * @param certificate Filled with the certificate used to for creating a + * secure connection to the cloud application + * @param auth_token Filled with the token used for authentication when + * reconnecting to the cloud app + * @param cloud_transport_type Filled with the transport type used by the + * cloud application (ex. "WSS") + * @param hybrid_app_preference Filled with the hybrid app preference for the + * cloud application set by the user + */ + virtual void GetCloudAppParameters( + const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const = 0; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + virtual void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) = 0; + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + virtual void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) = 0; + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + virtual void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type) = 0; + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + virtual void SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) = 0; + + /** * @brief Gets meta information * @return meta information */ 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 ee0bae7118..d22f52bfed 100644 --- a/src/components/include/policy/policy_regular/policy/policy_manager.h +++ b/src/components/include/policy/policy_regular/policy/policy_manager.h @@ -503,6 +503,70 @@ class PolicyManager : public usage_statistics::StatisticsManager { virtual const VehicleInfo GetVehicleInfo() 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 + */ + virtual void GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const = 0; + + /** + * @brief Get cloud app policy information, all fields that aren't set for a + * given app will be filled with empty strings + * @param policy_app_id Unique application id + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud + * application + * @param certificate Filled with the certificate used to for creating a + * secure connection to the cloud application + * @param auth_token Filled with the token used for authentication when + * reconnecting to the cloud app + * @param cloud_transport_type Filled with the transport type used by the + * cloud application (ex. "WSS") + * @param hybrid_app_preference Filled with the hybrid app preference for the + * cloud application set by the user + */ + virtual void GetCloudAppParameters( + const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const = 0; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + virtual void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) = 0; + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + virtual void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) = 0; + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + virtual void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type) = 0; + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + virtual void SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) = 0; + + /** * @brief OnAppRegisteredOnMobile allows to handle event when application were * succesfully registered on mobile device. * It will send OnAppPermissionSend notification and will try to start PTU. * 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 cb47147074..02a0d73086 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 @@ -213,6 +213,20 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { GetAppRequestTypes, const std::vector<std::string>(const std::string& policy_app_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector<std::string>& enabled_apps)); + MOCK_CONST_METHOD1(CheckCloudAppEnabled, + const bool(const std::string& policy_app_id)); + MOCK_CONST_METHOD7(GetCloudAppParameters, + void(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); + MOCK_METHOD1(OnSetCloudAppProperties, + void(const smart_objects::SmartObject& message)); #ifdef EXTERNAL_PROPRIETARY_MODE MOCK_CONST_METHOD0(GetMetaInfo, const policy::MetaInfo()); 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 a4d50d7cc2..db3f37fb91 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 @@ -76,6 +76,27 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { MOCK_METHOD1(SecondsBetweenRetries, bool(std::vector<int>& seconds)); MOCK_CONST_METHOD1(IsDeviceConsentCached, bool(const std::string& device_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const VehicleInfo()); + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector<std::string>& enabled_apps)); + MOCK_CONST_METHOD7(GetCloudAppParameters, + void(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); + MOCK_METHOD2(SetCloudAppEnabled, + void(const std::string& policy_app_id, const bool enabled)); + MOCK_METHOD2(SetAppAuthToken, + void(const std::string& policy_app_id, + const std::string& auth_token)); + MOCK_METHOD2(SetAppCloudTransportType, + void(const std::string& policy_app_id, + const std::string& cloud_transport_type)); + MOCK_METHOD2(SetHybridAppPreference, + void(const std::string& policy_app_id, + const std::string& hybrid_app_preference)); MOCK_CONST_METHOD1(GetDeviceConsent, DeviceConsent(const std::string& device_id)); MOCK_METHOD2(SetDeviceConsent, diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h index aeabf8fdcb..1eabb78019 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 @@ -184,6 +184,27 @@ class MockPolicyManager : public PolicyManager { GetAppRequestTypes, const std::vector<std::string>(const std::string policy_app_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector<std::string>& enabled_apps)); + MOCK_CONST_METHOD7(GetCloudAppParameters, + void(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); + MOCK_METHOD2(SetCloudAppEnabled, + void(const std::string& policy_app_id, const bool enabled)); + MOCK_METHOD2(SetAppAuthToken, + void(const std::string& policy_app_id, + const std::string& auth_token)); + MOCK_METHOD2(SetAppCloudTransportType, + void(const std::string& policy_app_id, + const std::string& cloud_transport_type)); + MOCK_METHOD2(SetHybridAppPreference, + void(const std::string& policy_app_id, + const std::string& hybrid_app_preference)); MOCK_CONST_METHOD0(GetMetaInfo, const policy::MetaInfo()); MOCK_CONST_METHOD0(RetrieveCertificate, std::string()); MOCK_CONST_METHOD0(HasCertificate, bool()); 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 440000dbff..3d8dc4116a 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 @@ -63,6 +63,27 @@ class MockCacheManagerInterface : public CacheManagerInterface { MOCK_METHOD0(TimeoutResponse, int()); MOCK_METHOD1(SecondsBetweenRetries, bool(std::vector<int>& seconds)); MOCK_CONST_METHOD0(GetVehicleInfo, const VehicleInfo()); + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector<std::string>& enabled_apps)); + MOCK_CONST_METHOD7(GetCloudAppParameters, + void(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); + MOCK_METHOD2(SetCloudAppEnabled, + void(const std::string& policy_app_id, const bool enabled)); + MOCK_METHOD2(SetAppAuthToken, + void(const std::string& policy_app_id, + const std::string& auth_token)); + MOCK_METHOD2(SetAppCloudTransportType, + void(const std::string& policy_app_id, + const std::string& cloud_transport_type)); + MOCK_METHOD2(SetHybridAppPreference, + void(const std::string& policy_app_id, + const std::string& hybrid_app_preference)); MOCK_METHOD1(SetVINValue, bool(const std::string& value)); MOCK_METHOD2(GetUserFriendlyMsg, std::vector<UserFriendlyMessage>( 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 0e06e9c1a3..a28ea32108 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 @@ -181,6 +181,27 @@ class MockPolicyManager : public PolicyManager { GetAppRequestTypes, const std::vector<std::string>(const std::string policy_app_id)); MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); + MOCK_CONST_METHOD1(GetEnabledCloudApps, + void(std::vector<std::string>& enabled_apps)); + MOCK_CONST_METHOD7(GetCloudAppParameters, + void(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference)); + MOCK_METHOD2(SetCloudAppEnabled, + void(const std::string& policy_app_id, const bool enabled)); + MOCK_METHOD2(SetAppAuthToken, + void(const std::string& policy_app_id, + const std::string& auth_token)); + MOCK_METHOD2(SetAppCloudTransportType, + void(const std::string& policy_app_id, + const std::string& cloud_transport_type)); + MOCK_METHOD2(SetHybridAppPreference, + void(const std::string& policy_app_id, + const std::string& hybrid_app_preference)); MOCK_CONST_METHOD0(GetMetaInfo, const policy::MetaInfo()); MOCK_CONST_METHOD0(RetrieveCertificate, std::string()); MOCK_CONST_METHOD0(HasCertificate, bool()); 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 d30e7cea24..98f279b345 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -159,6 +159,68 @@ class CacheManager : public CacheManagerInterface { virtual const VehicleInfo GetVehicleInfo() const; /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const; + + /** + * @brief Get cloud app policy information, all fields that aren't set for a + * given app will be filled with empty strings + * @param policy_app_id Unique application id + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud + * application + * @param certificate Filled with the certificate used to for creating a + * secure connection to the cloud application + * @param auth_token Filled with the token used for authentication when + * reconnecting to the cloud app + * @param cloud_transport_type Filled with the transport type used by the + * cloud application (ex. "WSS") + * @param hybrid_app_preference Filled with the hybrid app preference for the + * cloud application set by the user + */ + virtual void GetCloudAppParameters(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + virtual void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled); + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + virtual void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token); + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + virtual void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type); + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + virtual void SetHybridAppPreference(const std::string& policy_app_id, + const std::string& hybrid_app_preference); + + /** * @brief Allows to update 'vin' field in module_meta table. * * @param new 'vin' value. 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 bb9ce14c7f..2a334876ae 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 @@ -166,6 +166,70 @@ class CacheManagerInterface { virtual const VehicleInfo GetVehicleInfo() 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 + */ + virtual void GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const = 0; + + /** + * @brief Get cloud app policy information, all fields that aren't set for a + * given app will be filled with empty strings + * @param policy_app_id Unique application id + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud + * application + * @param certificate Filled with the certificate used to for creating a + * secure connection to the cloud application + * @param auth_token Filled with the token used for authentication when + * reconnecting to the cloud app + * @param cloud_transport_type Filled with the transport type used by the + * cloud application (ex. "WSS") + * @param hybrid_app_preference Filled with the hybrid app preference for the + * cloud application set by the user + */ + virtual void GetCloudAppParameters( + const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const = 0; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + virtual void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) = 0; + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + virtual void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) = 0; + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + virtual void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type) = 0; + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + virtual void SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) = 0; + + /** * @brief Allows to update 'vin' field in module_meta table. * * @param new 'vin' value. 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 3837dda1fa..6d4cbbf773 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 @@ -571,6 +571,69 @@ class PolicyManagerImpl : public PolicyManager { const VehicleInfo GetVehicleInfo() const OVERRIDE; /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + void GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const OVERRIDE; + + /** + * @brief Get cloud app policy information, all fields that aren't set for a + * given app will be filled with empty strings + * @param policy_app_id Unique application id + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud + * application + * @param certificate Filled with the certificate used to for creating a + * secure connection to the cloud application + * @param auth_token Filled with the token used for authentication when + * reconnecting to the cloud app + * @param cloud_transport_type Filled with the transport type used by the + * cloud application (ex. "WSS") + * @param hybrid_app_preference Filled with the hybrid app preference for the + * cloud application set by the user + */ + void GetCloudAppParameters(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const OVERRIDE; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) OVERRIDE; + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) OVERRIDE; + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type) OVERRIDE; + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + void SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) OVERRIDE; + + /** * @brief OnAppRegisteredOnMobile allows to handle event when application were * succesfully registered on mobile device. * It will send OnAppPermissionSend notification and will try to start PTU. * diff --git a/src/components/policy/policy_external/include/policy/policy_table/enums.h b/src/components/policy/policy_external/include/policy/policy_table/enums.h index e9d5319f13..dc2fdab2fa 100644 --- a/src/components/policy/policy_external/include/policy/policy_table/enums.h +++ b/src/components/policy/policy_external/include/policy/policy_table/enums.h @@ -182,6 +182,12 @@ bool IsValidEnum(ModuleType val); const char* EnumToJsonString(ModuleType val); bool EnumFromJsonString(const std::string& literal, ModuleType* result); +enum HybridAppPreference { HAP_MOBILE, HAP_CLOUD, HAP_BOTH }; +bool IsValidEnum(HybridAppPreference val); +const char* EnumToJsonString(HybridAppPreference val); +bool EnumFromJsonString(const std::string& literal, + HybridAppPreference* result); + /** * @brief Enumeration FunctionID. * diff --git a/src/components/policy/policy_external/include/policy/policy_table/types.h b/src/components/policy/policy_external/include/policy/policy_table/types.h index 68e29a97ee..f37531eb63 100644 --- a/src/components/policy/policy_external/include/policy/policy_table/types.h +++ b/src/components/policy/policy_external/include/policy/policy_table/types.h @@ -177,6 +177,13 @@ struct ApplicationParams : PolicyBase { Optional<Integer<uint16_t, 0, 65225> > memory_kb; Optional<Integer<uint32_t, 0, UINT_MAX> > heart_beat_timeout_ms; mutable Optional<ModuleTypes> moduleType; + Optional<String<0, 65535> > certificate; + // Cloud application params + Optional<Enum<HybridAppPreference> > hybrid_app_preference; + Optional<String<0, 255> > endpoint; + Optional<Boolean> enabled; + Optional<String<0, 65535> > auth_token; + Optional<String<0, 255> > cloud_transport_type; public: ApplicationParams(); diff --git a/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml b/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml index 0389986695..5ed852cf45 100644 --- a/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml +++ b/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml @@ -71,6 +71,12 @@ <element name="TESTING" /> <element name="SYSTEM" /> </enum> + + <enum name="HybridAppPreference"> + <element name="MOBILE" /> + <element name="CLOUD" /> + <element name="BOTH" /> + </enum> <!-- Common parameters end --> <!-- app_policies section start --> @@ -93,8 +99,15 @@ <param name="memory_kb" type="Integer" minvalue="1" maxvalue="65225" mandatory="false"/> <param name="watchdog_timer_ms" type="Integer" minvalue="1" maxvalue="65225" mandatory="false"/> - <param name="certificate" type="String" minlength="0" maxlength="255" + <param name="certificate" type="String" minlength="0" maxlength="65535" + mandatory="false" /> + <param name="endpoint" type="String" minlength="0" maxlength="255" mandatory="false" /> + <param name="enabled" type="Boolean" mandatory="false" /> + <param name="auth_token" type="String" minlength="0" maxlength="65535" + mandatory="false" /> + <param name="cloud_transport_type" type="String" minlength="0" maxlength="255" mandatory="false" /> + <param name="hybrid_app_preference" type="HybridAppPreference" mandatory="false" /> </struct> <typedef name="HmiLevels" type="HmiLevel" array="true" diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index c2c2e91257..dc0838d429 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -1389,6 +1389,99 @@ const policy::VehicleInfo CacheManager::GetVehicleInfo() const { return vehicle_info; } +void CacheManager::GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const { + const policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + for (policy_table::ApplicationPolicies::const_iterator it = policies.begin(); + it != policies.end(); + ++it) { + auto app_policy = (*it).second; + if (app_policy.enabled.is_initialized() && *app_policy.enabled) { + enabled_apps.push_back((*it).first); + } + } +} + +void CacheManager::GetCloudAppParameters( + const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const { + const policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::const_iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + auto app_policy = (*policy_iter).second; + endpoint = app_policy.endpoint.is_initialized() ? *app_policy.endpoint + : std::string(); + auth_token = app_policy.auth_token.is_initialized() ? *app_policy.auth_token + : std::string(); + cloud_transport_type = app_policy.cloud_transport_type.is_initialized() + ? *app_policy.cloud_transport_type + : std::string(); + certificate = app_policy.certificate.is_initialized() + ? *app_policy.certificate + : std::string(); + hybrid_app_preference = + app_policy.hybrid_app_preference.is_initialized() + ? EnumToJsonString(*app_policy.hybrid_app_preference) + : std::string(); + enabled = app_policy.enabled.is_initialized() && *app_policy.enabled; + } +} + +void CacheManager::SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) { + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + *(*policy_iter).second.enabled = enabled; + } +} + +void CacheManager::SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) { + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + *(*policy_iter).second.auth_token = auth_token; + } +} + +void CacheManager::SetAppCloudTransportType( + const std::string& policy_app_id, const std::string& cloud_transport_type) { + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + *(*policy_iter).second.cloud_transport_type = cloud_transport_type; + } +} + +void CacheManager::SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) { + policy_table::HybridAppPreference value; + bool valid = EnumFromJsonString(hybrid_app_preference, &value); + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter && valid) { + *(*policy_iter).second.hybrid_app_preference = value; + } +} + std::vector<UserFriendlyMessage> CacheManager::GetUserFriendlyMsg( const std::vector<std::string>& msg_codes, const std::string& language, diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index a603f122e2..df474268ba 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -725,6 +725,49 @@ const VehicleInfo PolicyManagerImpl::GetVehicleInfo() const { return cache_->GetVehicleInfo(); } +void PolicyManagerImpl::GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const { + cache_->GetEnabledCloudApps(enabled_apps); +} + +void PolicyManagerImpl::GetCloudAppParameters( + const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const { + cache_->GetCloudAppParameters(policy_app_id, + enabled, + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference); +} + +void PolicyManagerImpl::SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) { + cache_->SetCloudAppEnabled(policy_app_id, enabled); +} + +void PolicyManagerImpl::SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) { + cache_->SetAppAuthToken(policy_app_id, auth_token); +} + +void PolicyManagerImpl::SetAppCloudTransportType( + const std::string& policy_app_id, const std::string& cloud_transport_type) { + cache_->SetAppCloudTransportType(policy_app_id, cloud_transport_type); +} + +void PolicyManagerImpl::SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) { + cache_->SetHybridAppPreference(policy_app_id, hybrid_app_preference); +} + void PolicyManagerImpl::CheckPermissions(const PTString& app_id, const PTString& hmi_level, const PTString& rpc, diff --git a/src/components/policy/policy_external/src/policy_table/enums.cc b/src/components/policy/policy_external/src/policy_table/enums.cc index 29227adfc6..48ce4d4f72 100644 --- a/src/components/policy/policy_external/src/policy_table/enums.cc +++ b/src/components/policy/policy_external/src/policy_table/enums.cc @@ -1,4 +1,5 @@ #include "policy/policy_table/enums.h" +#include <cstring> namespace rpc { namespace policy_table_interface_base { @@ -847,6 +848,38 @@ bool EnumFromJsonString(const std::string& literal, ModuleType* result) { } } +bool IsValidEnum(HybridAppPreference val) { + return strlen(EnumToJsonString(val)) > 0; +} + +const char* EnumToJsonString(HybridAppPreference val) { + switch (val) { + case HAP_MOBILE: + return "MOBILE"; + case HAP_CLOUD: + return "CLOUD"; + case HAP_BOTH: + return "BOTH"; + default: + return ""; + } +} + +bool EnumFromJsonString(const std::string& literal, + HybridAppPreference* result) { + if ("MOBILE" == literal) { + *result = HAP_MOBILE; + return true; + } else if ("CLOUD" == literal) { + *result = HAP_CLOUD; + return true; + } else if ("BOTH" == literal) { + *result = HAP_BOTH; + return true; + } + return false; +} + bool EnumFromJsonString(const std::string& literal, FunctionID* result) { if ("RegisterAppInterface" == literal) { *result = RegisterAppInterfaceID; diff --git a/src/components/policy/policy_external/src/policy_table/types.cc b/src/components/policy/policy_external/src/policy_table/types.cc index 5922a020e6..977448dacd 100644 --- a/src/components/policy/policy_external/src/policy_table/types.cc +++ b/src/components/policy/policy_external/src/policy_table/types.cc @@ -241,7 +241,14 @@ ApplicationParams::ApplicationParams(const Json::Value* value__) , RequestSubType(impl::ValueMember(value__, "RequestSubType")) , memory_kb(impl::ValueMember(value__, "memory_kb"), 0) , heart_beat_timeout_ms(impl::ValueMember(value__, "heart_beat_timeout_ms")) - , moduleType(impl::ValueMember(value__, "moduleType")) {} + , moduleType(impl::ValueMember(value__, "moduleType")) + , certificate(impl::ValueMember(value__, "certificate"), "not_specified") + , hybrid_app_preference(impl::ValueMember(value__, "hybrid_app_preference")) + , endpoint(impl::ValueMember(value__, "endpoint")) + , enabled(impl::ValueMember(value__, "enabled")) + , auth_token(impl::ValueMember(value__, "auth_token")) + , cloud_transport_type(impl::ValueMember(value__, "cloud_transport_type")) { +} Json::Value ApplicationParams::ToJsonValue() const { Json::Value result__(PolicyBase::ToJsonValue()); @@ -253,6 +260,13 @@ Json::Value ApplicationParams::ToJsonValue() const { impl::WriteJsonField( "heart_beat_timeout_ms", heart_beat_timeout_ms, &result__); impl::WriteJsonField("moduleType", moduleType, &result__); + impl::WriteJsonField("certificate", certificate, &result__); + impl::WriteJsonField( + "hybrid_app_preference", hybrid_app_preference, &result__); + impl::WriteJsonField("endpoint", endpoint, &result__); + impl::WriteJsonField("enabled", enabled, &result__); + impl::WriteJsonField("auth_token", auth_token, &result__); + impl::WriteJsonField("cloud_transport_type", cloud_transport_type, &result__); return result__; } @@ -277,6 +291,24 @@ bool ApplicationParams::is_valid() const { if (!moduleType.is_valid()) { return false; } + if (!certificate.is_valid()) { + return false; + } + if (!endpoint.is_valid()) { + return false; + } + if (!enabled.is_valid()) { + return false; + } + if (!auth_token.is_valid()) { + return false; + } + if (!cloud_transport_type.is_valid()) { + return false; + } + if (!hybrid_app_preference.is_valid()) { + return false; + } return Validate(); } @@ -309,6 +341,24 @@ bool ApplicationParams::struct_empty() const { if (moduleType.is_initialized()) { return false; } + if (certificate.is_initialized()) { + return false; + } + if (endpoint.is_initialized()) { + return false; + } + if (enabled.is_initialized()) { + return false; + } + if (auth_token.is_initialized()) { + return false; + } + if (cloud_transport_type.is_initialized()) { + return false; + } + if (hybrid_app_preference.is_initialized()) { + return false; + } return true; } @@ -357,6 +407,25 @@ void ApplicationParams::ReportErrors(rpc::ValidationReport* report__) const { if (!moduleType.is_valid()) { moduleType.ReportErrors(&report__->ReportSubobject("moduleType")); } + if (!certificate.is_valid()) { + certificate.ReportErrors(&report__->ReportSubobject("certificate")); + } + if (!endpoint.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("endpoint")); + } + if (!enabled.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("enabled")); + } + if (!auth_token.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("auth_token")); + } + if (!cloud_transport_type.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("cloud_transport_type")); + } + if (!hybrid_app_preference.is_valid()) { + moduleType.ReportErrors( + &report__->ReportSubobject("hybrid_app_preference")); + } } void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) { @@ -367,6 +436,11 @@ void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) { memory_kb.SetPolicyTableType(pt_type); heart_beat_timeout_ms.SetPolicyTableType(pt_type); moduleType.SetPolicyTableType(pt_type); + certificate.SetPolicyTableType(pt_type); + endpoint.SetPolicyTableType(pt_type); + enabled.SetPolicyTableType(pt_type); + cloud_transport_type.SetPolicyTableType(pt_type); + hybrid_app_preference.SetPolicyTableType(pt_type); } // RpcParameters methods diff --git a/src/components/policy/policy_external/src/sql_pt_ext_queries.cc b/src/components/policy/policy_external/src/sql_pt_ext_queries.cc index afb1180692..32320b6d6c 100644 --- a/src/components/policy/policy_external/src/sql_pt_ext_queries.cc +++ b/src/components/policy/policy_external/src/sql_pt_ext_queries.cc @@ -205,7 +205,10 @@ const std::string kUpdateGroupPermissions = const std::string kInsertApplication = "INSERT OR IGNORE INTO `application`(`id`, `keep_context`, `steal_focus`, " " `default_hmi`, `priority_value`, `is_revoked`, `memory_kb`, " - " `heart_beat_timeout_ms`) VALUES( ?, ?, ?, ?, ?, ?, ?, ?) "; + " `heart_beat_timeout_ms`, `certificate`, `hybrid_app_preference_value`, " + " `endpoint`, `enabled`, `auth_token`, " + " `cloud_transport_type`) VALUES " + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; const std::string kCollectFriendlyMsg = "SELECT * FROM `message`"; @@ -232,8 +235,9 @@ const std::string kSelectPreconsentedGroupsId = const std::string kSelectAppPolicies = "SELECT `id`, `priority_value`, `default_hmi`, `keep_context`, " - "`steal_focus`, " - " `memory_kb`, `heart_beat_timeout_ms` FROM `application`"; + " `steal_focus`, `memory_kb`, `heart_beat_timeout_ms`, `certificate`, " + " `hybrid_app_preference_value`, `endpoint`, `enabled`, `auth_token` " + " `cloud_transport_type` FROM `application`"; const std::string kSelectFunctionalGroupNames = "SELECT `id`, `user_consent_prompt`, `name`" diff --git a/src/components/policy/policy_external/src/sql_pt_ext_representation.cc b/src/components/policy/policy_external/src/sql_pt_ext_representation.cc index a43b22a3b8..43961815d6 100644 --- a/src/components/policy/policy_external/src/sql_pt_ext_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_ext_representation.cc @@ -752,6 +752,25 @@ bool SQLPTExtRepresentation::SaveSpecificAppPolicy( app_query.Bind(5, app.second.is_null()); app_query.Bind(6, *app.second.memory_kb); app_query.Bind(7, static_cast<int64_t>(*app.second.heart_beat_timeout_ms)); + app.second.certificate.is_initialized() + ? app_query.Bind(8, *app.second.certificate) + : app_query.Bind(8); + app.second.hybrid_app_preference.is_initialized() + ? app_query.Bind(9, + std::string(policy_table::EnumToJsonString( + *app.second.hybrid_app_preference))) + : app_query.Bind(9); + app.second.endpoint.is_initialized() + ? app_query.Bind(10, *app.second.endpoint) + : app_query.Bind(10); + app.second.enabled.is_initialized() ? app_query.Bind(11, *app.second.enabled) + : app_query.Bind(11); + app.second.auth_token.is_initialized() + ? app_query.Bind(12, *app.second.auth_token) + : app_query.Bind(12); + app.second.cloud_transport_type.is_initialized() + ? app_query.Bind(13, *app.second.cloud_transport_type) + : app_query.Bind(13); if (!app_query.Exec() || !app_query.Reset()) { LOG4CXX_WARN(logger_, "Incorrect insert into application."); @@ -873,6 +892,22 @@ bool SQLPTExtRepresentation::GatherApplicationPoliciesSection( params.steal_focus = query.GetBoolean(4); *params.memory_kb = query.GetInteger(5); *params.heart_beat_timeout_ms = query.GetUInteger(6); + if (!query.IsNull(7)) { + *params.certificate = query.GetString(7); + } + + // Read cloud app properties + policy_table::HybridAppPreference hap; + bool valid = policy_table::EnumFromJsonString(query.GetString(8), &hap); + if (valid) { + *params.hybrid_app_preference = hap; + } + *params.endpoint = query.GetString(9); + if (!query.IsNull(10)) { + *params.enabled = query.GetBoolean(10); + } + *params.auth_token = query.GetString(11); + *params.cloud_transport_type = query.GetString(12); const auto& gather_app_id = ((*policies).apps[app_id].is_string()) ? (*policies).apps[app_id].get_string() diff --git a/src/components/policy/policy_external/src/sql_pt_queries.cc b/src/components/policy/policy_external/src/sql_pt_queries.cc index 97d75731ea..162d6957e7 100644 --- a/src/components/policy/policy_external/src/sql_pt_queries.cc +++ b/src/components/policy/policy_external/src/sql_pt_queries.cc @@ -98,6 +98,9 @@ const std::string kCreateSchema = "CREATE TABLE IF NOT EXISTS `hmi_level`( " " `value` VARCHAR(45) PRIMARY KEY NOT NULL " "); " + "CREATE TABLE IF NOT EXISTS `hybrid_app_preference`( " + " `value` VARCHAR(45) PRIMARY KEY NOT NULL " + "); " "CREATE TABLE IF NOT EXISTS `notifications_by_priority`( " " `priority_value` VARCHAR(45) PRIMARY KEY NOT NULL, " " `value` INTEGER NOT NULL, " @@ -147,6 +150,12 @@ const std::string kCreateSchema = " `is_predata` BOOLEAN, " " `memory_kb` INTEGER NOT NULL, " " `heart_beat_timeout_ms` INTEGER NOT NULL, " + " `certificate` VARCHAR(65535), " + " `hybrid_app_preference_value` VARCHAR(255), " + " `endpoint` VARCHAR(255), " + " `enabled` BOOLEAN, " + " `auth_token` VARCHAR(65535), " + " `cloud_transport_type` VARCHAR(255), " " `remote_control_denied` BOOLEAN NOT NULL DEFAULT 0, " " CONSTRAINT `fk_application_hmi_level1` " " FOREIGN KEY(`default_hmi`) " @@ -154,11 +163,17 @@ const std::string kCreateSchema = " CONSTRAINT `fk_application_priorities1` " " FOREIGN KEY(`priority_value`) " " REFERENCES `priority`(`value`) " + " CONSTRAINT `fk_application_hybrid_app_preference1` " + " FOREIGN KEY(`hybrid_app_preference_value`) " + " REFERENCES `hybrid_app_preference`(`value`) " "); " "CREATE INDEX IF NOT EXISTS `application.fk_application_hmi_level1_idx` " " ON `application`(`default_hmi`); " "CREATE INDEX IF NOT EXISTS `application.fk_application_priorities1_idx` " " ON `application`(`priority_value`); " + "CREATE INDEX IF NOT EXISTS " + "`application.fk_application_hybrid_app_preference1` " + " ON `application`(`hybrid_app_preference_value`); " "CREATE TABLE IF NOT EXISTS `app_group`( " " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, " " `functional_group_id` INTEGER NOT NULL, " @@ -430,6 +445,9 @@ const std::string kInsertInitData = "INSERT OR IGNORE INTO `hmi_level`(`value`) VALUES ('LIMITED'); " "INSERT OR IGNORE INTO `hmi_level`(`value`) VALUES ('BACKGROUND'); " "INSERT OR IGNORE INTO `hmi_level`(`value`) VALUES ('NONE'); " + "INSERT OR IGNORE INTO `hybrid_app_preference`(`value`) VALUES ('MOBILE'); " + "INSERT OR IGNORE INTO `hybrid_app_preference`(`value`) VALUES ('CLOUD'); " + "INSERT OR IGNORE INTO `hybrid_app_preference`(`value`) VALUES ('BOTH'); " "INSERT OR IGNORE INTO `version` (`number`) VALUES('0'); " "INSERT OR IGNORE INTO `_internal_data` (`db_version_hash`) VALUES(0); " ""; @@ -532,6 +550,7 @@ const std::string kDropSchema = "`notifications_by_priority.fk_notifications_by_priority_priority1_idx`; " "DROP TABLE IF EXISTS `notifications_by_priority`; " "DROP TABLE IF EXISTS `hmi_level`; " + "DROP TABLE IF EXISTS `hybrid_app_preference`; " "DROP TABLE IF EXISTS `priority`; " "DROP TABLE IF EXISTS `functional_group`; " "DROP TABLE IF EXISTS `module_config`; " @@ -628,8 +647,10 @@ const std::string kInsertRpcWithParameter = const std::string kInsertApplication = "INSERT OR IGNORE INTO `application` (`id`, `priority_value`, " - "`is_revoked`, `memory_kb`," - " `heart_beat_timeout_ms`) VALUES (?,?,?,?,?)"; + "`is_revoked`, `memory_kb`, `heart_beat_timeout_ms`, `certificate`, " + "`hybrid_app_preference_value`, `endpoint`, `enabled`, `auth_token`, " + "`cloud_transport_type`) VALUES " + "(?,?,?,?,?,?,?,?,?,?,?)"; const std::string kInsertAppGroup = "INSERT INTO `app_group` (`application_id`, `functional_group_id`)" @@ -752,7 +773,9 @@ const std::string kSelectUserMsgsVersion = const std::string kSelectAppPolicies = "SELECT `id`, `priority_value`, `memory_kb`, " - " `heart_beat_timeout_ms` FROM `application`"; + " `heart_beat_timeout_ms`, `certificate`, `hybrid_app_preference_value`, " + " `endpoint`, `enabled`, `auth_token`, `cloud_transport_type` FROM " + " `application`"; const std::string kCollectFriendlyMsg = "SELECT * FROM `message`"; @@ -849,15 +872,19 @@ const std::string kDeleteAppGroupByApplicationId = const std::string kInsertApplicationFull = "INSERT OR IGNORE INTO `application` (`id`, `keep_context`, `steal_focus`, " - " `default_hmi`, `priority_value`, `is_revoked`, `is_default`, " - "`is_predata`, " - " `memory_kb`, `heart_beat_timeout_ms`) " - " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + " `default_hmi`, `priority_value`, `is_revoked`, `is_default`, " + " `is_predata`, `memory_kb`, `heart_beat_timeout_ms`, " + " `certificate`, `hybrid_app_preference_value`, `endpoint`, `enabled`, " + " `auth_token`, `cloud_transport_type`) " + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; const std::string kSelectApplicationFull = "SELECT `keep_context`, `steal_focus`, `default_hmi`, `priority_value`, " " `is_revoked`, `is_default`, `is_predata`, `memory_kb`," - " `heart_beat_timeout_ms` FROM `application` WHERE `id` = ?"; + " `heart_beat_timeout_ms`, `certificate`, `hybrid_app_preference_value`, " + " `endpoint`, `enabled`, `auth_token`, `cloud_transport_type` " + "FROM `application` " + "WHERE `id` = ?"; const std::string kSelectDBVersion = "SELECT `db_version_hash` from `_internal_data`"; diff --git a/src/components/policy/policy_external/src/sql_pt_representation.cc b/src/components/policy/policy_external/src/sql_pt_representation.cc index c8b367c8ec..b794d4c3a6 100644 --- a/src/components/policy/policy_external/src/sql_pt_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_representation.cc @@ -761,6 +761,23 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection( *params.memory_kb = query.GetInteger(2); *params.heart_beat_timeout_ms = query.GetUInteger(3); + if (!query.IsNull(4)) { + *params.certificate = query.GetString(4); + } + + // Read cloud app properties + policy_table::HybridAppPreference hap; + bool valid = policy_table::EnumFromJsonString(query.GetString(5), &hap); + if (valid) { + *params.hybrid_app_preference = hap; + } + *params.endpoint = query.GetString(6); + if (!query.IsNull(7)) { + *params.enabled = query.GetBoolean(7); + } + *params.auth_token = query.GetString(8); + *params.cloud_transport_type = query.GetString(9); + const auto& gather_app_id = ((*policies).apps[app_id].is_string()) ? (*policies).apps[app_id].get_string() : app_id; @@ -1035,6 +1052,24 @@ bool SQLPTRepresentation::SaveSpecificAppPolicy( app_query.Bind(2, app.second.is_null()); app_query.Bind(3, *app.second.memory_kb); app_query.Bind(4, static_cast<int64_t>(*app.second.heart_beat_timeout_ms)); + app.second.certificate.is_initialized() + ? app_query.Bind(5, *app.second.certificate) + : app_query.Bind(5); + app.second.hybrid_app_preference.is_initialized() + ? app_query.Bind(6, + std::string(policy_table::EnumToJsonString( + *app.second.hybrid_app_preference))) + : app_query.Bind(6); + app.second.endpoint.is_initialized() ? app_query.Bind(7, *app.second.endpoint) + : app_query.Bind(7); + app.second.enabled.is_initialized() ? app_query.Bind(8, *app.second.enabled) + : app_query.Bind(8); + app.second.auth_token.is_initialized() + ? app_query.Bind(9, *app.second.auth_token) + : app_query.Bind(9); + app.second.cloud_transport_type.is_initialized() + ? app_query.Bind(10, *app.second.cloud_transport_type) + : app_query.Bind(10); if (!app_query.Exec() || !app_query.Reset()) { LOG4CXX_WARN(logger_, "Incorrect insert into application."); @@ -2125,6 +2160,18 @@ bool SQLPTRepresentation::CopyApplication(const std::string& source, : query.Bind(7, source_app.GetBoolean(6)); query.Bind(8, source_app.GetInteger(7)); query.Bind(9, source_app.GetInteger(8)); + source_app.IsNull(9) ? query.Bind(10) + : query.Bind(10, source_app.GetString(9)); + source_app.IsNull(10) ? query.Bind(11) + : query.Bind(11, source_app.GetString(10)); + source_app.IsNull(11) ? query.Bind(12) + : query.Bind(12, source_app.GetString(11)); + source_app.IsNull(12) ? query.Bind(13) + : query.Bind(13, source_app.GetBoolean(12)); + source_app.IsNull(13) ? query.Bind(14) + : query.Bind(14, source_app.GetString(13)); + source_app.IsNull(14) ? query.Bind(15) + : query.Bind(15, source_app.GetString(14)); if (!query.Exec()) { LOG4CXX_WARN(logger_, "Failed inserting into application."); diff --git a/src/components/policy/policy_external/test/sql_pt_representation_test.cc b/src/components/policy/policy_external/test/sql_pt_representation_test.cc index b0f340b0f2..fddc5e631e 100644 --- a/src/components/policy/policy_external/test/sql_pt_representation_test.cc +++ b/src/components/policy/policy_external/test/sql_pt_representation_test.cc @@ -406,8 +406,8 @@ TEST_F(SQLPTRepresentationTest, query.Prepare(query_select); query.Next(); - // 33 - is current total tables number created by schema - const int policy_tables_number = 33; + // 34 - is current total tables number created by schema + const int policy_tables_number = 34; ASSERT_EQ(policy_tables_number, query.GetInteger(0)); const std::string query_select_count_of_iap_buffer_full = 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 48e00f7049..a4ae45d604 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -147,6 +147,68 @@ class CacheManager : public CacheManagerInterface { virtual const VehicleInfo GetVehicleInfo() const; /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + virtual void GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const; + + /** + * @brief Get cloud app policy information, all fields that aren't set for a + * given app will be filled with empty strings + * @param policy_app_id Unique application id + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud + * application + * @param certificate Filled with the certificate used to for creating a + * secure connection to the cloud application + * @param auth_token Filled with the token used for authentication when + * reconnecting to the cloud app + * @param cloud_transport_type Filled with the transport type used by the + * cloud application (ex. "WSS") + * @param hybrid_app_preference Filled with the hybrid app preference for the + * cloud application set by the user + */ + virtual void GetCloudAppParameters(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + virtual void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled); + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + virtual void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token); + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + virtual void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type); + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + virtual void SetHybridAppPreference(const std::string& policy_app_id, + const std::string& hybrid_app_preference); + + /** * @brief Allows to update 'vin' field in module_meta table. * * @param new 'vin' value. 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 10a6ea7f89..f0ee9c2b25 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 @@ -152,6 +152,70 @@ class CacheManagerInterface { virtual const VehicleInfo GetVehicleInfo() 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 + */ + virtual void GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const = 0; + + /** + * @brief Get cloud app policy information, all fields that aren't set for a + * given app will be filled with empty strings + * @param policy_app_id Unique application id + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud + * application + * @param certificate Filled with the certificate used to for creating a + * secure connection to the cloud application + * @param auth_token Filled with the token used for authentication when + * reconnecting to the cloud app + * @param cloud_transport_type Filled with the transport type used by the + * cloud application (ex. "WSS") + * @param hybrid_app_preference Filled with the hybrid app preference for the + * cloud application set by the user + */ + virtual void GetCloudAppParameters( + const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const = 0; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + virtual void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) = 0; + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + virtual void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) = 0; + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + virtual void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type) = 0; + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + virtual void SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) = 0; + + /** * @brief Allows to update 'vin' field in module_meta table. * * @param new 'vin' value. 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 51d4ee88aa..0a0c260a96 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 @@ -565,6 +565,69 @@ class PolicyManagerImpl : public PolicyManager { const VehicleInfo GetVehicleInfo() const OVERRIDE; /** + * @brief Get a list of enabled cloud applications + * @param enabled_apps List filled with the policy app id of each enabled + * cloud application + */ + void GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const OVERRIDE; + + /** + * @brief Get cloud app policy information, all fields that aren't set for a + * given app will be filled with empty strings + * @param policy_app_id Unique application id + * @param enabled Whether or not the app is enabled + * @param endpoint Filled with the endpoint used to connect to the cloud + * application + * @param certificate Filled with the certificate used to for creating a + * secure connection to the cloud application + * @param auth_token Filled with the token used for authentication when + * reconnecting to the cloud app + * @param cloud_transport_type Filled with the transport type used by the + * cloud application (ex. "WSS") + * @param hybrid_app_preference Filled with the hybrid app preference for the + * cloud application set by the user + */ + void GetCloudAppParameters(const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const OVERRIDE; + + /** + * @brief Enable or disable a cloud application in the HMI + * @param enabled Cloud app enabled state + */ + void SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) OVERRIDE; + + /** + * @brief Set an app's auth token + * @param auth_token Cloud app authentication token + */ + void SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) OVERRIDE; + + /** + * @brief Set a cloud app's transport type + * @param cloud_transport_type Cloud app transport type + */ + void SetAppCloudTransportType( + const std::string& policy_app_id, + const std::string& cloud_transport_type) OVERRIDE; + + /** + * @brief Set the user preference for how a hybrid (cloud and mobile) app + * should be used + * @param hybrid_app_preference Hybrid app user preference + */ + void SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) OVERRIDE; + + /** * @brief OnAppRegisteredOnMobile allows to handle event when application were * succesfully registered on mobile device. * It will send OnAppPermissionSend notification and will try to start PTU. * diff --git a/src/components/policy/policy_regular/include/policy/policy_table/enums.h b/src/components/policy/policy_regular/include/policy/policy_table/enums.h index f398e16020..fce6b7b865 100644 --- a/src/components/policy/policy_regular/include/policy/policy_table/enums.h +++ b/src/components/policy/policy_regular/include/policy/policy_table/enums.h @@ -168,6 +168,12 @@ bool IsValidEnum(ModuleType val); const char* EnumToJsonString(ModuleType val); bool EnumFromJsonString(const std::string& literal, ModuleType* result); +enum HybridAppPreference { HAP_MOBILE, HAP_CLOUD, HAP_BOTH }; +bool IsValidEnum(HybridAppPreference val); +const char* EnumToJsonString(HybridAppPreference val); +bool EnumFromJsonString(const std::string& literal, + HybridAppPreference* result); + /** * @brief Enumeration FunctionID. * diff --git a/src/components/policy/policy_regular/include/policy/policy_table/types.h b/src/components/policy/policy_regular/include/policy/policy_table/types.h index e201251745..58f07492c4 100644 --- a/src/components/policy/policy_regular/include/policy/policy_table/types.h +++ b/src/components/policy/policy_regular/include/policy/policy_table/types.h @@ -144,6 +144,12 @@ struct ApplicationParams : PolicyBase { Optional<Integer<uint32_t, 0, UINT_MAX> > heart_beat_timeout_ms; Optional<String<0, 255> > certificate; mutable Optional<ModuleTypes> moduleType; + // Cloud application params + Optional<Enum<HybridAppPreference> > hybrid_app_preference; + Optional<String<0, 255> > endpoint; + Optional<Boolean> enabled; + Optional<String<0, 65535> > auth_token; + Optional<String<0, 255> > cloud_transport_type; public: ApplicationParams(); diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index bd95fc8e7c..c4b3d8db53 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -682,6 +682,99 @@ const policy::VehicleInfo CacheManager::GetVehicleInfo() const { return vehicle_info; } +void CacheManager::GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const { + const policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + for (policy_table::ApplicationPolicies::const_iterator it = policies.begin(); + it != policies.end(); + ++it) { + auto app_policy = (*it).second; + if (app_policy.enabled.is_initialized() && *app_policy.enabled) { + enabled_apps.push_back((*it).first); + } + } +} + +void CacheManager::GetCloudAppParameters( + const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const { + const policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::const_iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + auto app_policy = (*policy_iter).second; + endpoint = app_policy.endpoint.is_initialized() ? *app_policy.endpoint + : std::string(); + auth_token = app_policy.auth_token.is_initialized() ? *app_policy.auth_token + : std::string(); + cloud_transport_type = app_policy.cloud_transport_type.is_initialized() + ? *app_policy.cloud_transport_type + : std::string(); + certificate = app_policy.certificate.is_initialized() + ? *app_policy.certificate + : std::string(); + hybrid_app_preference = + app_policy.hybrid_app_preference.is_initialized() + ? EnumToJsonString(*app_policy.hybrid_app_preference) + : std::string(); + enabled = app_policy.enabled.is_initialized() && *app_policy.enabled; + } +} + +void CacheManager::SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) { + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + *(*policy_iter).second.enabled = enabled; + } +} + +void CacheManager::SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) { + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + *(*policy_iter).second.auth_token = auth_token; + } +} + +void CacheManager::SetAppCloudTransportType( + const std::string& policy_app_id, const std::string& cloud_transport_type) { + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter) { + *(*policy_iter).second.cloud_transport_type = cloud_transport_type; + } +} + +void CacheManager::SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) { + policy_table::HybridAppPreference value; + bool valid = EnumFromJsonString(hybrid_app_preference, &value); + policy_table::ApplicationPolicies& policies = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator policy_iter = + policies.find(policy_app_id); + if (policies.end() != policy_iter && valid) { + *(*policy_iter).second.hybrid_app_preference = value; + } +} + std::vector<UserFriendlyMessage> CacheManager::GetUserFriendlyMsg( const std::vector<std::string>& msg_codes, const std::string& language) { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc index 4985035629..6e635b7f36 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -217,7 +217,7 @@ void FilterInvalidApplicationParameters( } app_params.AppHMIType->swap(valid_app_hmi_types); - // Filter RquestTypes array + // Filter RequestTypes array policy_table::RequestTypes valid_request_types; const policy_table::RequestTypes& request_types = *(app_params.RequestType); for (const auto& request_type : request_types) { @@ -544,6 +544,49 @@ const VehicleInfo PolicyManagerImpl::GetVehicleInfo() const { return cache_->GetVehicleInfo(); } +void PolicyManagerImpl::GetEnabledCloudApps( + std::vector<std::string>& enabled_apps) const { + cache_->GetEnabledCloudApps(enabled_apps); +} + +void PolicyManagerImpl::GetCloudAppParameters( + const std::string& policy_app_id, + bool& enabled, + std::string& endpoint, + std::string& certificate, + std::string& auth_token, + std::string& cloud_transport_type, + std::string& hybrid_app_preference) const { + cache_->GetCloudAppParameters(policy_app_id, + enabled, + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference); +} + +void PolicyManagerImpl::SetCloudAppEnabled(const std::string& policy_app_id, + const bool enabled) { + cache_->SetCloudAppEnabled(policy_app_id, enabled); +} + +void PolicyManagerImpl::SetAppAuthToken(const std::string& policy_app_id, + const std::string& auth_token) { + cache_->SetAppAuthToken(policy_app_id, auth_token); +} + +void PolicyManagerImpl::SetAppCloudTransportType( + const std::string& policy_app_id, const std::string& cloud_transport_type) { + cache_->SetAppCloudTransportType(policy_app_id, cloud_transport_type); +} + +void PolicyManagerImpl::SetHybridAppPreference( + const std::string& policy_app_id, + const std::string& hybrid_app_preference) { + cache_->SetHybridAppPreference(policy_app_id, hybrid_app_preference); +} + void PolicyManagerImpl::CheckPermissions(const PTString& device_id, const PTString& app_id, const PTString& hmi_level, diff --git a/src/components/policy/policy_regular/src/policy_table/enums.cc b/src/components/policy/policy_regular/src/policy_table/enums.cc index bec9a2ec2d..2ddf74af7e 100644 --- a/src/components/policy/policy_regular/src/policy_table/enums.cc +++ b/src/components/policy/policy_regular/src/policy_table/enums.cc @@ -1,5 +1,5 @@ -// This file is generated, do not edit #include "policy/policy_table/enums.h" +#include <cstring> namespace rpc { namespace policy_table_interface_base { @@ -669,6 +669,7 @@ bool IsValidEnum(ModuleType val) { return false; } } + const char* EnumToJsonString(ModuleType val) { switch (val) { case MT_CLIMATE: @@ -716,6 +717,38 @@ bool EnumFromJsonString(const std::string& literal, ModuleType* result) { return false; } +bool IsValidEnum(HybridAppPreference val) { + return strlen(EnumToJsonString(val)) > 0; +} + +const char* EnumToJsonString(HybridAppPreference val) { + switch (val) { + case HAP_MOBILE: + return "MOBILE"; + case HAP_CLOUD: + return "CLOUD"; + case HAP_BOTH: + return "BOTH"; + default: + return ""; + } +} + +bool EnumFromJsonString(const std::string& literal, + HybridAppPreference* result) { + if ("MOBILE" == literal) { + *result = HAP_MOBILE; + return true; + } else if ("CLOUD" == literal) { + *result = HAP_CLOUD; + return true; + } else if ("BOTH" == literal) { + *result = HAP_BOTH; + return true; + } + return false; +} + bool IsValidEnum(FunctionID val) { switch (val) { case RegisterAppInterfaceID: diff --git a/src/components/policy/policy_regular/src/policy_table/types.cc b/src/components/policy/policy_regular/src/policy_table/types.cc index 851ed1bd18..88564df050 100644 --- a/src/components/policy/policy_regular/src/policy_table/types.cc +++ b/src/components/policy/policy_regular/src/policy_table/types.cc @@ -168,7 +168,13 @@ ApplicationParams::ApplicationParams(const Json::Value* value__) , memory_kb(impl::ValueMember(value__, "memory_kb"), 0) , heart_beat_timeout_ms(impl::ValueMember(value__, "heart_beat_timeout_ms")) , certificate(impl::ValueMember(value__, "certificate"), "not_specified") - , moduleType(impl::ValueMember(value__, "moduleType")) {} + , moduleType(impl::ValueMember(value__, "moduleType")) + , hybrid_app_preference(impl::ValueMember(value__, "hybrid_app_preference")) + , endpoint(impl::ValueMember(value__, "endpoint")) + , enabled(impl::ValueMember(value__, "enabled")) + , auth_token(impl::ValueMember(value__, "auth_token")) + , cloud_transport_type(impl::ValueMember(value__, "cloud_transport_type")) { +} Json::Value ApplicationParams::ToJsonValue() const { Json::Value result__(PolicyBase::ToJsonValue()); @@ -180,7 +186,14 @@ Json::Value ApplicationParams::ToJsonValue() const { impl::WriteJsonField("memory_kb", memory_kb, &result__); impl::WriteJsonField( "heart_beat_timeout_ms", heart_beat_timeout_ms, &result__); + impl::WriteJsonField("certificate", certificate, &result__); impl::WriteJsonField("moduleType", moduleType, &result__); + impl::WriteJsonField( + "hybrid_app_preference", hybrid_app_preference, &result__); + impl::WriteJsonField("endpoint", endpoint, &result__); + impl::WriteJsonField("enabled", enabled, &result__); + impl::WriteJsonField("auth_token", auth_token, &result__); + impl::WriteJsonField("cloud_transport_type", cloud_transport_type, &result__); return result__; } @@ -212,6 +225,21 @@ bool ApplicationParams::is_valid() const { if (!moduleType.is_valid()) { return false; } + if (!endpoint.is_valid()) { + return false; + } + if (!enabled.is_valid()) { + return false; + } + if (!auth_token.is_valid()) { + return false; + } + if (!cloud_transport_type.is_valid()) { + return false; + } + if (!hybrid_app_preference.is_valid()) { + return false; + } return Validate(); } @@ -250,6 +278,21 @@ bool ApplicationParams::struct_empty() const { if (moduleType.is_initialized()) { return false; } + if (endpoint.is_initialized()) { + return false; + } + if (enabled.is_initialized()) { + return false; + } + if (auth_token.is_initialized()) { + return false; + } + if (cloud_transport_type.is_initialized()) { + return false; + } + if (hybrid_app_preference.is_initialized()) { + return false; + } return true; } @@ -288,6 +331,22 @@ void ApplicationParams::ReportErrors(rpc::ValidationReport* report__) const { if (!moduleType.is_valid()) { moduleType.ReportErrors(&report__->ReportSubobject("moduleType")); } + if (!endpoint.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("endpoint")); + } + if (!enabled.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("enabled")); + } + if (!auth_token.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("auth_token")); + } + if (!cloud_transport_type.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("cloud_transport_type")); + } + if (!hybrid_app_preference.is_valid()) { + moduleType.ReportErrors( + &report__->ReportSubobject("hybrid_app_preference")); + } } void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) { @@ -300,6 +359,10 @@ void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) { heart_beat_timeout_ms.SetPolicyTableType(pt_type); certificate.SetPolicyTableType(pt_type); moduleType.SetPolicyTableType(pt_type); + endpoint.SetPolicyTableType(pt_type); + enabled.SetPolicyTableType(pt_type); + cloud_transport_type.SetPolicyTableType(pt_type); + hybrid_app_preference.SetPolicyTableType(pt_type); } // RpcParameters methods diff --git a/src/components/policy/policy_regular/src/sql_pt_queries.cc b/src/components/policy/policy_regular/src/sql_pt_queries.cc index f5ccffce3b..297031d4c0 100644 --- a/src/components/policy/policy_regular/src/sql_pt_queries.cc +++ b/src/components/policy/policy_regular/src/sql_pt_queries.cc @@ -84,6 +84,9 @@ const std::string kCreateSchema = "CREATE TABLE IF NOT EXISTS `hmi_level`( " " `value` VARCHAR(45) PRIMARY KEY NOT NULL " "); " + "CREATE TABLE IF NOT EXISTS `hybrid_app_preference`( " + " `value` VARCHAR(45) PRIMARY KEY NOT NULL " + "); " "CREATE TABLE IF NOT EXISTS `notifications_by_priority`( " " `priority_value` VARCHAR(45) PRIMARY KEY NOT NULL, " " `value` INTEGER NOT NULL, " @@ -133,7 +136,12 @@ const std::string kCreateSchema = " `is_predata` BOOLEAN, " " `memory_kb` INTEGER NOT NULL, " " `heart_beat_timeout_ms` INTEGER NOT NULL, " - " `certificate` VARCHAR(45), " + " `certificate` VARCHAR(65535), " + " `hybrid_app_preference_value` VARCHAR(255), " + " `endpoint` VARCHAR(255), " + " `enabled` BOOLEAN, " + " `auth_token` VARCHAR(65535), " + " `cloud_transport_type` VARCHAR(255), " " `remote_control_denied` BOOLEAN NOT NULL DEFAULT 0, " " CONSTRAINT `fk_application_hmi_level1` " " FOREIGN KEY(`default_hmi`) " @@ -141,11 +149,17 @@ const std::string kCreateSchema = " CONSTRAINT `fk_application_priorities1` " " FOREIGN KEY(`priority_value`) " " REFERENCES `priority`(`value`) " + " CONSTRAINT `fk_application_hybrid_app_preference1` " + " FOREIGN KEY(`hybrid_app_preference_value`) " + " REFERENCES `hybrid_app_preference`(`value`) " "); " "CREATE INDEX IF NOT EXISTS `application.fk_application_hmi_level1_idx` " " ON `application`(`default_hmi`); " "CREATE INDEX IF NOT EXISTS `application.fk_application_priorities1_idx` " " ON `application`(`priority_value`); " + "CREATE INDEX IF NOT EXISTS " + "`application.fk_application_hybrid_app_preference1` " + " ON `application`(`hybrid_app_preference_value`); " "CREATE TABLE IF NOT EXISTS `app_group`( " " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, " " `functional_group_id` INTEGER NOT NULL, " @@ -391,6 +405,9 @@ const std::string kInsertInitData = "INSERT OR IGNORE INTO `hmi_level`(`value`) VALUES ('LIMITED'); " "INSERT OR IGNORE INTO `hmi_level`(`value`) VALUES ('BACKGROUND'); " "INSERT OR IGNORE INTO `hmi_level`(`value`) VALUES ('NONE'); " + "INSERT OR IGNORE INTO `hybrid_app_preference`(`value`) VALUES ('MOBILE'); " + "INSERT OR IGNORE INTO `hybrid_app_preference`(`value`) VALUES ('CLOUD'); " + "INSERT OR IGNORE INTO `hybrid_app_preference`(`value`) VALUES ('BOTH'); " "INSERT OR IGNORE INTO `version` (`number`) VALUES('0'); " "INSERT OR IGNORE INTO `_internal_data` (`db_version_hash`) VALUES(0); " ""; @@ -491,6 +508,7 @@ const std::string kDropSchema = "`notifications_by_priority.fk_notifications_by_priority_priority1_idx`; " "DROP TABLE IF EXISTS `notifications_by_priority`; " "DROP TABLE IF EXISTS `hmi_level`; " + "DROP TABLE IF EXISTS `hybrid_app_preference`; " "DROP TABLE IF EXISTS `priority`; " "DROP TABLE IF EXISTS `functional_group`; " "DROP TABLE IF EXISTS `module_config`; " @@ -578,8 +596,10 @@ const std::string kInsertRpcWithParameter = const std::string kInsertApplication = "INSERT OR IGNORE INTO `application` (`id`, `priority_value`, " - "`is_revoked`, `memory_kb`," - " `heart_beat_timeout_ms`, `certificate`) VALUES (?,?,?,?,?,?)"; + "`is_revoked`, `memory_kb`, `heart_beat_timeout_ms`, `certificate`, " + "`hybrid_app_preference_value`, `endpoint`, `enabled`, `auth_token`, " + "`cloud_transport_type`) VALUES " + "(?,?,?,?,?,?,?,?,?,?,?)"; const std::string kInsertAppGroup = "INSERT INTO `app_group` (`application_id`, `functional_group_id`)" @@ -688,7 +708,9 @@ const std::string kSelectUserMsgsVersion = const std::string kSelectAppPolicies = "SELECT `id`, `priority_value`, `memory_kb`, " - " `heart_beat_timeout_ms`, `certificate` FROM `application`"; + " `heart_beat_timeout_ms`, `certificate`, `hybrid_app_preference_value`, " + " `endpoint`, `enabled`, `auth_token`, `cloud_transport_type` FROM " + " `application`"; const std::string kCollectFriendlyMsg = "SELECT * FROM `message`"; @@ -785,15 +807,19 @@ const std::string kDeleteAppGroupByApplicationId = const std::string kInsertApplicationFull = "INSERT OR IGNORE INTO `application` (`id`, `keep_context`, `steal_focus`, " - " `default_hmi`, `priority_value`, `is_revoked`, `is_default`, " - "`is_predata`, " - " `memory_kb`, `heart_beat_timeout_ms`, `certificate`) " - " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + " `default_hmi`, `priority_value`, `is_revoked`, `is_default`, " + " `is_predata`, `memory_kb`, `heart_beat_timeout_ms`, " + " `certificate`, `hybrid_app_preference_value`, `endpoint`, `enabled`, " + " `auth_token`, `cloud_transport_type`) " + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; const std::string kSelectApplicationFull = "SELECT `keep_context`, `steal_focus`, `default_hmi`, `priority_value`, " " `is_revoked`, `is_default`, `is_predata`, `memory_kb`," - " `heart_beat_timeout_ms`, `certificate` FROM `application` WHERE `id` = " + " `heart_beat_timeout_ms`, `certificate`, `hybrid_app_preference_value`, " + " `endpoint`, `enabled`, `auth_token`, `cloud_transport_type` " + "FROM `application` " + "WHERE `id` = " "?"; const std::string kSelectDBVersion = diff --git a/src/components/policy/policy_regular/src/sql_pt_representation.cc b/src/components/policy/policy_regular/src/sql_pt_representation.cc index 75f8be74eb..9282caf535 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -716,12 +716,24 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection( params.priority = priority; *params.memory_kb = query.GetInteger(2); - *params.heart_beat_timeout_ms = query.GetUInteger(3); - if (!query.IsNull(3)) { + if (!query.IsNull(4)) { *params.certificate = query.GetString(4); } + // Read cloud app properties + policy_table::HybridAppPreference hap; + bool valid = policy_table::EnumFromJsonString(query.GetString(5), &hap); + if (valid) { + *params.hybrid_app_preference = hap; + } + *params.endpoint = query.GetString(6); + if (!query.IsNull(7)) { + *params.enabled = query.GetBoolean(7); + } + *params.auth_token = query.GetString(8); + *params.cloud_transport_type = query.GetString(9); + const auto& gather_app_id = ((*policies).apps[app_id].is_string()) ? (*policies).apps[app_id].get_string() : app_id; @@ -984,6 +996,22 @@ bool SQLPTRepresentation::SaveSpecificAppPolicy( app.second.certificate.is_initialized() ? app_query.Bind(5, *app.second.certificate) : app_query.Bind(5); + app.second.hybrid_app_preference.is_initialized() + ? app_query.Bind(6, + std::string(policy_table::EnumToJsonString( + *app.second.hybrid_app_preference))) + : app_query.Bind(6); + app.second.endpoint.is_initialized() ? app_query.Bind(7, *app.second.endpoint) + : app_query.Bind(7); + app.second.enabled.is_initialized() ? app_query.Bind(8, *app.second.enabled) + : app_query.Bind(8); + app.second.auth_token.is_initialized() + ? app_query.Bind(9, *app.second.auth_token) + : app_query.Bind(9); + app.second.cloud_transport_type.is_initialized() + ? app_query.Bind(10, *app.second.cloud_transport_type) + : app_query.Bind(10); + if (!app_query.Exec() || !app_query.Reset()) { LOG4CXX_WARN(logger_, "Incorrect insert into application."); return false; @@ -2084,6 +2112,17 @@ bool SQLPTRepresentation::CopyApplication(const std::string& source, query.Bind(9, source_app.GetInteger(8)); source_app.IsNull(9) ? query.Bind(10) : query.Bind(10, source_app.GetString(9)); + source_app.IsNull(10) ? query.Bind(11) + : query.Bind(11, source_app.GetString(10)); + source_app.IsNull(11) ? query.Bind(12) + : query.Bind(12, source_app.GetString(11)); + source_app.IsNull(12) ? query.Bind(13) + : query.Bind(13, source_app.GetBoolean(12)); + source_app.IsNull(13) ? query.Bind(14) + : query.Bind(14, source_app.GetString(13)); + source_app.IsNull(14) ? query.Bind(15) + : query.Bind(15, source_app.GetString(14)); + if (!query.Exec()) { LOG4CXX_WARN(logger_, "Failed inserting into application."); return false; diff --git a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc index 7d192515dc..030dc374dd 100644 --- a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc +++ b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc @@ -426,8 +426,8 @@ TEST_F(SQLPTRepresentationTest, ASSERT_TRUE(reps->RefreshDB()); // Check PT structure destroyed and tables number is 0 - // There are 29 tables in the database, now. - const int32_t total_tables_number = 29; + // There are 30 tables in the database, now. + const int32_t total_tables_number = 30; ASSERT_EQ(total_tables_number, dbms->FetchOneInt(query_select)); const char* query_select_count_of_iap_buffer_full = "SELECT `count_of_iap_buffer_full` FROM `usage_and_error_count`"; |