diff options
author | JackLivio <jack@livio.io> | 2018-10-15 23:30:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-15 23:30:57 -0400 |
commit | 17c3f5114533f954d9afea8166c1d3d7b3adff2a (patch) | |
tree | eb44d1a866c775bfb142c8a2a1dec20bfcabe13a | |
parent | a79f04439de495787f660019859d46eede5b07e2 (diff) | |
parent | e7e56b24918da119a025bd0787150c008f000798 (diff) | |
download | sdl_core-17c3f5114533f954d9afea8166c1d3d7b3adff2a.tar.gz |
Merge pull request #2676 from LuxoftAKutsan/fix/fix_missing_module_types_for_default_app5.0.0_RC3
Load module types from referenced group for app_policies
13 files changed, 42 insertions, 3163 deletions
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 248372beff..a43b22a3b8 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 @@ -874,33 +874,39 @@ bool SQLPTExtRepresentation::GatherApplicationPoliciesSection( *params.memory_kb = query.GetInteger(5); *params.heart_beat_timeout_ms = query.GetUInteger(6); - if (!GatherAppGroup(app_id, ¶ms.groups)) { + const auto& gather_app_id = ((*policies).apps[app_id].is_string()) + ? (*policies).apps[app_id].get_string() + : app_id; + // Data should be gathered from db by "default" key if application has + // default policies + + if (!GatherAppGroup(gather_app_id, ¶ms.groups)) { return false; } bool denied = false; - if (!GatherRemoteControlDenied(app_id, &denied)) { + if (!GatherRemoteControlDenied(gather_app_id, &denied)) { return false; } if (!denied) { - if (!GatherModuleType(app_id, &*params.moduleType)) { + if (!GatherModuleType(gather_app_id, &*params.moduleType)) { return false; } } - if (!GatherNickName(app_id, &*params.nicknames)) { + if (!GatherNickName(gather_app_id, &*params.nicknames)) { return false; } - if (!GatherAppType(app_id, &*params.AppHMIType)) { + if (!GatherAppType(gather_app_id, &*params.AppHMIType)) { return false; } - if (!GatherRequestType(app_id, &*params.RequestType)) { + if (!GatherRequestType(gather_app_id, &*params.RequestType)) { return false; } - if (!GatherRequestSubType(app_id, &*params.RequestSubType)) { + if (!GatherRequestSubType(gather_app_id, &*params.RequestSubType)) { return false; } - GatherPreconsentedGroup(app_id, &*params.preconsented_groups); + GatherPreconsentedGroup(gather_app_id, &*params.preconsented_groups); (*policies).apps[app_id] = params; } return true; 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 31c69e3725..c8b367c8ec 100644 --- a/src/components/policy/policy_external/src/sql_pt_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_representation.cc @@ -761,30 +761,36 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection( *params.memory_kb = query.GetInteger(2); *params.heart_beat_timeout_ms = query.GetUInteger(3); - if (!GatherAppGroup(app_id, ¶ms.groups)) { + const auto& gather_app_id = ((*policies).apps[app_id].is_string()) + ? (*policies).apps[app_id].get_string() + : app_id; + // Data should be gathered from db by "default" key if application has + // default policies + + if (!GatherAppGroup(gather_app_id, ¶ms.groups)) { return false; } bool denied = false; - if (!GatherRemoteControlDenied(app_id, &denied)) { + if (!GatherRemoteControlDenied(gather_app_id, &denied)) { return false; } if (!denied) { - if (!GatherModuleType(app_id, &*params.moduleType)) { + if (!GatherModuleType(gather_app_id, &*params.moduleType)) { return false; } } - if (!GatherNickName(app_id, &*params.nicknames)) { + if (!GatherNickName(gather_app_id, &*params.nicknames)) { return false; } - if (!GatherAppType(app_id, &*params.AppHMIType)) { + if (!GatherAppType(gather_app_id, &*params.AppHMIType)) { return false; } - if (!GatherRequestType(app_id, &*params.RequestType)) { + if (!GatherRequestType(gather_app_id, &*params.RequestType)) { return false; } - if (!GatherRequestSubType(app_id, &*params.RequestSubType)) { + if (!GatherRequestSubType(gather_app_id, &*params.RequestSubType)) { return false; } diff --git a/src/components/policy/policy_regular/CMakeLists.txt b/src/components/policy/policy_regular/CMakeLists.txt index 225e99329a..a5533302a5 100644 --- a/src/components/policy/policy_regular/CMakeLists.txt +++ b/src/components/policy/policy_regular/CMakeLists.txt @@ -60,8 +60,6 @@ target_link_libraries(UsageStatistics Utils) set(EXCLUDE_PATHS ${POLICY_TABLE_PATHS} ${USAGE_STATISTICS_PATHS} - sql_pt_ext_queries.cc - sql_pt_ext_representation.cc ) set(PATHS 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 a28f1b3461..48e00f7049 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -36,7 +36,6 @@ #include <map> #include "policy/pt_representation.h" -#include "policy/pt_ext_representation.h" #include "policy/usage_statistics/statistics_manager.h" #include "policy/cache_manager_interface.h" #include "utils/threads/thread.h" diff --git a/src/components/policy/policy_regular/include/policy/policy_table.h b/src/components/policy/policy_regular/include/policy/policy_table.h index 353cdda871..8ef3cd7fc8 100644 --- a/src/components/policy/policy_regular/include/policy/policy_table.h +++ b/src/components/policy/policy_regular/include/policy/policy_table.h @@ -34,7 +34,6 @@ #define SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_POLICY_TABLE_H_ #include "policy/pt_representation.h" -#include "policy/pt_ext_representation.h" namespace policy { diff --git a/src/components/policy/policy_regular/include/policy/pt_ext_representation.h b/src/components/policy/policy_regular/include/policy/pt_ext_representation.h deleted file mode 100644 index f70946d1f5..0000000000 --- a/src/components/policy/policy_regular/include/policy/pt_ext_representation.h +++ /dev/null @@ -1,336 +0,0 @@ -/* - Copyright (c) 2013, Ford Motor Company - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following - disclaimer in the documentation and/or other materials provided with the - distribution. - - Neither the name of the Ford Motor Company nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_PT_EXT_REPRESENTATION_H_ -#define SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_PT_EXT_REPRESENTATION_H_ - -#include "policy/pt_representation.h" - -namespace policy { - -enum StatisticsType { - S_NONE = 0, - S_IAP_BUFFER_FULL, - S_SYNC_OUT_OF_MEMORY, - S_SYNC_REBOOTS, - S_MINS_HMI_FULL, - S_MINS_HMI_LIMITED, - S_MINS_HMI_BACKGROUND, - S_MINS_HMI_NONE, - S_RFCOM_LIMIT_REACHED, - S_USER_SELECTIONS, - S_REJECTIONS_SYNC_OUT_OF_MEMORY, - S_REJECTIONS_NICKNAME_MISMATCH, - S_REJECTIONS_DUPLICATE_NAME, - S_REJECTED_RPC_CALLS, - S_RPCS_IN_HMI_NONE, - S_REMOVALS_MISBEHAVED, - S_RUN_ATTEMPTS_WHILE_REVOKED -}; - -enum LanguageType { L_NONE = 0, L_GUI, L_VUI }; - -class PTExtRepresentation : public virtual PTRepresentation { - public: - virtual ~PTExtRepresentation() {} - - /** - * @brief Is application allowed to send notifications while in - * Backgound or limited mode. - * @param app_id Application id - * @return bool Allowed/disallowed. - */ - virtual bool CanAppKeepContext(const std::string& app_id) = 0; - - /** - * @brief Is application allowed to move foreground at will? - * @param app_id Application id - * @return bool Allowed/disallowed. - */ - virtual bool CanAppStealFocus(const std::string& app_id) = 0; - - /** - * @brief Get default_hmi for given application - * @param policy_app_id Unique application id - * @param default_hmi Default HMI level for application or empty, if value was - * not set - * @return true, if succedeed, otherwise - false - */ - virtual bool GetDefaultHMI(const std::string& policy_app_id, - std::string* default_hmi) = 0; - - /** - * @brief Reset user consent for device data and applications permissions - * @return - */ - virtual bool ResetUserConsent() = 0; - - /** - * @brief Reset user consent for device data - * @return - */ - virtual bool ResetDeviceConsents() = 0; - - /** - * @brief Reset user consent for applications permissions - * @return - */ - virtual bool ResetAppConsents() = 0; - - /** - * @brief Get user permissions for device data usage - * @param device_id Generated or obtained id of device - * @param consented_groups Groups consented by user - * @param disallowed_groups Groups not consented by user - * @return true, if query was successfull, otherwise - false - */ - virtual bool GetUserPermissionsForDevice( - const std::string& device_id, - StringArray* consented_groups = NULL, - StringArray* disallowed_groups = NULL) = 0; - - /** - * @brief Gets list of groups permissions from policy table - * @param device_id Unique device id, which hosts specific application - * @param policy_app_id Unique application id - * @param group_types Group list sorted by permission status - * @return true, if query was successfull, otherwise - false - */ - virtual bool GetPermissionsForApp(const std::string& device_id, - const std::string& policy_app_id, - FunctionalIdType* group_types) = 0; - - /** - * @brief Get device groups and preconsented groups from policies section - * @param groups List of groups to be consented for device usage - * @param preconsented_groups List of preconsented groups for device usage - * @return true, if query was successful, otherwise - false - */ - virtual bool GetDeviceGroupsFromPolicies( - policy_table::Strings* groups = NULL, - policy_table::Strings* preconsented_groups = NULL) = 0; - - /** - * @brief Record information about mobile device in Policy Table. - * @param device_id Generated or obtained id of device - * @return bool Success of operation - */ - virtual bool SetDeviceData(const std::string& device_id, - const std::string& hardware = "", - const std::string& firmware = "", - const std::string& os = "", - const std::string& os_version = "", - const std::string& carrier = "", - const uint32_t number_of_ports = 0, - const std::string& connection_type = "") = 0; - - /** - * @brief Sets user consent for particular mobile device, - * i.e. to use device for exchanging of Policy Table. - * @return bool Success of operation - */ - virtual bool SetUserPermissionsForDevice( - const std::string& device_id, - const StringArray& consented_groups = StringArray(), - const StringArray& disallowed_gropus = StringArray()) = 0; - - /** - * @brief Update Application Policies as reaction - * on User allowing/disallowing device this app is running on. - */ - virtual bool ReactOnUserDevConsentForApp(const std::string& app_id, - bool is_device_allowed) = 0; - - /** - * @brief Set user consent on functional groups - * @param permissions User consent on functional group - * @return true, if operation succedeed, otherwise - false - */ - virtual bool SetUserPermissionsForApp( - const PermissionConsent& permissions) = 0; - - /** - * @brief Counter for statistics information: adds 1 to existing number. - * @param type Type of statistics (errors, mins in mode etc) - * @return bool Success of operation - */ - virtual bool IncreaseStatisticsData(StatisticsType type) = 0; - - /** - * @brief Records information about what language - * application tried to register with. - * @param app_id Id of application - * @param type - language for UI/VR - * @param language Language - * @return bool Success of operation - */ - virtual bool SetAppRegistrationLanguage(const std::string& app_id, - LanguageType type, - const std::string& language) = 0; - - /** - * @brief Records information about head unit system to PT - * @return bool Success of operation - */ - virtual bool SetMetaInfo(const std::string& ccpu_version, - const std::string& wers_country_code, - const std::string& language) = 0; - - /** - * @brief Checks, if specific head unit is present in PT - * @return boot Suceess, if present, otherwise - false - */ - virtual bool IsMetaInfoPresent() = 0; - - /** - * @brief Kms pass since last successfull PT update - */ - virtual int GetKmFromSuccessfulExchange() = 0; - - /** - * @brief Days pass since last successfull PT update - */ - virtual int GetDayFromScsExchange() = 0; - - /** - * @brief Ignition cycles pass since last successfull PT update - */ - virtual int GetIgnitionsFromScsExchange() = 0; - - /** - * @brief Set current system language - * @param language System language - * @return true, if succedeed, otherwise - false - */ - virtual bool SetSystemLanguage(const std::string& language) = 0; - - /** - * Increments global counter - * @param type type of counter - */ - virtual void Increment(const std::string& type) const = 0; - - /** - * Increments counter of application - * @param app_id id application - * @param type type of counter - */ - virtual void Increment(const std::string& app_id, - const std::string& type) const = 0; - - /** - * Sets value of application information - * @param app_id id application - * @param type type of information - * @param value value of information - */ - virtual void Set(const std::string& app_id, - const std::string& type, - const std::string& value) const = 0; - - /** - * Adds value to stopwatch of application - * @param app_id id application - * @param type type of stopwatch - * @param seconds value for adding in seconds - */ - virtual void Add(const std::string& app_id, - const std::string& type, - int seconds) const = 0; - - virtual bool CountUnconsentedGroups(const std::string& policy_app_id, - const std::string& device_id, - int* result) const = 0; - - /** - * @brief Gets functional group names and user_consent_prompts, if any - * @param Array to be filled with group ids, names and functional prompts - * @return true, if succeeded, otherwise - false - */ - // TODO(AOleynik): Possibly, we can get rid of this method. Check this. - virtual bool GetFunctionalGroupNames(policy::FunctionalGroupNames& names) = 0; - - /** - * @brief Set app policy to pre_DataConsented policy - * @param app_id Policy ID of application to be changed - * @return true, if succeeded, otherwise - false - */ - virtual bool SetPredataPolicy(const std::string& app_id) = 0; - - /** - * @brief Updates application policy to either pre_DataConsented or not - * @param app_id Policy Id of application to be checked - * @param is_pre_data True of False to setting app policy to be - * pre_DataConsented - * @return true, if succeeded, otherwise - false - */ - virtual bool SetIsPredata(const std::string& app_id, bool is_pre_data) = 0; - - /** - * @brief Removes unpaired devices - * @return true if success - */ - virtual bool CleanupUnpairedDevices(const DeviceIds& device_ids) const = 0; - - /** - * Sets flag of unpaired device - * @param device_id Unique device id - * @param unpaired True, if unpaired, otherwise - false - * @return true if success - */ - virtual bool SetUnpairedDevice(const std::string& device_id, - bool unpaired) const = 0; - - /** - * Gets list of unpaired devices - * @param device_ids output list - * @return true if success - */ - virtual bool UnpairedDevicesList(DeviceIds* device_ids) const = 0; - - /** - * @brief Remove application consent for particular group - * @param policy_app_id Unique application id - * @param functional_group_name Functional group name, which consents should - * be removed - * @return true, in case of success, otherwise - false - */ - virtual bool RemoveAppConsentForGroup( - const std::string& policy_app_id, - const std::string& functional_group_name) const = 0; - virtual bool SaveExternalConsentStatus( - const ExternalConsentStatus& status) const = 0; - virtual ExternalConsentStatus GetExternalConsentStatus() const = 0; -}; -} // namespace policy - -#endif // SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_PT_EXT_REPRESENTATION_H_ diff --git a/src/components/policy/policy_regular/include/policy/sql_pt_ext_queries.h b/src/components/policy/policy_regular/include/policy/sql_pt_ext_queries.h deleted file mode 100644 index 727c0b165d..0000000000 --- a/src/components/policy/policy_regular/include/policy/sql_pt_ext_queries.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - Copyright (c) 2013, " Ford Motor Company - All rights reserved. - - Redistribution and use in source and binary forms, " with or without - modification, " are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, " this - list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, " - this list of conditions and the following - disclaimer in the documentation and/or other materials provided with the - distribution. - - Neither the name of the Ford Motor Company nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, " INCLUDING, " BUT NOT LIMITED TO, " THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, " INDIRECT, " INCIDENTAL, " SPECIAL, " EXEMPLARY, " OR - CONSEQUENTIAL DAMAGES (INCLUDING, " BUT NOT LIMITED TO, " PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, " DATA, " OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, " WHETHER IN - CONTRACT, " STRICT LIABILITY, " OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, " EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_SQL_PT_EXT_QUERIES_H_ -#define SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_SQL_PT_EXT_QUERIES_H_ - -#include <string> - -namespace policy { -namespace sql_pt_ext { - -extern const std::string kSelectKeepContext; -extern const std::string kSelectStealFocus; -extern const std::string kResetDeviceConsents; -extern const std::string kResetAppConsents; -extern const std::string kCountDeviceConsentGroup; -extern const std::string kCountDevice; -extern const std::string kSelectDeviceConsentedGroup; -extern const std::string kUpdateDeviceConsentedGroup; -extern const std::string kUpdateDevice; -extern const std::string kInsertDeviceConsentedGroup; -extern const std::string kInsertDevice; -extern const std::string kSelectDeviceData; -extern const std::string kSelectConsentGroup; -extern const std::string kInsertPreconsentedGroups; -extern const std::string kSelectPreconsentedGroups; -extern const std::string kDeletePreconsentedGroups; -extern const std::string kSelectUsageAndErrorCount; -extern const std::string kSelectAppLevels; -extern const std::string kUpdateGlobalCounters; -extern const std::string kInsertDeviceData; -extern const std::string kDeleteDeviceData; -extern const std::string kInsertConsentGroups; -extern const std::string kCountUnconsentedGroups; -extern const std::string kSelectModuleMeta; -extern const std::string kUpdateMetaParams; -extern const std::string kUpdateModuleMetaVinParam; -extern const std::string kSaveModuleMeta; -extern const std::string kSelectMetaParams; -extern const std::string kCountAppLevel; -extern const std::string kUpdateGroupPermissions; -extern const std::string kSelectDefaultHmi; -extern const std::string kInsertApplication; -extern const std::string kSelectFriendlyMsg; -extern const std::string kCollectFriendlyMsg; -extern const std::string kSelectAppGroupsId; -extern const std::string kSelectConsentedGroupsId; -extern const std::string kCountAppConsents; -extern const std::string kSelectPreconsentedGroupsId; -extern const std::string kSelectFunctionalGroupNames; -extern const std::string kSelectAppPolicies; -extern const std::string kUpdateMetaLanguage; -extern const std::string kDeleteDeviceConsent; -extern const std::string kDeleteAppGroupConsent; -extern const std::string kSelectGroupId; -extern const std::string kSelectApplicationIsPreData; -extern const std::string kUpdateIsPredata; -extern const std::string kHasAppPreloadedGroups; -extern const std::string kUpdateUnpairedDevice; -extern const std::string kSelectUnpairedDevices; -extern const std::string kHasMsgLanguageCode; -extern const std::string kDeletePreconsentedGroupsByApplicationId; -extern const std::string kDeleteAppConsent; -extern const std::string kSelectExternalConsentStatus; -} // namespace sql_pt_ext -} // namespace policy - -#endif // SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_SQL_PT_EXT_QUERIES_H_ diff --git a/src/components/policy/policy_regular/include/policy/sql_pt_ext_representation.h b/src/components/policy/policy_regular/include/policy/sql_pt_ext_representation.h deleted file mode 100644 index 0958bad5e1..0000000000 --- a/src/components/policy/policy_regular/include/policy/sql_pt_ext_representation.h +++ /dev/null @@ -1,206 +0,0 @@ -/* - Copyright (c) 2013, Ford Motor Company - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following - disclaimer in the documentation and/or other materials provided with the - distribution. - - Neither the name of the Ford Motor Company nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_SQL_PT_EXT_REPRESENTATION_H_ -#define SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_SQL_PT_EXT_REPRESENTATION_H_ - -#include <string> -#include "policy/sql_pt_representation.h" -#include "policy/pt_ext_representation.h" - -namespace policy { - -class SQLPTExtRepresentation : public SQLPTRepresentation, - public PTExtRepresentation { - public: - bool CanAppKeepContext(const std::string& app_id); - bool CanAppStealFocus(const std::string& app_id); - bool GetDefaultHMI(const std::string& policy_app_id, - std::string* default_hmi); - bool ResetUserConsent(); - bool ResetDeviceConsents(); - bool ResetAppConsents(); - bool GetUserPermissionsForDevice(const std::string& device_id, - StringArray* consented_groups = NULL, - StringArray* disallowed_groups = NULL); - - bool GetPermissionsForApp(const std::string& device_id, - const std::string& policy_app_id, - FunctionalIdType* group_types); - - bool GetDeviceGroupsFromPolicies( - policy_table::Strings* groups = NULL, - policy_table::Strings* preconsented_groups = NULL); - bool SetDeviceData(const std::string& device_id, - const std::string& hardware = "", - const std::string& firmware = "", - const std::string& os = "", - const std::string& os_version = "", - const std::string& carrier = "", - const uint32_t number_of_ports = 0, - const std::string& connection_type = ""); - bool SetUserPermissionsForDevice( - const std::string& device_id, - const StringArray& consented_groups = StringArray(), - const StringArray& disallowed_groups = StringArray()); - - bool ReactOnUserDevConsentForApp(const std::string& app_id, - bool is_device_allowed); - - bool SetUserPermissionsForApp(const PermissionConsent& permissions); - - std::vector<UserFriendlyMessage> GetUserFriendlyMsg( - const std::vector<std::string>& msg_codes, const std::string& language); - - bool IncreaseStatisticsData(StatisticsType type) { - return true; - } - bool SetAppRegistrationLanguage(const std::string& app_id, - LanguageType type, - const std::string& language) { - return true; - } - - bool SetMetaInfo(const std::string& ccpu_version, - const std::string& wers_country_code, - const std::string& language); - - bool IsMetaInfoPresent(); - - bool SetSystemLanguage(const std::string& language); - - int GetKmFromSuccessfulExchange() { - return true; - } - int GetDayFromScsExchange() { - return true; - } - int GetIgnitionsFromScsExchange() { - return true; - } - - bool GetFunctionalGroupNames(FunctionalGroupNames& names); - bool CleanupUnpairedDevices(const DeviceIds& device_ids) const; - - void Increment(const std::string& type) const; - void Increment(const std::string& app_id, const std::string& type) const; - void Set(const std::string& app_id, - const std::string& type, - const std::string& value) const; - void Add(const std::string& app_id, - const std::string& type, - int seconds) const; - bool SetDefaultPolicy(const std::string& app_id); - bool SetPredataPolicy(const std::string& app_id); - bool SetIsPredata(const std::string& app_id, bool is_pre_data); - bool IsPredataPolicy(const std::string& app_id) const; - bool SetUnpairedDevice(const std::string& device_id, bool unpaired) const; - bool UnpairedDevicesList(DeviceIds* device_ids) const; - bool RemoveAppConsentForGroup(const std::string& policy_app_id, - const std::string& functional_group_name) const; - - virtual bool SetVINValue(const std::string& value); - bool SaveExternalConsentStatus(const ExternalConsentStatus& status) const; - ExternalConsentStatus GetExternalConsentStatus() const; - - private: - void GatherModuleMeta(policy_table::ModuleMeta* meta) const; - void GatherPreconsentedGroup(const std::string& app_id, - policy_table::Strings* groups) const; - bool GatherUsageAndErrorCounts( - policy_table::UsageAndErrorCounts* counts) const; - bool GatherAppLevels(policy_table::AppLevels* apps) const; - void GatherDeviceData(policy_table::DeviceData* data) const; - void GatherConsentGroup(const std::string& device_id, - policy_table::UserConsentRecords* records) const; - bool GatherApplicationPoliciesSection( - policy_table::ApplicationPoliciesSection* policies) const; - bool SaveDeviceData(const policy_table::DeviceData& devices); - bool GatherConsumerFriendlyMessages( - policy_table::ConsumerFriendlyMessages* messages) const; - bool SaveConsentGroup(const std::string& device_id, - const policy_table::UserConsentRecords& records); - bool SaveApplicationPoliciesSection( - const policy_table::ApplicationPoliciesSection& policies); - bool SaveSpecificAppPolicy( - const policy_table::ApplicationPolicies::value_type& app); - bool SaveDevicePolicy(const policy_table::DevicePolicy& device); - bool SavePreconsentedGroup(const std::string& app_id, - const policy_table::Strings& groups); - bool SaveMessageString(const std::string& type, - const std::string& lang, - const policy_table::MessageString& strings); - - virtual bool SaveUsageAndErrorCounts( - const policy_table::UsageAndErrorCounts& counts); - - virtual bool SaveModuleMeta(const policy_table::ModuleMeta& meta); - - bool SaveAppCounters(const policy_table::AppLevels& app_levels); - - bool SaveGlobalCounters(const policy_table::UsageAndErrorCounts& counts); - - bool IsExistAppLevel(const std::string& app_id) const; - - bool GetAllAppGroups(const std::string& policy_app_id, - FunctionalGroupIDs& all_groups); - - bool GetConsentedGroups(const std::string& policy_app_id, - const std::string& device_id, - FunctionalGroupIDs& allowed_groups, - FunctionalGroupIDs& disallowed_groups); - - bool GetPreconsentedGroups(const std::string& policy_app_id, - FunctionalGroupIDs& preconsented_groups); - - void FillFunctionalGroupPermissions( - FunctionalGroupIDs& ids, - FunctionalGroupNames& names, - GroupConsent state, - std::vector<FunctionalGroupPermission>& permissions); - bool CountUnconsentedGroups(const std::string& policy_app_id, - const std::string& device_id, - int* result) const; - - /** - * @brief Checks, if there is message present with requested language in PT - * @param message Message name - * @param language Required message language - * @return True, if message with requested language is present, otherwise - - * false - */ - bool IsMsgLanguagePresent(const std::string& message, - const std::string& language); - -} // namespace policy - -#endif // SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_SQL_PT_EXT_REPRESENTATION_H_ diff --git a/src/components/policy/policy_regular/policy_table_interface_ext.xml b/src/components/policy/policy_regular/policy_table_interface_ext.xml deleted file mode 100644 index 7a751c0ea9..0000000000 --- a/src/components/policy/policy_regular/policy_table_interface_ext.xml +++ /dev/null @@ -1,284 +0,0 @@ - -<?xml version="1.0" standalone="no"?> -<?xml-stylesheet type="text/xml" href="protocol2html.xsl"?> - -<interface name="policy table interface base" version="0.0" - date="2014-01-23"> - - <!-- Common parameters start --> - <enum name="Priority"> - <element name="EMERGENCY" /> - <element name="NAVIGATION" /> - <element name="VOICECOM" /> - <element name="COMMUNICATION" /> - <element name="NORMAL" /> - <element name="NONE" /> - </enum> - - <enum name="HmiLevel"> - <element name="BACKGROUND" /> - <element name="FULL" /> - <element name="LIMITED" /> - <element name="NONE" /> - </enum> - - <enum name="Parameter"> - <element name="gps" /> - <element name="speed" /> - <element name="engineTorque" /> - <element name="externalTemperature" /> - <element name="turnSignal" /> - <element name="fuelLevel" /> - <element name="fuelLevel_State" /> - <element name="headLampStatus" /> - <element name="instantFuelConsumption" /> - <element name="fuelRange" /> - <element name="odometer" /> - <element name="tirePressure" /> - <element name="wiperStatus" /> - <element name="vin" /> - <element name="accPedalPosition" /> - <element name="beltStatus" /> - <element name="electronicParkBrakeStatus" /> - <element name="driverBraking" /> - <element name="prndl" /> - <element name="rpm" /> - <element name="steeringWheelAngle" /> - <element name="engineOilLife" /> - <element name="myKey" /> - <element name="airbagStatus" /> - <element name="bodyInformation" /> - <element name="clusterModeStatus" /> - <element name="deviceStatus" /> - <element name="emergencyEvent" /> - <element name="eCallInfo" /> - </enum> - - <enum name="AppHMIType"> - <element name="DEFAULT" /> - <element name="COMMUNICATION" /> - <element name="MEDIA" /> - <element name="MESSAGING" /> - <element name="NAVIGATION" /> - <element name="INFORMATION" /> - <element name="SOCIAL" /> - <element name="BACKGROUND_PROCESS" /> - <element name="TESTING" /> - <element name="SYSTEM" /> - </enum> - <!-- Common parameters end --> - - <!-- app_policies section start --> - - <typedef name="Strings" type="String" maxlength="255" array="true" - maxsize="255" /> - - <typedef name="AppHMITypes" type="AppHMIType" array="true" - maxsize="255" /> - - <struct name="ApplicationParams"> - <param name="groups" type="Strings" /> - <param name="nicknames" type="Strings" mandatory="false" /> - <param name="preconsented_groups" type="Strings" mandatory="false" /> - <param name="AppHMIType" type="AppHMITypes" mandatory="false" /> - <param name="priority" type="Priority" /> - <param name="default_hmi" type="HmiLevel" /> - <param name="keep_context" type="Boolean" /> - <param name="steal_focus" type="Boolean" /> - <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" - mandatory="false" /> - </struct> - - <typedef name="HmiLevels" type="HmiLevel" array="true" - maxsize="4" /> - <typedef name="Parameters" type="Parameter" array="true"/> - - <struct name="RpcParameters"> - <!-- maxsizes are equal to number of currently known elements of - given type --> - <param name="hmi_levels" type="HmiLevels" /> - <param name="parameters" type="Parameters" mandatory="false" /> - </struct> - - <!-- maxsizes are equal to number of currently known elements of given - type --> - <typedef name="Rpc" type="RpcParameters" map="true" maxsize="50" null_values_allowed="true" /> - - <struct name="Rpcs"> - <param name="user_consent_prompt" type="String" minlegth="1" - maxlength="255" mandatory="false"/> - <param name="rpcs" type="Rpc" null_values_allowed="true"/> - </struct> - <!-- app_policies section end --> - - <!-- module_config section start --> - <!-- minlenght="10" since minimum expected is "http://a.b" --> - <typedef name="URL" type="String" minlength="10" maxlength="255" - array="true" minsize="1" maxsize="255" /> - - <typedef name="URLList" type="URL" map="true" minsize="1" - maxsize="255" /> - - <!-- max number of services is limited to 255 according to protocol specification --> - <typedef name="ServiceEndpoints" type="URLList" map="true" - minsize="1" maxsize="255" /> - - <typedef name="NumberOfNotificationsPerMinute" type="Integer" - map="true" maxsize="7" minvalue="0" maxvalue="255" /> - - <typedef name="SecondsBetweenRetries" type="Integer" array="true" - maxsize="10" minvalue="1" maxvalue="1000" /> - - <struct name="ModuleConfig"> - <param name="device_certificates" type="String" minlength="1" maxlength="100" mandatory="false" map="true" minsize="1" maxsize="255" /> - <param name="preloaded_pt" type="Boolean" mandatory="false" /> - <param name="full_app_id_supported" type="Boolean" mandatory="false" /> - <param name="exchange_after_x_ignition_cycles" type="Integer" - maxvalue="255" /> - <param name="exchange_after_x_kilometers" type="Integer" - maxvalue="4294967296" /> - <param name="exchange_after_x_days" type="Integer" - maxvalue="255" /> - <param name="timeout_after_x_seconds" type="Integer" - maxvalue="65535" /> - <param name="seconds_between_retries" type="SecondsBetweenRetries" /> - <param name="endpoints" type="ServiceEndpoints" /> - <param name="notifications_per_minute_by_priority" type="NumberOfNotificationsPerMinute" /> - <param name="vehicle_make" type="String" maxlength="100" - mandatory="false" /> - <param name="vehicle_model" type="String" maxlength="100" - mandatory="false" /> - <param name="vehicle_year" type="String" minlength="4" maxlength="4" - mandatory="false" /> - </struct> - <!-- module_config section end --> - - <!-- consumer_friendly_messages section start --> - <struct name="MessageString"> - <param name="line1" type="String" maxlength="255" - mandatory="false" /> - <param name="line2" type="String" maxlength="255" - mandatory="false" /> - <param name="tts" type="String" maxlength="65535" mandatory="false" /> - <param name="label" type="String" maxlength="255" - mandatory="false" /> - <param name="textBody" type="String" maxlength="500" - mandatory="false" /> - </struct> - - <typedef name="Languages" map="true" type="MessageString" - maxsize="500" mandatory="false" /> - - <struct name="MessageLanguages"> - <param name="languages" type="Languages" /> - </struct> - - <typedef name="Messages" map="true" type="MessageLanguages" - maxsize="255" /> - - <struct name="ConsumerFriendlyMessages"> - <param name="version" type="String" maxlength="100" /> - <param name="messages" type="Messages" mandatory="false" /> - </struct> - <!-- consumer_friendly_messages section end --> - - <!-- module_meta section start --> - <struct name="ModuleMeta"> - <param name="ccpu_version" type="String" maxlength="250" mandatory="false"/> - <param name="language" type="String" maxlength="250" mandatory="false"/> - <param name="wers_country_code" type="String" maxlength="250" mandatory="false"/> - <param name="pt_exchanged_at_odometer_x" type="Integer" minvalue="0" maxvalue="65535" mandatory="false"/> - <param name="pt_exchanged_x_days_after_epoch" type="Integer" minvalue="0" maxvalue="65535" mandatory="false"/> - <param name="ignition_cycles_since_last_exchange" type="Integer" minvalue="0" maxvalue="65535" mandatory="false"/> - <param name="vin" type="String" maxlength="250" mandatory="false"/> - </struct> - <!-- module_meta section end --> - - <!-- usage_and_error_counts section start --> - <struct name="AppLevel"> - <param name="minutes_in_hmi_full" type="Integer" minvalue="0" maxvalue="65535" /> - <param name="app_registration_language_gui" type="String" minlength="1" maxlength="10" /> - <param name="app_registration_language_vui" type="String" minlength="1" maxlength="10" /> - <param name="count_of_rfcom_limit_reached" type="Integer" minvalue="0" maxvalue="65535" /> - <param name="minutes_in_hmi_limited" type="Integer" minvalue="0" maxvalue="65535" /> - <param name="minutes_in_hmi_background" type="Integer" minvalue="0" maxvalue="65535" /> - <param name="minutes_in_hmi_none" type="Integer" minvalue="0" maxvalue="65535" /> - <param name="count_of_user_selections" type="Integer" minvalue="0" maxvalue="65535" /> - <param name="count_of_rejections_sync_out_of_memory" type="Integer" minvalue="0" maxvalue="65535" /> - <param name="count_of_rejections_nickname_mismatch" type="Integer" minvalue="0" maxvalue="65535" /> - <param name="count_of_rejections_duplicate_name" type="Integer" minvalue="0" maxvalue="65535" /> - <param name="count_of_rejected_rpc_calls" type="Integer" minvalue="0" maxvalue="65535" /> - <param name="count_of_rpcs_sent_in_hmi_none" type="Integer" minvalue="0" maxvalue="65535" /> - <param name="count_of_removals_for_bad_behavior" type="Integer" minvalue="0" maxvalue="65535" /> - <param name="count_of_run_attempts_while_revoked" type="Integer" minvalue="0" maxvalue="65535" /> - </struct> - - <typedef name="AppLevels" type="AppLevel" map="true" - maxsize="255" /> - - <struct name="UsageAndErrorCounts"> - <param name="count_of_iap_buffer_full" type="Integer" minvalue="0" maxvalue="65535" mandatory="false" /> - <param name="count_sync_out_of_memory" type="Integer" minvalue="0" maxvalue="65535" mandatory="false" /> - <param name="count_of_sync_reboots" type="Integer" minvalue="0" maxvalue="65535" mandatory="false" /> - <param name="app_level" type="AppLevels" mandatory="false" /> - </struct> - <!-- usage_and_error_counts section end --> - - <!-- device_data section start --> - <enum name="Input" scope="internal"> - <element name="GUI" /> - <element name="VUI" /> - </enum> - - <typedef name="ConsentGroups" scope="internal" type="Boolean" map="true" maxsize="255" mandatory="false"/> - - <struct name="ConsentRecords" scope="internal"> - <param name="consent_groups" type="ConsentGroups" mandatory="false"/> - <param name="input" type="Input" mandatory="false" /> - <param name="time_stamp" type="String" maxlength="255" mandatory="false" /> - </struct> - - <typedef name="UserConsentRecords" scope="internal" map="true" type="ConsentRecords" minsize="0" maxsize="1000"/> - - <struct name="DeviceParams" scope="internal"> - <param name="hardware" type="String" maxlength="255" mandatory="false"/> - <param name="firmware_rev" type="String" maxlength="255" nullable="true" mandatory="false"/> - <param name="os" type="String" maxlength="255" mandatory="false"/> - <param name="os_version" type="String" maxlength="255" mandatory="false"/> - <param name="carrier" type="String" maxlength="255" nullable="true" mandatory="false"/> - <param name="user_consent_records" type="UserConsentRecords" mandatory="false"/> - <param name="max_number_rfcom_ports" type="Integer" maxvalue="255" mandatory="false"/> - </struct> - <!-- device_data section end --> - - <!-- policy_table section start --> - <typedef name="ApplicationPolicies" map="true" type="ApplicationParams" - null_values_allowed="true" minsize="1" maxsize="1000" /> - - <typedef name="FunctionalGroupings" map="true" type="Rpcs" - minsize="1" maxsize="255" /> - - <typedef name="DeviceData" map="true" type="DeviceParams" - maxsize="255" /> - - <struct name="PolicyTable"> - <!-- maxsize for app_policies can be changed, if necessary --> - <param name="app_policies" type="ApplicationPolicies" /> - <param name="functional_groupings" type="FunctionalGroupings" /> - <param name="consumer_friendly_messages" type="ConsumerFriendlyMessages" /> - <param name="module_config" type="ModuleConfig" /> - <param name="module_meta" type="ModuleMeta" mandatory="false"/> - <param name="usage_and_error_counts" type="UsageAndErrorCounts" mandatory="false" /> - <param name="device_data" type="DeviceData" mandatory="false" /> - </struct> - <!-- policy_table section end --> - - <!-- Root element --> - <struct name="Table"> - <param name="policy_table" type="PolicyTable" /> - </struct> - -</interface> diff --git a/src/components/policy/policy_regular/src/sql_pt_ext_queries.cc b/src/components/policy/policy_regular/src/sql_pt_ext_queries.cc deleted file mode 100644 index 3fde462a32..0000000000 --- a/src/components/policy/policy_regular/src/sql_pt_ext_queries.cc +++ /dev/null @@ -1,268 +0,0 @@ -/* - Copyright (c) 2013, " Ford Motor Company - All rights reserved. - - Redistribution and use in source and binary forms, " with or without - modification, " are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, " this - list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, " - this list of conditions and the following - disclaimer in the documentation and/or other materials provided with the - distribution. - - Neither the name of the Ford Motor Company nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, " INCLUDING, " BUT NOT LIMITED TO, " THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, " INDIRECT, " INCIDENTAL, " SPECIAL, " EXEMPLARY, " OR - CONSEQUENTIAL DAMAGES (INCLUDING, " BUT NOT LIMITED TO, " PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, " DATA, " OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, " WHETHER IN - CONTRACT, " STRICT LIABILITY, " OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, " EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - */ - -#include "policy/sql_pt_ext_queries.h" - -namespace policy { -namespace sql_pt_ext { - -const std::string kSelectKeepContext = - "SELECT `keep_context` FROM `application` WHERE `id` = ? LIMIT 1"; - -const std::string kSelectStealFocus = - "SELECT `steal_focus` FROM `application` WHERE `id` = ? LIMIT 1"; - -const std::string kSelectDefaultHmi = - "SELECT `default_hmi` FROM `application` WHERE `id` = ? LIMIT 1"; - -const std::string kResetDeviceConsents = "DELETE FROM `device_consent_group`"; - -const std::string kResetAppConsents = "DELETE FROM `consent_group`"; - -const std::string kCountDeviceConsentGroup = - "SELECT COUNT (`device_id`) " - "FROM `device_consent_group` WHERE `device_id` = ?"; - -const std::string kCountDevice = - "SELECT COUNT (`id`) " - "FROM `device` WHERE `id` = ?"; - -const std::string kSelectDeviceConsentedGroup = - "SELECT * FROM `device_consent_group` WHERE `device_id` = ?"; - -const std::string kUpdateDeviceConsentedGroup = - "UPDATE `device_consent_group` SET `is_consented` = ?, `input` = ? WHERE " - "(`device_id` = ? AND `functional_group_id` = ?)"; - -const std::string kUpdateDevice = - "UPDATE `device` SET `hardware` = ?, `firmware_rev` = ?, `os` = ?, " - "`os_version` = ?, `carrier` = ?, `max_number_rfcom_ports` = ?, " - " `connection_type` = ? WHERE `id` = ? "; - -const std::string kInsertDeviceConsentedGroup = - "INSERT OR REPLACE INTO `device_consent_group` " - "(`device_id`, `functional_group_id`, `is_consented`, `input`, " - "`time_stamp`) " - "VALUES (?,?,?,?,?)"; - -const std::string kInsertDevice = - "INSERT OR IGNORE INTO `device` " - "(`id`, `hardware`, `firmware_rev`, `os`, `os_version`, `carrier`," - "`max_number_rfcom_ports`, `connection_type`) " - "VALUES (?,?,?,?,?,?,?,?)"; - -const std::string kSelectDeviceData = "SELECT * FROM `device`"; - -const std::string kSelectConsentGroup = - "SELECT * FROM `consent_group` WHERE `device_id` = ? "; - -const std::string kInsertPreconsentedGroups = - "INSERT INTO `preconsented_group` (`application_id`, `functional_group_id`)" - " SELECT ?, `id` FROM `functional_group` WHERE `name` = ? LIMIT 1"; - -const std::string kSelectPreconsentedGroups = - "SELECT `f`.`name` FROM `preconsented_group` AS `p`" - " LEFT JOIN `functional_group` AS `f` " - " ON (`f`.`id` = `p`.`functional_group_id`)" - " WHERE `p`.`application_id` = ?"; - -const std::string kDeletePreconsentedGroups = - "DELETE FROM `preconsented_group`"; - -const std::string kSelectUsageAndErrorCount = - "SELECT `count_of_iap_buffer_full`, `count_sync_out_of_memory`, " - " `count_of_sync_reboots` " - "FROM `usage_and_error_count` LIMIT 1"; - -const std::string kSelectAppLevels = - "SELECT `application_id`, `minutes_in_hmi_full`, `minutes_in_hmi_limited`, " - " `minutes_in_hmi_background`, `minutes_in_hmi_none`, " - " `count_of_user_selections`, " - " `count_of_rejections_sync_out_of_memory`, " - " `count_of_rejections_nickname_mismatch`, " - " `count_of_rejections_duplicate_name`, " - " `count_of_rejected_rpcs_calls`, " - " `count_of_rpcs_sent_in_hmi_none`, " - " `count_of_removals_for_bad_behavior`, " - " `count_of_run_attempts_while_revoked`, " - " `app_registration_language_gui`, " - " `app_registration_language_vui`, " - " `count_of_tls_errors` " - "FROM `app_level`"; - -const std::string kUpdateGlobalCounters = - "UPDATE `usage_and_error_count` SET " - "`count_of_iap_buffer_full` = ?, " - "`count_sync_out_of_memory` = ?, " - "`count_of_sync_reboots` = ? "; - -const std::string kInsertDeviceData = - "INSERT OR IGNORE INTO `device` " - "(`id`, `hardware`, `firmware_rev`, `os`, `os_version`, `carrier`, " - "`max_number_rfcom_ports`,`connection_type`) VALUES (?,?,?,?,?,?,?,?) "; - -const std::string kInsertConsentGroups = - "INSERT OR REPLACE INTO `consent_group` " - "(`device_id`, `application_id`, `functional_group_id`, `is_consented`, " - "`input`, `time_stamp`) " - "VALUES (?,?,?,?,?,?)"; - -const std::string kDeleteAppGroupConsent = - "DELETE FROM `consent_group` WHERE " - "`application_id` = ? AND `functional_group_id` = ? "; - -const std::string kSelectGroupId = - "SELECT `id` FROM `functional_group` WHERE `name` = ? "; - -const std::string kCountUnconsentedGroups = - "SELECT COUNT(`a`.`functional_group_id`) FROM `app_group` AS `a` " - " WHERE `a`.`application_id` = ? AND NOT EXISTS " - " (SELECT NULL FROM `preconsented_group` AS `p` WHERE " - " (`p`.`functional_group_id` = `a`.`functional_group_id` AND " - " `p`.`application_id` = `a`.`application_id`)) " - " AND NOT EXISTS (SELECT NULL FROM `consent_group` AS `c` " - " WHERE (`c`.`application_id` = `a`.`application_id` " - " AND `c`.`functional_group_id` = `a`.`functional_group_id` " - " AND `c`.`device_id` = ?)) AND NOT EXISTS " - " (SELECT NULL FROM `app_group` AS `def` WHERE " - " (`def`.`application_id` = ? OR " - " `def`.`application_id` = ?) " - " AND `def`.`functional_group_id` = `a`.`functional_group_id`)" - " AND NOT EXISTS (SELECT NULL FROM `functional_group` AS `f` " - " WHERE (`a`.`functional_group_id` = `f`.`id`" - " AND`f`.`user_consent_prompt` IS NULL))"; - -const std::string kSelectModuleMeta = "SELECT* FROM `module_meta`"; - -const std::string kUpdateMetaParams = - "UPDATE `module_meta` SET " - "`ccpu_version` = ?, `wers_country_code` = ?, `language` = ? "; - -const std::string kUpdateModuleMetaVinParam = - "UPDATE `module_meta` SET `vin` = ? "; - -const std::string kSaveModuleMeta = - "UPDATE `module_meta` SET `ccpu_version` = ?, `language` = ?," - "`wers_country_code` = ?, `pt_exchanged_at_odometer_x` = ?," - "`pt_exchanged_x_days_after_epoch` = ?," - "`ignition_cycles_since_last_exchange` = ?, `vin` = ?"; - -const std::string kSelectMetaParams = - "SELECT `ccpu_version`, " - "`wers_country_code`, `language` from `module_meta`"; - -const std::string kUpdateMetaLanguage = - "UPDATE `module_meta` SET `language` = ? "; - -const std::string kCountAppLevel = - "SELECT COUNT(`application_id`) FROM `app_level`" - " WHERE `application_id` = ? "; - -const std::string kUpdateGroupPermissions = - "UPDATE `consent_group` " - "SET `is_consented` = ?, `input` = ? " - "WHERE(`application_id` = ? AND `functional_group_id` = ? AND `device_id` " - "= ?) "; - -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`, `certificate`) VALUES( ?, ?, ?, ?, ?, ?, ?, ?, " - "?) "; - -const std::string kCollectFriendlyMsg = "SELECT * FROM `message`"; - -const std::string kSelectFriendlyMsg = - "SELECT `tts`, `label`, `line1`, `line2`, `textBody` FROM `message` " - "WHERE `message_type_name` = ? AND `language_code` = ? LIMIT 1"; - -const std::string kSelectAppGroupsId = - "SELECT `functional_group_id` " - "FROM `app_group` WHERE `application_id` = ? "; - -const std::string kSelectConsentedGroupsId = - "SELECT `functional_group_id`, `is_consented` " - "FROM `consent_group` WHERE(`application_id` = ? AND `device_id` = ?) "; - -const std::string kCountAppConsents = - "SELECT COUNT(*) from `consent_group`" - "WHERE(`device_id` = ? AND `application_id` = ? AND " - "`functional_group_id` = ?) "; - -const std::string kSelectPreconsentedGroupsId = - "SELECT `functional_group_id` " - "FROM `preconsented_group` WHERE `application_id` = ? "; - -const std::string kSelectAppPolicies = - "SELECT `id`, `priority_value`, `default_hmi`, `keep_context`, " - "`steal_focus`, " - " `memory_kb`, `heart_beat_timeout_ms`, `certificate` FROM `application`"; - -const std::string kSelectFunctionalGroupNames = - "SELECT `id`, `user_consent_prompt`, `name`" - " FROM `functional_group`"; - -const std::string kDeleteDeviceConsent = - "DELETE FROM `device_consent_group` " - "WHERE `device_id` = ? "; - -const std::string kDeleteAppConsent = - "DELETE FROM `consent_group` " - "WHERE `device_id` = ? "; - -const std::string kSelectApplicationIsPreData = - "SELECT `is_predata` FROM `application` WHERE `id` = ? "; - -const std::string kUpdateIsPredata = - "UPDATE `application` SET `is_predata` = ? WHERE `id` = ? "; - -const std::string kHasAppPreloadedGroups = - "SELECT COUNT(`a1`.`functional_group_id`) FROM `app_group` " - " AS `a1` JOIN `app_group` AS `a2` " - " ON `a1`.`functional_group_id` = `a2`.`functional_group_id` " - " WHERE `a1`.`application_id` = ? AND `a2`.`application_id` = ? "; - -const std::string kUpdateUnpairedDevice = - "UPDATE `device` SET `unpaired` = ? WHERE `id` = ? "; - -const std::string kSelectUnpairedDevices = - "SELECT `id` FROM `device` WHERE `unpaired` = 1"; - -const std::string kHasMsgLanguageCode = - "SELECT COUNT (`id`) FROM message " - "WHERE `message_type_name` = ? AND `language_code` = ? "; - -const std::string kDeletePreconsentedGroupsByApplicationId = - "DELETE FROM `preconsented_group` WHERE `application_id` = ?"; - -} // namespace sql_pt_ext -} // namespace policy diff --git a/src/components/policy/policy_regular/src/sql_pt_ext_representation.cc b/src/components/policy/policy_regular/src/sql_pt_ext_representation.cc deleted file mode 100644 index c64efaaede..0000000000 --- a/src/components/policy/policy_regular/src/sql_pt_ext_representation.cc +++ /dev/null @@ -1,1807 +0,0 @@ -/* - Copyright (c) 2015, Ford Motor Company - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following - disclaimer in the documentation and/or other materials provided with the - distribution. - - Neither the name of the Ford Motor Company nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - */ -#include <algorithm> -#include <utility> -#include "utils/logger.h" -#include "policy/sql_pt_ext_representation.h" -#include "policy/sql_wrapper.h" -#include "policy/sql_pt_queries.h" -#include "policy/sql_pt_ext_queries.h" -#include "policy/policy_helper.h" -#include "policy/cache_manager.h" - -namespace policy { - -CREATE_LOGGERPTR_GLOBAL(logger_, "Policy") - -bool SQLPTExtRepresentation::CanAppKeepContext(const std::string& app_id) { - utils::dbms::SQLQuery query(db()); - if (query.Prepare(sql_pt_ext::kSelectKeepContext)) { - query.Bind(0, app_id); - if (query.Exec()) { - return query.GetBoolean(0); - } - } - return false; -} - -bool SQLPTExtRepresentation::CanAppStealFocus(const std::string& app_id) { - utils::dbms::SQLQuery query(db()); - if (query.Prepare(sql_pt_ext::kSelectStealFocus)) { - query.Bind(0, app_id); - if (query.Exec()) { - return query.GetBoolean(0); - } - } - return false; -} - -bool SQLPTExtRepresentation::ResetUserConsent() { - return ResetDeviceConsents() && ResetAppConsents(); -} - -bool SQLPTExtRepresentation::ResetDeviceConsents() { - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kResetDeviceConsents)) { - LOG4CXX_WARN(logger_, "Incorrect delete statement from device_consents."); - return false; - } - return query.Exec(); -} - -bool SQLPTExtRepresentation::ResetAppConsents() { - return utils::dbms::SQLQuery(db()).Exec(sql_pt_ext::kResetAppConsents); -} - -bool SQLPTExtRepresentation::GetUserPermissionsForDevice( - const std::string& device_id, - StringArray* consented_groups, - StringArray* disallowed_groups) { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kSelectDeviceConsentedGroup)) { - LOG4CXX_WARN(logger_, "Incorrect select from device consented groups"); - return false; - } - query.Bind(0, device_id); - while (query.Next()) { - if (query.GetBoolean(2)) { - if (!consented_groups) { - continue; - } - consented_groups->push_back(query.GetString(1)); - } else { - if (!disallowed_groups) { - continue; - } - disallowed_groups->push_back(query.GetString(1)); - } - } - - return true; -} - -bool SQLPTExtRepresentation::GetPermissionsForApp( - const std::string& device_id, - const std::string& policy_app_id, - FunctionalIdType* group_types) { - LOG4CXX_AUTO_TRACE(logger_); - if (!group_types) { - LOG4CXX_WARN(logger_, "Input parameter for group types is null."); - return false; - } - // Get all app groups for specified device and application - FunctionalGroupIDs all_groups; - if (!GetAllAppGroups(policy_app_id, all_groups)) { - return false; - } - // Get preconsented group - FunctionalGroupIDs preconsented_groups; - if (!GetPreconsentedGroups(policy_app_id, preconsented_groups)) { - return false; - } - // Get consented (allowed/disallowed) groups - FunctionalGroupIDs allowed_groups; - FunctionalGroupIDs disallowed_groups; - if (!GetConsentedGroups( - policy_app_id, device_id, allowed_groups, disallowed_groups)) { - return false; - } - // Get all default groups - FunctionalGroupIDs default_groups; - if (!GetAllAppGroups(kDefaultId, default_groups)) { - return false; - } - - // Get all pre_DataConsent groups - FunctionalGroupIDs predataconsented_groups; - if (!GetAllAppGroups(kPreDataConsentId, predataconsented_groups)) { - return false; - } - - // Get all device groups - FunctionalGroupIDs device_groups; - if (!GetAllAppGroups(kDeviceId, device_groups)) { - return false; - } - - (*group_types)[kTypeDefault] = default_groups; - (*group_types)[kTypeAllowed] = allowed_groups; - (*group_types)[kTypeDisallowed] = disallowed_groups; - (*group_types)[kTypePreconsented] = preconsented_groups; - (*group_types)[kTypeGeneral] = all_groups; - (*group_types)[kTypePreDataConsented] = predataconsented_groups; - (*group_types)[kTypeDevice] = device_groups; - - return true; -} - -bool SQLPTExtRepresentation::GetDeviceGroupsFromPolicies( - policy_table::Strings* groups, policy_table::Strings* preconsented_groups) { - LOG4CXX_AUTO_TRACE(logger_); - if (groups) { - GatherAppGroup(kDeviceId, groups); - } - if (preconsented_groups) { - GatherPreconsentedGroup(kDeviceId, preconsented_groups); - } - return true; -} - -bool SQLPTExtRepresentation::SetDeviceData(const std::string& device_id, - const std::string& hardware, - const std::string& firmware, - const std::string& os, - const std::string& os_version, - const std::string& carrier, - const uint32_t number_of_ports, - const std::string& connection_type) { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery count_query(db()); - if (!count_query.Prepare(sql_pt_ext::kCountDevice)) { - LOG4CXX_WARN(logger_, "Incorrect statement for count of device."); - return false; - } - - count_query.Bind(0, device_id); - - if (!count_query.Exec()) { - LOG4CXX_WARN(logger_, "Incorrect count of device."); - return false; - } - - bool update = count_query.GetInteger(0); - - // Update old value - if (update) { - utils::dbms::SQLQuery update_query(db()); - if (!update_query.Prepare(sql_pt_ext::kUpdateDevice)) { - LOG4CXX_WARN(logger_, "Incorrect statement for udpate device."); - return false; - } - - update_query.Bind(0, hardware); - update_query.Bind(1, firmware); - update_query.Bind(2, os); - update_query.Bind(3, os_version); - update_query.Bind(4, carrier); - update_query.Bind(5, static_cast<int>(number_of_ports)); - update_query.Bind(6, device_id); - update_query.Bind(7, connection_type); - - if (!update_query.Exec() || !update_query.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect update for device."); - return false; - } - - return true; - } - - // Insert new data - utils::dbms::SQLQuery insert_query(db()); - if (!insert_query.Prepare(sql_pt_ext::kInsertDevice)) { - LOG4CXX_WARN(logger_, "Incorrect insert statement for device."); - return false; - } - - insert_query.Bind(0, device_id); - insert_query.Bind(1, hardware); - insert_query.Bind(2, firmware); - insert_query.Bind(3, os); - insert_query.Bind(4, os_version); - insert_query.Bind(5, carrier); - insert_query.Bind(6, static_cast<int>(number_of_ports)); - insert_query.Bind(7, connection_type); - - if (!insert_query.Exec() || !insert_query.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect insert to device."); - return false; - } - - SetPreloaded(false); - - return true; -} - -bool SQLPTExtRepresentation::SetUserPermissionsForDevice( - const std::string& device_id, - const StringArray& consented_groups, - const StringArray& disallowed_groups) { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery count_query(db()); - if (!count_query.Prepare(sql_pt_ext::kCountDeviceConsentGroup)) { - LOG4CXX_WARN(logger_, "Incorrect count of device consented groups"); - return false; - } - - count_query.Bind(0, device_id); - - if (!count_query.Exec()) { - LOG4CXX_WARN(logger_, "Failed count of device consented groups"); - return false; - } - - bool update = count_query.GetInteger(0); - - // TODO(AOleynik): Split to several methods? - utils::dbms::SQLQuery query(db()); - // Update old values - if (update) { - if (!query.Prepare(sql_pt_ext::kUpdateDeviceConsentedGroup)) { - LOG4CXX_WARN( - logger_, - "Incorrect statement for updating consented groups on device"); - return false; - } - - StringArray::const_iterator it_consented_groups = consented_groups.begin(); - StringArray::const_iterator it_consented_groups_end = - consented_groups.end(); - for (; it_consented_groups != it_consented_groups_end; - ++it_consented_groups) { - query.Bind(0, true); - query.Bind(1, std::string("GUI")); - query.Bind(2, device_id); - query.Bind(3, *it_consented_groups); - // TODO(AOleynik): Get this info from external data - if (!query.Exec() || !query.Reset()) { - LOG4CXX_WARN(logger_, - "Failed update of device allowed consented groups."); - return false; - } - } - - StringArray::const_iterator it_disallowed_groups = - disallowed_groups.begin(); - StringArray::const_iterator it_disallowed_groups_end = - disallowed_groups.end(); - for (; it_disallowed_groups != it_disallowed_groups_end; - ++it_disallowed_groups) { - query.Bind(0, false); - query.Bind(1); - query.Bind(2, device_id); - query.Bind(3, *it_disallowed_groups); - if (!query.Exec() || !query.Reset()) { - LOG4CXX_WARN(logger_, - "Failed update of device disallowed consented groups."); - return false; - } - } - - return true; - } - - // Insert new values - if (!query.Prepare(sql_pt_ext::kInsertDeviceConsentedGroup)) { - LOG4CXX_WARN(logger_, - "Incorrect statement of inserting to device consented groups"); - return false; - } - - StringArray::const_iterator it_consented_groups = consented_groups.begin(); - StringArray::const_iterator it_consented_groups_end = consented_groups.end(); - for (; it_consented_groups != it_consented_groups_end; - ++it_consented_groups) { - query.Bind(0, device_id); - query.Bind(1, *it_consented_groups); - query.Bind(2, true); - // TODO(AOleynik): Get this info from external data - query.Bind(3, std::string("GUI")); - if (!query.Exec() || !query.Reset()) { - LOG4CXX_WARN(logger_, - "Failed insert to device allowed consented groups."); - return false; - } - } - - StringArray::const_iterator it_disallowed_groups = disallowed_groups.begin(); - StringArray::const_iterator it_disallowed_groups_end = - disallowed_groups.end(); - for (; it_disallowed_groups != it_disallowed_groups_end; - ++it_disallowed_groups) { - query.Bind(0, device_id); - query.Bind(1, *it_disallowed_groups); - query.Bind(2, false); - query.Bind(3); - if (!query.Exec() || !query.Reset()) { - LOG4CXX_WARN(logger_, - "Failed insert to device disallowed consented groups."); - return false; - } - } - - return true; -} - -bool SQLPTExtRepresentation::ReactOnUserDevConsentForApp( - const std::string& app_id, bool is_device_allowed) { - bool result = true; - if (is_device_allowed) { - // If app has pre_DataConsented groups it should be 'promoted' to default - // If app has only pre_DataConsented flag it should be only set to false and - // all groups get restored automatically - if (IsPredataPolicy(app_id)) { - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kHasAppPreloadedGroups)) { - LOG4CXX_WARN(logger_, - "Incorrect statement for has app preloaded groups"); - return false; - } - query.Bind(0, app_id); - query.Bind(1, kPreDataConsentId); - if (!query.Exec()) { - LOG4CXX_WARN(logger_, - "Incorrect select for app has predataconsted groups"); - return false; - } - if (query.GetInteger(0) > 0) { - result = result && SetDefaultPolicy(app_id); - } else { - result = result && SetIsPredata(app_id, false); - } - } - } else { - // If app has default groups change them to pre_DataConsented - // If app has 'normal' groups leave them as is and set - // pre_DataConsented flag to true. - if (IsDefaultPolicy(app_id)) { - result = result && SetPredataPolicy(app_id); - } else { - result = result && SetIsPredata(app_id, true); - } - } - return result; -} - -bool SQLPTExtRepresentation::SetUserPermissionsForApp( - const PermissionConsent& permissions) { - LOG4CXX_AUTO_TRACE(logger_); - // TODO(AOleynik): Handle situation, when no application was specified, i.e. - // general permissions were set - std::vector<FunctionalGroupPermission>::const_iterator it = - permissions.group_permissions.begin(); - std::vector<FunctionalGroupPermission>::const_iterator it_end = - permissions.group_permissions.end(); - - utils::dbms::SQLQuery query(db()); - for (; it != it_end; ++it) { - utils::dbms::SQLQuery counter(db()); - if (!counter.Prepare(sql_pt_ext::kCountAppConsents)) { - LOG4CXX_WARN(logger_, "Incorrect statement for consent group count."); - return false; - } - - counter.Bind(0, permissions.device_id); - counter.Bind(1, permissions.policy_app_id); - counter.Bind(2, static_cast<int>((*it).group_id)); - if (!counter.Exec()) { - LOG4CXX_WARN(logger_, "Incorrent count on consent groups."); - return false; - } - - bool update_required = counter.GetInteger(0); - - // Update already present consent record - if (update_required) { - if (!query.Prepare(sql_pt_ext::kUpdateGroupPermissions)) { - LOG4CXX_WARN(logger_, "Incorrect statement for update consent groups."); - return false; - } - - // Skip consent saving, if user didn't choose any state - if (policy::kGroupUndefined == (*it).state) { - continue; - } - query.Bind(0, (*it).state == kGroupAllowed ? 1 : 0); - query.Bind(1, permissions.consent_source); - query.Bind(2, permissions.policy_app_id); - query.Bind(3, static_cast<int>((*it).group_id)); - query.Bind(4, permissions.device_id); - - if (!query.Exec() || !query.Reset()) { - LOG4CXX_WARN(logger_, - "Incorrect update on user defined permissions " - "for app groups."); - return false; - } - continue; - } - - // Insert new consent record - if (!query.Prepare(sql_pt_ext::kInsertConsentGroups)) { - LOG4CXX_WARN(logger_, - "Incorrect statement for update app group permissions."); - return false; - } - - // Skip consent saving, if user didn't choose any state - if (policy::kGroupUndefined == (*it).state) { - continue; - } - query.Bind(0, permissions.device_id); - query.Bind(1, permissions.policy_app_id); - query.Bind(2, static_cast<int>((*it).group_id)); - query.Bind(3, (*it).state == kGroupAllowed ? 1 : 0); - query.Bind(4, permissions.consent_source); - - if (!query.Exec() || !query.Reset()) { - LOG4CXX_WARN(logger_, - "Incorrect insert to user defined permissions " - "for app groups."); - return false; - } - continue; - } - return true; -} - -std::vector<UserFriendlyMessage> SQLPTExtRepresentation::GetUserFriendlyMsg( - const std::vector<std::string>& msg_codes, const std::string& language) { - utils::dbms::SQLQuery query(db()); - std::vector<UserFriendlyMessage> result; - if (!query.Prepare(sql_pt_ext::kSelectFriendlyMsg)) { - LOG4CXX_WARN(logger_, "Incorrect statement for select friendly messages."); - return result; - } - - const std::string fallback_language = "en-us"; - std::vector<std::string>::const_iterator it = msg_codes.begin(); - std::vector<std::string>::const_iterator it_end = msg_codes.end(); - for (; it != it_end; ++it) { - std::string msg_language = language; - // If message has no records with required language, fallback language - // should be used instead. - if (!IsMsgLanguagePresent((*it), language)) { - msg_language = fallback_language; - } - query.Bind(0, *it); - query.Bind(1, msg_language); - - if (!query.Exec() || !query.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect select from friendly messages."); - return result; - } - - UserFriendlyMessage msg; - - msg.message_code = *it; - msg.tts = query.GetString(0); - msg.label = query.GetString(1); - msg.line1 = query.GetString(2); - msg.line2 = query.GetString(3); - msg.text_body = query.GetString(4); - - result.push_back(msg); - - if (!query.Reset()) { - LOG4CXX_WARN(logger_, - "Failed reset statement for selecting friendly " - "messages."); - return result; - } - } - - return result; -} - -bool SQLPTExtRepresentation::GatherConsumerFriendlyMessages( - policy_table::ConsumerFriendlyMessages* messages) const { - if (NULL == messages) { - LOG4CXX_ERROR(logger_, "NULL pointer has been passed to fill"); - return false; - } - - if (!SQLPTRepresentation::GatherConsumerFriendlyMessages(messages)) { - return false; - } - - utils::dbms::SQLQuery query(db()); - bool result = query.Prepare(sql_pt_ext::kCollectFriendlyMsg); - - if (result) { - while (query.Next()) { - UserFriendlyMessage msg; - - msg.tts = query.GetString(1); - msg.label = query.GetString(2); - msg.line1 = query.GetString(3); - msg.line2 = query.GetString(4); - msg.text_body = query.GetString(5); - msg.message_code = query.GetString(7); - - std::string language = query.GetString(6); - - *(*messages->messages)[msg.message_code].languages[language].tts = - msg.tts; - *(*messages->messages)[msg.message_code].languages[language].label = - msg.label; - *(*messages->messages)[msg.message_code].languages[language].line1 = - msg.line1; - *(*messages->messages)[msg.message_code].languages[language].line2 = - msg.line2; - *(*messages->messages)[msg.message_code].languages[language].textBody = - msg.text_body; - } - } else { - LOG4CXX_WARN(logger_, "Incorrect statement for select friendly messages."); - } - return result; -} - -bool SQLPTExtRepresentation::SetMetaInfo(const std::string& ccpu_version, - const std::string& wers_country_code, - const std::string& language) { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kUpdateMetaParams)) { - LOG4CXX_WARN(logger_, "Incorrect statement for insert to module meta."); - return false; - } - - query.Bind(0, ccpu_version); - query.Bind(1, wers_country_code); - query.Bind(2, language); - - if (!query.Exec() || !query.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect insert to module meta."); - return false; - } - return true; -} - -bool SQLPTExtRepresentation::IsMetaInfoPresent() { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kSelectMetaParams)) { - LOG4CXX_WARN(logger_, "Incorrect statement for selecting meta info."); - return false; - } - - if (!query.Exec()) { - LOG4CXX_WARN(logger_, "Incorrect select from module meta."); - return false; - } - - return !query.IsNull(0) && !query.IsNull(1) && !query.IsNull(2); -} - -bool SQLPTExtRepresentation::SetSystemLanguage(const std::string& language) { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kUpdateMetaLanguage)) { - LOG4CXX_WARN(logger_, "Incorrect statement for update meta language."); - return false; - } - - query.Bind(0, language); - - if (!query.Exec()) { - LOG4CXX_WARN(logger_, "Incorrect update for meta language."); - return false; - } - - return true; -} - -bool SQLPTExtRepresentation::SaveApplicationPoliciesSection( - const policy_table::ApplicationPoliciesSection& policies) { - LOG4CXX_INFO(logger_, "SaveApplicationPolicies ext"); - utils::dbms::SQLQuery query_delete(db()); - if (!query_delete.Exec(sql_pt::kDeleteAppGroup)) { - LOG4CXX_WARN(logger_, "Incorrect delete from app_group."); - return false; - } - - utils::dbms::SQLQuery query_delete_preconsented(db()); - if (!query_delete_preconsented.Exec(sql_pt_ext::kDeletePreconsentedGroups)) { - LOG4CXX_WARN(logger_, "Incorrect delete from preconsented_group."); - return false; - } - - if (!query_delete.Exec(sql_pt::kDeleteApplication)) { - LOG4CXX_WARN(logger_, "Incorrect delete from application."); - return false; - } - - if (!query_delete.Exec(sql_pt::kDeleteRequestType)) { - LOG4CXX_WARN(logger_, "Incorrect delete from request type."); - return false; - } - - // First, all predefined apps (e.g. default, pre_DataConsent) should be saved, - // otherwise another app with the predefined permissions can get incorrect - // permissions - policy_table::ApplicationPolicies::const_iterator it_default = - policies.apps.find(kDefaultId); - if (policies.apps.end() != it_default) { - if (!SaveSpecificAppPolicy(*it_default)) { - return false; - } - } - policy_table::ApplicationPolicies::const_iterator it_pre_data_consent = - policies.apps.find(kPreDataConsentId); - if (policies.apps.end() != it_pre_data_consent) { - if (!SaveSpecificAppPolicy(*it_pre_data_consent)) { - return false; - } - } - - if (!SaveDevicePolicy(policies.device)) { - return false; - } - - policy_table::ApplicationPolicies::const_iterator it; - for (it = policies.apps.begin(); it != policies.apps.end(); ++it) { - // Skip saving of predefined app, since they should be saved before - if (IsPredefinedApp(*it)) { - continue; - } - if (!SaveSpecificAppPolicy(*it)) { - return false; - } - } - - return true; -} - -bool SQLPTExtRepresentation::SaveSpecificAppPolicy( - const policy_table::ApplicationPolicies::value_type& app) { - if (app.second.is_string()) { - if (kDefaultId.compare(app.second.get_string()) == 0) { - if (!SetDefaultPolicy(app.first)) { - return false; - } - if (!SaveRequestType(app.first, *app.second.RequestType)) { - return false; - } - } else if (kPreDataConsentId.compare(app.second.get_string()) == 0) { - if (!SetPredataPolicy(app.first)) { - return false; - } - if (!SaveRequestType(app.first, *app.second.RequestType)) { - return false; - } - } - - // Stop saving other params, since predefined permissions already set - return true; - } - - SetIsDefault(app.first, false); - SetIsPredata(app.first, false); - - utils::dbms::SQLQuery app_query(db()); - if (!app_query.Prepare(sql_pt_ext::kInsertApplication)) { - LOG4CXX_WARN(logger_, "Incorrect insert statement into application."); - return false; - } - - app_query.Bind(0, app.first); - app_query.Bind(1, app.second.keep_context); - app_query.Bind(2, app.second.steal_focus); - app_query.Bind( - 3, std::string(policy_table::EnumToJsonString(app.second.default_hmi))); - app_query.Bind( - 4, std::string(policy_table::EnumToJsonString(app.second.priority))); - 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, std::string()); - - if (!app_query.Exec() || !app_query.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect insert into application."); - return false; - } - - 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; - } - // TODO(IKozyrenko): Check logic if optional container is missing - if (!SavePreconsentedGroup(app.first, *app.second.preconsented_groups)) { - return false; - } - - return true; -} - -bool policy::SQLPTExtRepresentation::SaveDevicePolicy( - const policy_table::DevicePolicy& device) { - dbms::SQLQuery app_query(db()); - if (!app_query.Prepare(sql_pt_ext::kInsertApplication)) { - LOG4CXX_WARN(logger_, - "Incorrect insert statement into application (device)."); - return false; - } - app_query.Bind(0, kDeviceId); - app_query.Bind(1, device.keep_context); - app_query.Bind(2, device.steal_focus); - app_query.Bind( - 3, std::string(policy_table::EnumToJsonString(device.default_hmi))); - app_query.Bind(4, - std::string(policy_table::EnumToJsonString(device.priority))); - app_query.Bind(5, false); - app_query.Bind(6, 0); - app_query.Bind(7, 0); - app_query.Bind(8, std::string()); - - if (!app_query.Exec() || !app_query.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect insert into application."); - return false; - } - - if (!SaveAppGroup(kDeviceId, device.groups)) { - return false; - } - if (!SavePreconsentedGroup(kDeviceId, *device.preconsented_groups)) { - return false; - } - - return true; -} - -bool SQLPTExtRepresentation::GatherApplicationPoliciesSection( - policy_table::ApplicationPoliciesSection* policies) const { - LOG4CXX_INFO(logger_, "Gather applications policies"); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kSelectAppPolicies)) { - LOG4CXX_WARN(logger_, "Incorrect select from app_policies"); - return false; - } - - while (query.Next()) { - rpc::Nullable<policy_table::ApplicationParams> params; - const std::string& app_id = query.GetString(0); - if (IsApplicationRevoked(app_id)) { - params.set_to_null(); - (*policies).apps[app_id] = params; - continue; - } - if (IsDefaultPolicy(app_id)) { - (*policies).apps[app_id].set_to_string(kDefaultId); - } - if (IsPredataPolicy(app_id)) { - (*policies).apps[app_id].set_to_string(kPreDataConsentId); - } - if (kDeviceId == app_id) { - policy_table::DevicePolicy device_policy; - policy_table::Priority priority; - policy_table::EnumFromJsonString(query.GetString(1), &priority); - device_policy.priority = priority; - policy_table::HmiLevel hmi; - policy_table::EnumFromJsonString(query.GetString(2), &hmi); - device_policy.default_hmi = hmi; - device_policy.keep_context = query.GetBoolean(3); - device_policy.steal_focus = query.GetBoolean(4); - if (!GatherAppGroup(app_id, &device_policy.groups)) { - return false; - } - GatherPreconsentedGroup(app_id, &*device_policy.preconsented_groups); - (*policies).device = device_policy; - continue; - } - policy_table::Priority priority; - policy_table::EnumFromJsonString(query.GetString(1), &priority); - params.priority = priority; - policy_table::HmiLevel hmi; - policy_table::EnumFromJsonString(query.GetString(2), &hmi); - params.default_hmi = hmi; - params.keep_context = query.GetBoolean(3); - 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); - } - if (!GatherAppGroup(app_id, ¶ms.groups)) { - return false; - } - if (!GatherNickName(app_id, &*params.nicknames)) { - return false; - } - if (!GatherAppType(app_id, &*params.AppHMIType)) { - return false; - } - if (!GatherRequestType(app_id, &*params.RequestType)) { - return false; - } - GatherPreconsentedGroup(app_id, &*params.preconsented_groups); - (*policies).apps[app_id] = params; - } - return true; -} - -void SQLPTExtRepresentation::GatherPreconsentedGroup( - const std::string& app_id, policy_table::Strings* groups) const { - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kSelectPreconsentedGroups)) { - LOG4CXX_WARN(logger_, "Incorrect select from preconsented group"); - return; - } - - query.Bind(0, app_id); - while (query.Next()) { - groups->push_back(query.GetString(0)); - } -} - -bool SQLPTExtRepresentation::GatherUsageAndErrorCounts( - policy_table::UsageAndErrorCounts* counts) const { - LOG4CXX_INFO(logger_, "Gather Usage and Error Counts."); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kSelectUsageAndErrorCount) || !query.Exec()) { - LOG4CXX_INFO(logger_, "Failed select from user_and_error_count"); - return false; - } - - *counts->count_of_iap_buffer_full = query.GetInteger(0); - *counts->count_sync_out_of_memory = query.GetInteger(1); - *counts->count_of_sync_reboots = query.GetInteger(2); - - return GatherAppLevels(&*counts->app_level); -} - -bool SQLPTExtRepresentation::GatherAppLevels( - policy_table::AppLevels* apps) const { - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kSelectAppLevels)) { - LOG4CXX_INFO(logger_, - "Failed select from app_level. SQLError = " - << query.LastError().text()); - return false; - } - while (query.Next()) { - policy_table::AppLevel level; - // value of time fields database is seconds - level.minutes_in_hmi_full = query.GetInteger(1); - level.minutes_in_hmi_limited = query.GetInteger(2); - level.minutes_in_hmi_background = query.GetInteger(3); - level.minutes_in_hmi_none = query.GetInteger(4); - level.count_of_user_selections = query.GetInteger(5); - level.count_of_rejections_sync_out_of_memory = query.GetInteger(6); - level.count_of_rejections_nickname_mismatch = query.GetInteger(7); - level.count_of_rejections_duplicate_name = query.GetInteger(8); - level.count_of_rejected_rpc_calls = query.GetInteger(9); - level.count_of_rpcs_sent_in_hmi_none = query.GetInteger(10); - level.count_of_removals_for_bad_behavior = query.GetInteger(11); - level.count_of_run_attempts_while_revoked = query.GetInteger(12); - level.app_registration_language_gui = query.GetString(13); - level.app_registration_language_vui = query.GetString(14); - level.count_of_tls_errors = query.GetInteger(15); - (*apps)[query.GetString(0)] = level; - } - - return true; -} - -void SQLPTExtRepresentation::GatherDeviceData( - policy_table::DeviceData* data) const { - LOG4CXX_INFO(logger_, "Gather device data."); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kSelectDeviceData)) { - LOG4CXX_WARN(logger_, "Incorrect select statement for device data."); - return; - } - data->mark_initialized(); - while (query.Next()) { - policy_table::DeviceParams* specific_device = &(*data)[query.GetString(0)]; - *specific_device->hardware = query.GetString(1); - *specific_device->firmware_rev = query.GetString(2); - *specific_device->os = query.GetString(3); - *specific_device->os_version = query.GetString(4); - *specific_device->carrier = query.GetString(5); - *specific_device->max_number_rfcom_ports = query.GetInteger(6); - - // TODO(IKozyrenko): Check logic if optional container is missing - GatherConsentGroup(query.GetString(0), - &(*specific_device->user_consent_records)); - } -} - -void SQLPTExtRepresentation::GatherConsentGroup( - const std::string& device_id, - policy_table::UserConsentRecords* records) const { - LOG4CXX_INFO(logger_, "Gather consent records."); - utils::dbms::SQLQuery query(db()); - // Fill data for device - if (!query.Prepare(sql_pt_ext::kSelectDeviceConsentedGroup)) { - LOG4CXX_WARN(logger_, - "Incorrect select statement for device consented groups."); - return; - } - - query.Bind(0, device_id); - - // Fill device_data -> user_consent_records -> "device" - while (query.Next()) { - policy_table::ConsentRecords* device_consent_records = - &(*records)[kDeviceId]; - // TODO(IKozyrenko): Check logic if optional container is missing - policy_table::ConsentGroups& consent_groups = - *device_consent_records->consent_groups; - consent_groups[query.GetString(1)] = query.GetBoolean(2); - policy_table::Input input; - policy_table::EnumFromJsonString(query.GetString(3), &input); - *device_consent_records->input = input; - *device_consent_records->time_stamp = query.GetString(4); - } - - if (!query.Reset()) { - return; - } - - // Fill data for applications - if (!query.Prepare(sql_pt_ext::kSelectConsentGroup)) { - LOG4CXX_WARN(logger_, - "Incorrect select statement for app consented groups."); - return; - } - - query.Bind(0, device_id); - - // Fill device_data -> user_consent_records -> <app_id> - while (query.Next()) { - policy_table::ConsentRecords* app_consent_records = - &(*records)[query.GetString(1)]; - // TODO(IKozyrenko): Check logic if optional container is missing - policy_table::ConsentGroups& consent_groups = - *app_consent_records->consent_groups; - - consent_groups[query.GetString(2)] = query.GetBoolean(3); - policy_table::Input input; - policy_table::EnumFromJsonString(query.GetString(4), &input); - *app_consent_records->input = input; - *app_consent_records->time_stamp = query.GetString(5); - } -} - -bool SQLPTExtRepresentation::SaveDeviceData( - const policy_table::DeviceData& devices) { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery drop_device_query(db()); - const std::string drop_device = "DELETE FROM `device`"; - if (!drop_device_query.Exec(drop_device)) { - LOG4CXX_WARN(logger_, "Could not clear device table."); - return false; - } - - utils::dbms::SQLQuery drop_device_consents_query(db()); - const std::string drop_device_consents = "DELETE FROM `device_consent_group`"; - if (!drop_device_consents_query.Exec(drop_device_consents)) { - LOG4CXX_WARN(logger_, "Could not clear device consents."); - return false; - } - - utils::dbms::SQLQuery drop_user_consents_query(db()); - const std::string drop_user_consents = "DELETE FROM `consent_group`"; - if (!drop_user_consents_query.Exec(drop_user_consents)) { - LOG4CXX_WARN(logger_, "Could not clear user consents."); - return false; - } - - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kInsertDeviceData)) { - LOG4CXX_WARN(logger_, "Incorrect insert statement for device data."); - return false; - } - - policy_table::DeviceData::const_iterator it = devices.begin(); - policy_table::DeviceData::const_iterator it_end = devices.end(); - for (; it != it_end; ++it) { - query.Bind(0, it->first); - query.Bind(1, *(it->second.hardware)); - query.Bind(2, *(it->second.firmware_rev)); - query.Bind(3, *(it->second.os)); - query.Bind(4, *(it->second.os_version)); - query.Bind(5, *(it->second.carrier)); - query.Bind(6, *(it->second.max_number_rfcom_ports)); - query.Bind(7, *(it->second.connection_type)); - - if (!query.Exec() || !query.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect insert into device data."); - return false; - } - - // TODO(IKozyrenko): Check logic if optional container is missing - if (!SaveConsentGroup(it->first, *it->second.user_consent_records)) { - return false; - } - } - - return true; -} - -bool SQLPTExtRepresentation::SaveConsentGroup( - const std::string& device_id, - const policy_table::UserConsentRecords& records) { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery query(db()); - - policy_table::UserConsentRecords::const_iterator it = records.begin(); - policy_table::UserConsentRecords::const_iterator it_end = records.end(); - for (; it != it_end; ++it) { - // TODO(IKozyrenko): Check logic if optional container is missing - policy_table::ConsentGroups::const_iterator it_groups = - it->second.consent_groups->begin(); - policy_table::ConsentGroups::const_iterator it_groups_end = - it->second.consent_groups->end(); - for (; it_groups != it_groups_end; ++it_groups) { - if (kDeviceId == it->first) { - if (!query.Prepare(sql_pt_ext::kInsertDeviceConsentedGroup)) { - LOG4CXX_WARN(logger_, - "Incorrect insert statement for device consent group."); - return false; - } - query.Bind(0, device_id); - query.Bind(1, it_groups->first); - query.Bind(2, it_groups->second); - query.Bind( - 3, - std::string(policy_table::EnumToJsonString(*(it->second.input)))); - query.Bind(4, std::string(*(it->second.time_stamp))); - LOG4CXX_INFO(logger_, - "Device:" - << "time stamp " - << std::string(*(it->second.time_stamp)) << " group " - << it_groups->first << " consent " - << it_groups->second); - } else { - if (!query.Prepare(sql_pt_ext::kInsertConsentGroups)) { - LOG4CXX_WARN(logger_, - "Incorrect insert statement for consent group."); - return false; - } - query.Bind(0, device_id); - query.Bind(1, it->first); - query.Bind(2, it_groups->first); - query.Bind(3, it_groups->second); - query.Bind( - 4, - std::string(policy_table::EnumToJsonString(*(it->second.input)))); - query.Bind(5, std::string(*(it->second.time_stamp))); - LOG4CXX_INFO(logger_, - "Device:" - << "time stamp " - << std::string(*(it->second.time_stamp)) << " group " - << it_groups->first << " consent " - << it_groups->second); - } - - if (!query.Exec() || !query.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect insert into consent group."); - return false; - } - } - } - - return true; -} - -bool SQLPTExtRepresentation::SavePreconsentedGroup( - const std::string& app_id, const policy_table::Strings& groups) { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kInsertPreconsentedGroups)) { - LOG4CXX_WARN(logger_, "Incorrect insert statement for preconsented groups"); - return false; - } - - policy_table::Strings::const_iterator it; - for (it = groups.begin(); it != groups.end(); ++it) { - query.Bind(0, app_id); - query.Bind(1, *it); - if (!query.Exec() || !query.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect insert into preconsented groups."); - return false; - } - } - - return true; -} - -void SQLPTExtRepresentation::GatherModuleMeta( - policy_table::ModuleMeta* meta) const { - LOG4CXX_INFO(logger_, "Gather Module Meta Info"); - utils::dbms::SQLQuery query(db()); - if (query.Prepare(sql_pt_ext::kSelectModuleMeta) && query.Next()) { - *meta->ccpu_version = query.GetString(0); - *meta->language = query.GetString(1); - *meta->wers_country_code = query.GetString(2); - *meta->pt_exchanged_at_odometer_x = query.GetInteger(3); - *meta->pt_exchanged_x_days_after_epoch = query.GetInteger(4); - *meta->ignition_cycles_since_last_exchange = query.GetInteger(5); - *meta->vin = query.GetString(6); - } -} - -void SQLPTExtRepresentation::Increment(const std::string& type) const { - utils::dbms::SQLQuery query(db()); - std::string update_counter = - "UPDATE `usage_and_error_count` SET `" + type + "` = `" + type + "` + 1"; - if (!query.Exec(update_counter)) { - LOG4CXX_INFO(logger_, "Failed updating global counter"); - } -} - -bool SQLPTExtRepresentation::IsExistAppLevel(const std::string& app_id) const { - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kCountAppLevel)) { - LOG4CXX_INFO(logger_, "Incorrect statement of count app_level"); - return false; - } - query.Bind(0, app_id); - if (!query.Exec()) { - LOG4CXX_INFO(logger_, "Failed count app_level"); - return false; - } - return query.GetInteger(0) > 0; -} - -bool SQLPTExtRepresentation::GetAllAppGroups(const std::string& policy_app_id, - FunctionalGroupIDs& all_groups) { - LOG4CXX_INFO(logger_, "GetAllAppGroups for '" << policy_app_id << "'"); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kSelectAppGroupsId)) { - LOG4CXX_WARN(logger_, "Incorrect statement for select app groups id."); - return false; - } - - query.Bind(0, policy_app_id); - - while (query.Next()) { - all_groups.push_back(query.GetInteger(0)); - } - - return true; -} - -bool SQLPTExtRepresentation::GetConsentedGroups( - const std::string& policy_app_id, - const std::string& device_id, - FunctionalGroupIDs& allowed_groups, - FunctionalGroupIDs& disallowed_groups) { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kSelectConsentedGroupsId)) { - LOG4CXX_WARN(logger_, "Incorrect statement for select consent groups id."); - return false; - } - - query.Bind(0, policy_app_id); - query.Bind(1, device_id); - - while (query.Next()) { - if (query.GetBoolean(1)) { - allowed_groups.push_back(query.GetInteger(0)); - } else { - disallowed_groups.push_back(query.GetInteger(0)); - } - } - - return true; -} - -bool SQLPTExtRepresentation::GetPreconsentedGroups( - const std::string& policy_app_id, FunctionalGroupIDs& preconsented_groups) { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kSelectPreconsentedGroupsId)) { - LOG4CXX_WARN(logger_, - "Incorrect statement for select preconsented groups id."); - return false; - } - - query.Bind(0, policy_app_id); - - while (query.Next()) { - preconsented_groups.push_back(query.GetInteger(0)); - } - - return true; -} - -bool SQLPTExtRepresentation::GetFunctionalGroupNames( - FunctionalGroupNames& names) { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kSelectFunctionalGroupNames)) { - LOG4CXX_WARN(logger_, - "Incorrect statement for select functional groups names."); - return false; - } - - while (query.Next()) { - // Some of functional grous doesn't have filled user_consent_prompt - if (query.IsNull(1)) { - names[query.GetInteger(0)] = - std::make_pair<std::string, std::string>("", query.GetString(2)); - } else { - names[query.GetInteger(0)] = std::make_pair<std::string, std::string>( - query.GetString(1), query.GetString(2)); - } - } - - return true; -} - -void SQLPTExtRepresentation::FillFunctionalGroupPermissions( - FunctionalGroupIDs& ids, - FunctionalGroupNames& names, - GroupConsent state, - std::vector<FunctionalGroupPermission>& permissions) { - FunctionalGroupIDs::const_iterator it = ids.begin(); - FunctionalGroupIDs::const_iterator it_end = ids.end(); - for (; it != it_end; ++it) { - FunctionalGroupPermission current_group; - current_group.group_id = *it; - current_group.group_alias = names[*it].first; - current_group.group_name = names[*it].second; - current_group.state = state; - permissions.push_back(current_group); - } -} - -void SQLPTExtRepresentation::Increment(const std::string& app_id, - const std::string& type) const { - utils::dbms::SQLQuery query(db()); - std::string sql_counter; - if (IsExistAppLevel(app_id)) { - // update - sql_counter = "UPDATE `app_level` SET `" + type + "` = `" + type + - "` + 1 WHERE `application_id` = ?"; - } else { - // insert - sql_counter = "INSERT INTO `app_level` (`application_id`, `" + type + - "`) " - "VALUES (?, 1)"; - } - if (!query.Prepare(sql_counter)) { - LOG4CXX_INFO(logger_, "Incorrect statement of update app counter"); - return; - } - query.Bind(0, app_id); - if (!query.Exec()) { - LOG4CXX_INFO(logger_, "Failed updating app counter"); - } -} - -void SQLPTExtRepresentation::Set(const std::string& app_id, - const std::string& type, - const std::string& value) const { - utils::dbms::SQLQuery query(db()); - std::string sql_info; - if (IsExistAppLevel(app_id)) { - // update - sql_info = "UPDATE `app_level` SET `" + type + - "` = ? " - "WHERE `application_id` = ?"; - } else { - // insert - sql_info = "INSERT INTO `app_level` (`" + type + - "`, `application_id`) " - "VALUES (?, ?)"; - } - if (!query.Prepare(sql_info)) { - LOG4CXX_INFO(logger_, "Incorrect statement of update app info"); - return; - } - query.Bind(0, value); - query.Bind(1, app_id); - if (!query.Exec()) { - LOG4CXX_INFO(logger_, "Failed updating app info"); - } -} - -void SQLPTExtRepresentation::Add(const std::string& app_id, - const std::string& type, - int seconds) const { - utils::dbms::SQLQuery query(db()); - std::string sql_stopwatch; - if (IsExistAppLevel(app_id)) { - // update - sql_stopwatch = "UPDATE `app_level` SET `" + type + "` = `" + type + - "` + ? WHERE `application_id` = ?"; - } else { - // insert - sql_stopwatch = "INSERT INTO `app_level` (`" + type + - "`, `application_id`) " - "VALUES (?, ?)"; - } - if (!query.Prepare(sql_stopwatch)) { - LOG4CXX_INFO(logger_, "Incorrect statement of update app stopwatch"); - return; - } - query.Bind(0, seconds); - query.Bind(1, app_id); - if (!query.Exec()) { - LOG4CXX_INFO(logger_, "Failed updating app stopwatch"); - } -} - -bool SQLPTExtRepresentation::GetDefaultHMI(const std::string& policy_app_id, - std::string* default_hmi) { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kSelectDefaultHmi)) { - LOG4CXX_INFO(logger_, "Incorrect statement for default hmi."); - return false; - } - - query.Bind(0, policy_app_id); - - if (!query.Exec()) { - LOG4CXX_INFO(logger_, "Error during default hmi getting."); - return false; - } - - if (query.IsNull(0)) { - default_hmi->clear(); - return true; - } - - default_hmi->assign(query.GetString(0)); - - return true; -} - -bool SQLPTExtRepresentation::CountUnconsentedGroups( - const std::string& policy_app_id, - const std::string& device_id, - int* result) const { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kCountUnconsentedGroups)) { - LOG4CXX_WARN(logger_, "Incorrect select for unconsented groups."); - return false; - } - - query.Bind(0, policy_app_id); - query.Bind(1, device_id); - query.Bind(2, kDefaultId); - query.Bind(3, kPreDataConsentId); - - if (!query.Exec()) { - LOG4CXX_INFO(logger_, "Error during executing unconsented groups."); - return false; - } - *result = query.GetInteger(0); - return true; -} - -bool SQLPTExtRepresentation::IsMsgLanguagePresent(const std::string& message, - const std::string& language) { - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kHasMsgLanguageCode)) { - LOG4CXX_WARN(logger_, "Incorrect statement for message language check."); - return false; - } - - query.Bind(0, message); - query.Bind(1, language); - - if (!query.Exec()) { - LOG4CXX_WARN(logger_, "Failed to check message language code."); - return false; - } - - return query.GetInteger(0) != 0; -} - -bool SQLPTExtRepresentation::SaveMessageString( - const std::string& type, - const std::string& lang, - const policy_table::MessageString& strings) { - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt::kInsertMessageString)) { - LOG4CXX_WARN(logger_, "Incorrect insert statement for message."); - return false; - } - - query.Bind(0, *strings.tts); - query.Bind(1, *strings.label); - query.Bind(2, *strings.line1); - query.Bind(3, *strings.line2); - query.Bind(4, lang); - query.Bind(5, type); - query.Bind(6, *strings.textBody); - - if (!query.Exec() || !query.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect insert into message."); - return false; - } - - return true; -} - -bool SQLPTExtRepresentation::SaveUsageAndErrorCounts( - const policy_table::UsageAndErrorCounts& counts) { - return SaveAppCounters(*counts.app_level) && SaveGlobalCounters(counts); -} - -bool SQLPTExtRepresentation::SaveModuleMeta( - const policy_table::ModuleMeta& meta) { - utils::dbms::SQLQuery query(db()); - - if (!query.Prepare(sql_pt_ext::kSaveModuleMeta)) { - LOG4CXX_WARN(logger_, "Incorrect insert statement for module_meta."); - return false; - } - const int64_t odometer = *(meta.pt_exchanged_at_odometer_x); - - query.Bind(0, *(meta.ccpu_version)); - query.Bind(1, *(meta.language)); - query.Bind(2, *(meta.wers_country_code)); - query.Bind(3, odometer); - query.Bind(4, *(meta.pt_exchanged_x_days_after_epoch)); - query.Bind(5, *(meta.ignition_cycles_since_last_exchange)); - query.Bind(6, *(meta.vin)); - - if (!query.Exec()) { - LOG4CXX_WARN(logger_, "Incorrect update for module_meta."); - return false; - } - - return true; -} - -bool SQLPTExtRepresentation::SaveAppCounters( - const rpc::policy_table_interface_base::AppLevels& app_levels) { - utils::dbms::SQLQuery query(db()); - if (!query.Exec(sql_pt::kDeleteAppLevel)) { - LOG4CXX_WARN(logger_, "Incorrect delete from app level."); - return false; - } - if (!query.Prepare(sql_pt::kInsertAppLevel)) { - LOG4CXX_WARN(logger_, "Incorrect insert statement for app level."); - return false; - } - - policy_table::AppLevels::const_iterator it; - for (it = app_levels.begin(); it != app_levels.end(); ++it) { - query.Bind(0, it->first); - query.Bind(1, it->second.minutes_in_hmi_full); - query.Bind(2, it->second.minutes_in_hmi_limited); - query.Bind(3, it->second.minutes_in_hmi_background); - query.Bind(4, it->second.minutes_in_hmi_none); - query.Bind(5, it->second.count_of_user_selections); - query.Bind(6, it->second.count_of_rejections_sync_out_of_memory); - query.Bind(7, it->second.count_of_rejections_nickname_mismatch); - query.Bind(8, it->second.count_of_rejections_duplicate_name); - query.Bind(9, it->second.count_of_rejected_rpc_calls); - query.Bind(10, it->second.count_of_rpcs_sent_in_hmi_none); - query.Bind(11, it->second.count_of_removals_for_bad_behavior); - query.Bind(12, it->second.count_of_run_attempts_while_revoked); - query.Bind(13, it->second.app_registration_language_gui); - query.Bind(14, it->second.app_registration_language_vui); - query.Bind(15, it->second.count_of_tls_errors); - - if (!query.Exec() || !query.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect insert into app level."); - return false; - } - } - return true; -} - -bool SQLPTExtRepresentation::SaveGlobalCounters( - const rpc::policy_table_interface_base::UsageAndErrorCounts& counts) { - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kUpdateGlobalCounters)) { - LOG4CXX_WARN(logger_, "Incorrect insert statement for global counters."); - return false; - } - - query.Bind(0, *counts.count_of_iap_buffer_full); - query.Bind(1, *counts.count_sync_out_of_memory); - query.Bind(2, *counts.count_of_sync_reboots); - - if (!query.Exec()) { - LOG4CXX_WARN(logger_, "Incorrect insert into global counters."); - return false; - } - - return true; -} - -bool SQLPTExtRepresentation::CleanupUnpairedDevices( - const DeviceIds& device_ids) const { - LOG4CXX_AUTO_TRACE(logger_); - utils::dbms::SQLQuery delete_device_query(db()); - if (!delete_device_query.Prepare(sql_pt::kDeleteDevice)) { - LOG4CXX_WARN(logger_, "Incorrect statement for device delete."); - return true; - } - - utils::dbms::SQLQuery delete_device_consent_query(db()); - if (!delete_device_consent_query.Prepare(sql_pt_ext::kDeleteDeviceConsent)) { - LOG4CXX_WARN(logger_, "Incorrect statement for delete device consent."); - return false; - } - - utils::dbms::SQLQuery delete_app_consent_query(db()); - if (!delete_app_consent_query.Prepare(sql_pt_ext::kDeleteAppConsent)) { - LOG4CXX_WARN(logger_, "Incorrect statement for delete app consent."); - return false; - } - - DeviceIds::const_iterator it = device_ids.begin(); - DeviceIds::const_iterator it_end = device_ids.end(); - for (; it != it_end; ++it) { - delete_device_query.Bind(0, (*it)); - if (!delete_device_query.Exec() || !delete_device_query.Reset()) { - LOG4CXX_WARN(logger_, "Failed to delete from device"); - return false; - } - - delete_device_consent_query.Bind(0, (*it)); - if (!delete_device_consent_query.Exec() || - !delete_device_consent_query.Reset()) { - LOG4CXX_WARN(logger_, "Failed to delete from device consent."); - return false; - } - - delete_app_consent_query.Bind(0, (*it)); - if (!delete_app_consent_query.Exec() || !delete_app_consent_query.Reset()) { - LOG4CXX_WARN(logger_, "Failed to delete from app consent."); - return false; - } - } - return true; -} - -bool SQLPTExtRepresentation::SetDefaultPolicy(const std::string& app_id) { - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt::kDeleteAppGroupByApplicationId)) { - LOG4CXX_ERROR(logger_, "Incorrect statement to delete from app_group."); - return false; - } - query.Bind(0, app_id); - if (!query.Exec()) { - LOG4CXX_ERROR(logger_, "Failed deleting from app_group."); - return false; - } - - if (!query.Prepare(sql_pt_ext::kDeletePreconsentedGroupsByApplicationId)) { - LOG4CXX_ERROR(logger_, "Incorrect statement to delete from app_group."); - return false; - } - query.Bind(0, app_id); - if (!query.Exec()) { - LOG4CXX_ERROR(logger_, "Failed deleting from app_group."); - return false; - } - - if (!CopyApplication(kDefaultId, app_id)) { - return false; - } - - SetPreloaded(false); - - policy_table::Strings default_groups; - policy_table::Strings default_preconsented_groups; - GatherAppGroup(kDefaultId, &default_groups); - GatherPreconsentedGroup(kDefaultId, &default_preconsented_groups); - if (SaveAppGroup(app_id, default_groups) && - SavePreconsentedGroup(app_id, default_preconsented_groups)) { - return SetIsDefault(app_id, true) && SetIsPredata(app_id, false); - } - - return false; -} - -bool SQLPTExtRepresentation::SetPredataPolicy(const std::string& app_id) { - LOG4CXX_INFO(logger_, - "SQLPTExtRepresentation::SetPredataPolicy for " << app_id); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt::kDeleteAppGroupByApplicationId)) { - LOG4CXX_ERROR(logger_, "Incorrect statement to delete from app_group."); - return false; - } - query.Bind(0, app_id); - if (!query.Exec()) { - LOG4CXX_ERROR(logger_, "Failed deleting from app_group."); - return false; - } - - if (!query.Prepare(sql_pt_ext::kDeletePreconsentedGroupsByApplicationId)) { - LOG4CXX_ERROR(logger_, "Incorrect statement to delete from app_group."); - return false; - } - query.Bind(0, app_id); - if (!query.Exec()) { - LOG4CXX_ERROR(logger_, "Failed deleting from app_group."); - return false; - } - - if (!CopyApplication(kPreDataConsentId, app_id)) { - return false; - } - - SetPreloaded(false); - - policy_table::Strings predataconsent_groups; - policy_table::Strings predataconsent_preconsented_groups; - GatherAppGroup(kPreDataConsentId, &predataconsent_groups); - GatherPreconsentedGroup(kPreDataConsentId, &predataconsent_groups); - if (SaveAppGroup(app_id, predataconsent_groups) && - SavePreconsentedGroup(app_id, predataconsent_groups)) { - return SetIsDefault(app_id, false) && SetIsPredata(app_id, true); - } - return false; -} - -bool SQLPTExtRepresentation::IsPredataPolicy(const std::string& app_id) const { - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kSelectApplicationIsPreData)) { - LOG4CXX_WARN(logger_, "Incorrect select application is pre_dataConsented"); - return false; - } - - query.Bind(0, app_id); - if (!query.Exec()) { - LOG4CXX_WARN(logger_, "Failed select application is pre_dataConsented"); - return false; - } - return query.IsNull(0) ? false : query.GetBoolean(0); -} - -bool SQLPTExtRepresentation::SetIsPredata(const std::string& app_id, - bool is_pre_data) { - LOG4CXX_TRACE(logger_, "Set flag is_predata of application"); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kUpdateIsPredata)) { - LOG4CXX_WARN(logger_, "Incorect statement for updating is_predata"); - return false; - } - - query.Bind(0, is_pre_data); - query.Bind(1, app_id); - if (!query.Exec()) { - LOG4CXX_WARN(logger_, "Failed update is_predata"); - return false; - } - return true; -} - -bool SQLPTExtRepresentation::SetUnpairedDevice(const std::string& device_id, - bool unpaired) const { - LOG4CXX_TRACE(logger_, "Set unpaired device: " << device_id); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kUpdateUnpairedDevice)) { - LOG4CXX_WARN(logger_, "Incorect statement for updating unpaired device"); - return false; - } - - query.Bind(0, unpaired); - query.Bind(1, device_id); - if (!query.Exec()) { - LOG4CXX_WARN(logger_, "Failed update unpaired device"); - return false; - } - return true; -} - -bool SQLPTExtRepresentation::UnpairedDevicesList(DeviceIds* device_ids) const { - LOG4CXX_TRACE(logger_, "Get list of unpaired devices"); - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kSelectUnpairedDevices)) { - LOG4CXX_WARN(logger_, "Incorect statement for selecting unpaired devices"); - return false; - } - - while (query.Next()) { - device_ids->push_back(query.GetString(0)); - } - return true; -} - -bool SQLPTExtRepresentation::SetVINValue(const std::string& value) { - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kUpdateModuleMetaVinParam)) { - LOG4CXX_WARN(logger_, "Incorect statement for updating module_meta params"); - return false; - } - - query.Bind(0, value); - const bool result = query.Exec(); - - if (!result) { - LOG4CXX_WARN(logger_, "Failed update module_meta"); - } - return result; -} - -bool SQLPTExtRepresentation::RemoveAppConsentForGroup( - const std::string& policy_app_id, - const std::string& functional_group_name) const { - utils::dbms::SQLQuery query_group_id(db()); - if (!query_group_id.Prepare(sql_pt_ext::kSelectGroupId)) { - LOG4CXX_WARN(logger_, "Incorect statement for select group name."); - return false; - } - - query_group_id.Bind(0, functional_group_name); - - if (!query_group_id.Exec()) { - LOG4CXX_WARN(logger_, "Failed to select group id."); - return false; - } - - const int id = query_group_id.GetInteger(0); - - utils::dbms::SQLQuery query(db()); - if (!query.Prepare(sql_pt_ext::kDeleteAppGroupConsent)) { - LOG4CXX_WARN(logger_, "Incorect statement for remove app consent."); - return false; - } - - query.Bind(0, policy_app_id); - query.Bind(1, id); - - if (!query.Exec()) { - LOG4CXX_WARN(logger_, "Failed to remove app consent."); - return false; - } - - return true; -} - -} // namespace policy diff --git a/src/components/policy/policy_regular/src/sql_pt_representation.cc b/src/components/policy/policy_regular/src/sql_pt_representation.cc index 4f5dbc4c3b..75f8be74eb 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -692,6 +692,7 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection( while (query.Next()) { rpc::Nullable<policy_table::ApplicationParams> params; const std::string& app_id = query.GetString(0); + if (IsApplicationRevoked(app_id)) { params.set_to_null(); (*policies).apps[app_id] = params; @@ -720,29 +721,36 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection( if (!query.IsNull(3)) { *params.certificate = query.GetString(4); } - if (!GatherAppGroup(app_id, ¶ms.groups)) { + + const auto& gather_app_id = ((*policies).apps[app_id].is_string()) + ? (*policies).apps[app_id].get_string() + : app_id; + // Data should be gathered from db by "default" key if application has + // default policies + + if (!GatherAppGroup(gather_app_id, ¶ms.groups)) { return false; } bool denied = false; - if (!GatherRemoteControlDenied(app_id, &denied)) { + if (!GatherRemoteControlDenied(gather_app_id, &denied)) { return false; } if (!denied) { - if (!GatherModuleType(app_id, &*params.moduleType)) { + if (!GatherModuleType(gather_app_id, &*params.moduleType)) { return false; } } - if (!GatherNickName(app_id, &*params.nicknames)) { + if (!GatherNickName(gather_app_id, &*params.nicknames)) { return false; } - if (!GatherAppType(app_id, &*params.AppHMIType)) { + if (!GatherAppType(gather_app_id, &*params.AppHMIType)) { return false; } - if (!GatherRequestType(app_id, &*params.RequestType)) { + if (!GatherRequestType(gather_app_id, &*params.RequestType)) { return false; } - if (!GatherRequestSubType(app_id, &*params.RequestSubType)) { + if (!GatherRequestSubType(gather_app_id, &*params.RequestSubType)) { return false; } diff --git a/src/components/policy/policy_regular/test/include/policy/mock_pt_ext_representation.h b/src/components/policy/policy_regular/test/include/policy/mock_pt_ext_representation.h deleted file mode 100644 index 34ad6af5a6..0000000000 --- a/src/components/policy/policy_regular/test/include/policy/mock_pt_ext_representation.h +++ /dev/null @@ -1,139 +0,0 @@ -/* Copyright (c) 2014, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SRC_COMPONENTS_POLICY_POLICY_REGULAR_TEST_INCLUDE_MOCK_PT_EXT_REPRESENTATION_H_ -#define SRC_COMPONENTS_POLICY_POLICY_REGULAR_TEST_INCLUDE_MOCK_PT_EXT_REPRESENTATION_H_ - -#include <string> -#include <vector> - -#include "gmock/gmock.h" - -#include "policy/pt_ext_representation.h" -#include "rpc_base/rpc_base.h" -#include "policy/policy_table/types.h" -#include "mock_pt_representation.h" - -namespace policy_table = ::rpc::policy_table_interface_base; - -namespace policy { -class MockPTExtRepresentation : public MockPTRepresentation, - public PTExtRepresentation { - public: - MOCK_METHOD1(CanAppKeepContext, bool(const std::string& app_id)); - MOCK_METHOD1(CanAppStealFocus, bool(const std::string& app_id)); - MOCK_METHOD2(GetDefaultHMI, - bool(const std::string& app_id, std::string* default_hmi)); - MOCK_METHOD0(ResetUserConsent, bool()); - MOCK_METHOD0(ResetDeviceConsents, bool()); - MOCK_METHOD0(ResetAppConsents, bool()); - MOCK_METHOD3(GetUserPermissionsForDevice, - bool(const std::string&, StringArray*, StringArray*)); - MOCK_METHOD3(GetPermissionsForApp, - bool(const std::string&, - const std::string&, - FunctionalIdType* group_types)); - MOCK_METHOD2(GetDeviceGroupsFromPolicies, - bool(policy_table::Strings*, policy_table::Strings*)); - MOCK_METHOD2( - GetUserFriendlyMsg, - std::vector<UserFriendlyMessage>(const std::vector<std::string>& msg_code, - const std::string& language)); - MOCK_METHOD8(SetDeviceData, - bool(const std::string& device_id, - const std::string& hardware, - const std::string& firmware, - const std::string& os, - const std::string& os_version, - const std::string& carrier, - const uint32_t number_of_ports, - const std::string& connection_type)); - MOCK_METHOD6(SetDeviceData, - bool(const std::string&, - const std::string&, - const std::string&, - const std::string&, - const std::string&, - const std::string&)); - MOCK_METHOD2(SetMaxNumberPorts, - bool(const std::string& device_id, - unsigned int number_of_ports)); - MOCK_METHOD3(SetUserPermissionsForDevice, - bool(const std::string&, - const StringArray&, - const StringArray&)); - MOCK_METHOD1(SetUserPermissionsForApp, bool(const PermissionConsent&)); - MOCK_METHOD1(IncreaseStatisticsData, bool(StatisticsType type)); - MOCK_METHOD3(SetAppRegistrationLanguage, - bool(const std::string& app_id, - LanguageType type, - const std::string& language)); - MOCK_METHOD3(SetMetaInfo, - bool(const std::string& ccpu_version, - const std::string& wers_country_code, - const std::string& vin)); - MOCK_METHOD0(IsMetaInfoPresent, bool()); - MOCK_METHOD1(SetSystemLanguage, bool(const std::string& language)); - MOCK_METHOD0(GetKmFromSuccessfulExchange, int()); - MOCK_METHOD0(GetDayFromScsExchange, int()); - MOCK_METHOD0(GetIgnitionsFromScsExchange, int()); - MOCK_CONST_METHOD1(Increment, void(const std::string& type)); - MOCK_CONST_METHOD2(Increment, - void(const std::string& app_id, const std::string& type)); - MOCK_CONST_METHOD3(Set, - void(const std::string& app_id, - const std::string& type, - const std::string& value)); - MOCK_CONST_METHOD3(Add, - void(const std::string& app_id, - const std::string& type, - int seconds)); - MOCK_CONST_METHOD3(CountUnconsentedGroups, - bool(const std::string& app_id, - const std::string& device_id, - int* count)); - MOCK_METHOD1(GetFunctionalGroupNames, bool(FunctionalGroupNames& names)); - MOCK_CONST_METHOD1(CleanupUnpairedDevices, bool(const DeviceIds& device_ids)); - MOCK_METHOD2(ReactOnUserDevConsentForApp, - bool(const std::string& app_id, bool is_device_allowed)); - MOCK_METHOD1(SetPredataPolicy, bool(const std::string& app_id)); - MOCK_METHOD2(SetIsPredata, bool(const std::string& app_id, bool is_predata)); - MOCK_CONST_METHOD2(SetUnpairedDevice, - bool(const std::string& device_id, bool unpaired)); - MOCK_CONST_METHOD1(UnpairedDevicesList, bool(DeviceIds* device_ids)); - MOCK_CONST_METHOD2(RemoveAppConsentForGroup, - bool(const std::string& policy_app_id, - const std::string& functional_group)); -}; - -} // namespace policy - -#endif // SRC_COMPONENTS_POLICY_POLICY_REGULAR_TEST_INCLUDE_MOCK_PT_EXT_REPRESENTATION_H_ |