diff options
author | Alexander Kutsan <akutsan@luxoft.com> | 2017-08-10 14:07:09 +0300 |
---|---|---|
committer | Andrey Oleynik <aoleynik@luxoft.com> | 2017-08-16 22:34:23 +0300 |
commit | 59f437dc8608e1ec54c517416a39860d9a7be3b8 (patch) | |
tree | 2908c276bd5ea066741c034eb2bd144682ba8649 /src/components/policy/policy_regular | |
parent | 06729e8b744374a4d9694f669101b6c554ce42e0 (diff) | |
download | sdl_core-59f437dc8608e1ec54c517416a39860d9a7be3b8.tar.gz |
Implementation of Remote Control plugin
Stype changes after integration
Fix policy handler remote unit tests
Diffstat (limited to 'src/components/policy/policy_regular')
29 files changed, 2503 insertions, 588 deletions
diff --git a/src/components/policy/policy_regular/CMakeLists.txt b/src/components/policy/policy_regular/CMakeLists.txt index 76e10a58b0..c7b9c068b9 100644 --- a/src/components/policy/policy_regular/CMakeLists.txt +++ b/src/components/policy/policy_regular/CMakeLists.txt @@ -65,12 +65,17 @@ set(EXCLUDE_PATHS ) set(PATHS - ${CMAKE_CURRENT_SOURCE_DIR}/include/ - ${CMAKE_CURRENT_SOURCE_DIR}/src/ + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/src ${COMPONENTS_DIR}/rpc_base/src/rpc_base/rpc_base.cc ) collect_sources(SOURCES "${PATHS}" "${EXCLUDE_PATHS}") +if (NOT REMOTE_CONTROL) + list(REMOVE_ITEM SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/src/access_remote_impl.cc) +endif() + set(LIBRARIES ConfigProfile policy_struct diff --git a/src/components/policy/policy_regular/include/policy/access_remote.h b/src/components/policy/policy_regular/include/policy/access_remote.h new file mode 100644 index 0000000000..b9fd8862e9 --- /dev/null +++ b/src/components/policy/policy_regular/include/policy/access_remote.h @@ -0,0 +1,233 @@ +/* + * 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. + */ +#ifndef SRC_COMPONENTS_POLICY_SRC_POLICY_INCLUDE_POLICY_ACCESS_REMOTE_H_ +#define SRC_COMPONENTS_POLICY_SRC_POLICY_INCLUDE_POLICY_ACCESS_REMOTE_H_ + +#include <vector> +#include <ostream> +#include <string> +#include "policy/policy_table/types.h" +#include "policy/policy_types.h" + +namespace policy_table = ::rpc::policy_table_interface_base; + +namespace policy { + +enum TypeAccess { kDisallowed, kAllowed, kManual }; +inline std::ostream& operator<<(std::ostream& output, TypeAccess x) { + output << "Access: "; + switch (x) { + case kDisallowed: + output << "DISALLOWED"; + break; + case kAllowed: + output << "ALLOWED"; + break; + case kManual: + output << "MANUAL"; + break; + default: + output << "Error: Unknown type"; + } + return output; +} + +struct Subject { + PTString dev_id; + PTString app_id; +}; +inline bool operator<(const Subject& x, const Subject& y) { + return x.dev_id < y.dev_id || (x.dev_id == y.dev_id && x.app_id < y.app_id); +} +inline bool operator==(const Subject& x, const Subject& y) { + return x.dev_id == y.dev_id && x.app_id == y.app_id; +} +inline std::ostream& operator<<(std::ostream& output, const Subject& who) { + output << "Subject(dev:" << who.dev_id << ", app:" << who.app_id << ")"; + return output; +} + +struct Object { + policy_table::ModuleType module; +}; +inline bool operator<(const Object& x, const Object& y) { + return x.module < y.module; +} +inline bool operator==(const Object& x, const Object& y) { + return x.module == y.module; +} +inline std::ostream& operator<<(std::ostream& output, const Object& what) { + output << "Object(module:" << EnumToJsonString(what.module) << ")"; + return output; +} + +typedef std::vector<PTString> RemoteControlParams; + +class AccessRemote { + public: + virtual ~AccessRemote() {} + + /** + * Initializes oneself + */ + virtual void Init() = 0; + + /** + * Enables remote control + */ + virtual void Enable() = 0; + + /** + * Disables remote control + */ + virtual void Disable() = 0; + + /** + * Checks if remote control is enabled + * @return true if enabled + */ + virtual bool IsEnabled() const = 0; + + /** + * Checks whether device is driver's device + * @param dev_id unique device id + * @return true if device is have driver + */ + virtual bool IsPrimaryDevice(const PTString& dev_id) const = 0; + + /** + * Sets device as driver's device + * @param dev_id ID device + */ + virtual void SetPrimaryDevice(const PTString& dev_id) = 0; + + /** + * Gets current primary device + * @return ID device + */ + virtual PTString PrimaryDevice() const = 0; + + /** + * Allows access subject to object + * @param who subject is dev_id and app_id + * @param what object is group_id + */ + virtual void Allow(const Subject& who, const Object& what) = 0; + + /** + * Denies access subject to object + * @param who subject is dev_id and app_id + * @param what object is group_id + */ + virtual void Deny(const Subject& who, const Object& what) = 0; + + /** + * Resets access subject to all object + * @param who subject is dev_id and app_id + */ + virtual void Reset(const Subject& who) = 0; + + /** + * Resets access to object for all subjects + * @param what object is group + */ + virtual void Reset(const Object& what) = 0; + + /* + * Resets all stored consents + */ + virtual void Reset() = 0; + + /** + * Checks access subject to object + * @param who subject is dev_id and app_id + * @param what object is group_id + * @return allowed if access was given, disallowed if access was denied + * manual if need to ask driver + */ + virtual TypeAccess Check(const Subject& who, const Object& what) const = 0; + + /** + * Checks permissions for module + * @param app_id application ID + * @param module type + * @return true if allowed + */ + virtual bool CheckModuleType(const PTString& app_id, + policy_table::ModuleType module) const = 0; + + /** + * Sets HMI types if application has default policy permissions + * @param who subject + * @param hmi_types list of HMI types + */ + virtual void SetDefaultHmiTypes(const Subject& who, + const std::vector<int>& hmi_types) = 0; + + /** + * Gets groups + * @param who subject + * @return list of groups + */ + virtual const policy_table::Strings& GetGroups(const Subject& who) = 0; + + /** + * Gets permissions for application + * @param device_id + * @param app_id + * @param group_types + * @return true if success + */ + virtual bool GetPermissionsForApp(const std::string& device_id, + const std::string& app_id, + FunctionalIdType& group_types) = 0; + + /** + * Checks if application has remote functionality + * @param who subject + * @return true if application uses remote control + */ + virtual bool IsAppRemoteControl(const Subject& who) = 0; + + /** + * Gets all allowed module types + * @param app_id unique identifier of application + * @param list of allowed module types + * @return true if application has allowed modules + */ + virtual bool GetModuleTypes(const std::string& policy_app_id, + std::vector<std::string>* modules) = 0; +}; + +} // namespace policy + +#endif // SRC_COMPONENTS_POLICY_SRC_POLICY_INCLUDE_POLICY_ACCESS_REMOTE_H_ diff --git a/src/components/policy/policy_regular/include/policy/access_remote_impl.h b/src/components/policy/policy_regular/include/policy/access_remote_impl.h new file mode 100644 index 0000000000..03427d2501 --- /dev/null +++ b/src/components/policy/policy_regular/include/policy/access_remote_impl.h @@ -0,0 +1,123 @@ +/* + * 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. + */ +#ifndef SRC_COMPONENTS_POLICY_SRC_POLICY_INCLUDE_POLICY_ACCESS_REMOTE_IMPL_H_ +#define SRC_COMPONENTS_POLICY_SRC_POLICY_INCLUDE_POLICY_ACCESS_REMOTE_IMPL_H_ + +#include <map> +#include "policy/policy_table/types.h" +#include "utils/macro.h" +#include "utils/shared_ptr.h" +#include "policy/access_remote.h" +#include "policy/cache_manager.h" + +using policy_table::FunctionalGroupings; + +namespace policy { + +class AccessRemoteImpl : public AccessRemote { + public: + typedef std::map<Subject, TypeAccess> AccessControlRow; + typedef std::map<Object, AccessControlRow> AccessControlList; + typedef std::map<Subject, policy_table::AppHMITypes> HMIList; + + AccessRemoteImpl(); + explicit AccessRemoteImpl(utils::SharedPtr<CacheManager> cache); + + virtual void Init(); + virtual void Enable(); + virtual void Disable(); + virtual bool IsEnabled() const; + + virtual bool IsPrimaryDevice(const PTString& dev_id) const; + virtual void SetPrimaryDevice(const PTString& dev_id); + virtual PTString PrimaryDevice() const; + + virtual void Allow(const Subject& who, const Object& what); + virtual void Deny(const Subject& who, const Object& what); + virtual void Reset(const Subject& who); + virtual void Reset(const Object& what); + virtual void Reset(); + virtual TypeAccess Check(const Subject& who, const Object& what) const; + virtual bool CheckModuleType(const PTString& app_id, + policy_table::ModuleType module) const; + virtual void SetDefaultHmiTypes(const Subject& who, + const std::vector<int>& hmi_types); + virtual const policy_table::Strings& GetGroups(const Subject& who); + virtual bool GetPermissionsForApp(const std::string& device_id, + const std::string& app_id, + FunctionalIdType& group_types); + virtual bool IsAppRemoteControl(const Subject& who); + virtual bool GetModuleTypes(const std::string& policy_app_id, + std::vector<std::string>* modules); + + private: + inline void set_enabled(bool value); + inline bool country_consent() const; + const policy_table::AppHMITypes& HmiTypes(const Subject& who); + void GetGroupsIds(const std::string& device_id, + const std::string& app_id, + FunctionalGroupIDs& grops_ids); + bool IsAllowed(const policy_table::AccessModules& modules, + const std::string& module_name, + const std::string& rpc_name, + RemoteControlParams* input) const; + bool CompareParameters(const policy_table::Strings& parameters, + RemoteControlParams* input) const; + utils::SharedPtr<CacheManager> cache_; + PTString primary_device_; + bool enabled_; + AccessControlList acl_; + HMIList hmi_types_; + +#ifdef BUILD_TESTS + friend struct Erase; + friend struct IsTypeAccess; + + FRIEND_TEST(AccessRemoteImplTest, KeyMapTest); + FRIEND_TEST(AccessRemoteImplTest, Allow); + FRIEND_TEST(AccessRemoteImplTest, Deny); + FRIEND_TEST(AccessRemoteImplTest, ChangeAccess); + FRIEND_TEST(AccessRemoteImplTest, ResetBySubject); + FRIEND_TEST(AccessRemoteImplTest, ResetByObject); + FRIEND_TEST(AccessRemoteImplTest, CheckAllowed); + FRIEND_TEST(AccessRemoteImplTest, CheckDisallowed); + FRIEND_TEST(AccessRemoteImplTest, CheckManual); + FRIEND_TEST(AccessRemoteImplTest, CheckModuleType); + FRIEND_TEST(AccessRemoteImplTest, EnableDisable); + FRIEND_TEST(AccessRemoteImplTest, SetDefaultHmiTypes); + FRIEND_TEST(AccessRemoteImplTest, GetGroups); +#endif // BUILD_TESTS +}; + +} // namespace policy + +#endif // SRC_COMPONENTS_POLICY_SRC_POLICY_INCLUDE_POLICY_ACCESS_REMOTE_IMPL_H_ 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 73c010ce33..c5d4c848f4 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -325,6 +325,13 @@ class CacheManager : public CacheManagerInterface { bool GetDefaultHMI(const std::string& app_id, std::string& default_hmi) const; /** + * Gets HMI types from specific policy + * @param app_id ID application + * @return list of HMI types + */ + const policy_table::AppHMITypes* GetHMITypes(const std::string& app_id); + + /** * @brief Reset user consent for device data and applications permissions * @return */ @@ -690,11 +697,9 @@ class CacheManager : public CacheManagerInterface { const PolicySettings& get_settings() const; -#ifdef BUILD_TESTS - utils::SharedPtr<policy_table::Table> GetPT() const { + utils::SharedPtr<policy_table::Table> pt() const { return pt_; } -#endif private: std::string currentDateTime(); @@ -767,6 +772,13 @@ class CacheManager : public CacheManagerInterface { sync_primitives::Lock backuper_locker_; BackgroundBackuper* backuper_; const PolicySettings* settings_; + +#ifdef BUILD_TESTS + friend class AccessRemoteImpl; + FRIEND_TEST(AccessRemoteImplTest, CheckModuleType); + FRIEND_TEST(AccessRemoteImplTest, EnableDisable); + FRIEND_TEST(AccessRemoteImplTest, GetGroups); +#endif // BUILD_TESTS }; } // namespace policy #endif // SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_CACHE_MANAGER_H_ diff --git a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h index 50896bb8f1..9712b799dc 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h @@ -323,6 +323,14 @@ class CacheManagerInterface { std::string& default_hmi) const = 0; /** + * Gets HMI types from specific policy + * @param app_id ID application + * @return list of HMI types + */ + virtual const policy_table::AppHMITypes* GetHMITypes( + const std::string& app_id) = 0; + + /** * @brief Reset user consent for device data and applications permissions * @return */ @@ -626,15 +634,13 @@ class CacheManagerInterface { */ virtual std::string GetCertificate() const = 0; -#ifdef BUILD_TESTS /** - * @brief GetPT allows to obtain SharedPtr to PT. + * @brief pt allows to obtain SharedPtr to PT. * Used ONLY in Unit tests * @return SharedPTR to PT * */ - virtual utils::SharedPtr<policy_table::Table> GetPT() const = 0; -#endif + virtual utils::SharedPtr<policy_table::Table> pt() const = 0; }; typedef utils::SharedPtr<CacheManagerInterface> CacheManagerInterfaceSPtr; diff --git a/src/components/policy/policy_regular/include/policy/policy_helper.h b/src/components/policy/policy_regular/include/policy/policy_helper.h index 996c2917d0..ce1288fa1b 100644 --- a/src/components/policy/policy_regular/include/policy/policy_helper.h +++ b/src/components/policy/policy_regular/include/policy/policy_helper.h @@ -243,6 +243,22 @@ FunctionalGroupIDs FindSame(const FunctionalGroupIDs& first, * @return true, if succeded, otherwise - false */ bool UnwrapAppPolicies(policy_table::ApplicationPolicies& app_policies); + +#ifdef SDL_REMOTE_CONTROL + +struct ProccessAppGroups { + ProccessAppGroups(const policy_table::ApplicationPolicies& apps, + PolicyManagerImpl* pm) + : new_apps_(apps), pm_(pm), default_(new_apps_.find(kDefaultId)) {} + void operator()(const policy_table::ApplicationPolicies::value_type& app); + + private: + const policy_table::ApplicationPolicies& new_apps_; + PolicyManagerImpl* pm_; + policy_table::ApplicationPolicies::const_iterator default_; +}; + +#endif // SDL_REMOTE_CONTROL } #endif // SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_POLICY_HELPER_H_ diff --git a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h index 3ca9994a8a..868328bcb4 100644 --- a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h @@ -47,6 +47,10 @@ #include "policy/usage_statistics/statistics_manager.h" #include "policy/policy_helper.h" #include "utils/timer.h" +#ifdef SDL_REMOTE_CONTROL +#include "policy/access_remote.h" +#include "policy/access_remote_impl.h" +#endif // SDL_REMOTE_CONTROL namespace policy_table = rpc::policy_table_interface_base; @@ -176,6 +180,39 @@ class PolicyManagerImpl : public PolicyManager { StatusNotifier AddApplication( const std::string& application_id, const rpc::policy_table_interface_base::AppHmiTypes& hmi_types); +#ifdef SDL_REMOTE_CONTROL + void SetDefaultHmiTypes(const std::string& application_id, + const std::vector<int>& hmi_types); + /** + * Gets HMI types + * @param application_id ID application + * @param app_types list to save HMI types + * @return true if policy has specific policy for this application + */ + virtual bool GetHMITypes(const std::string& application_id, + std::vector<int>* app_types) OVERRIDE; + virtual void set_access_remote(utils::SharedPtr<AccessRemote> access_remote); + TypeAccess CheckDriverConsent(const Subject& who, + const Object& what, + const std::string& rpc, + const RemoteControlParams& params); + void CheckPTUUpdatesChange( + const utils::SharedPtr<policy_table::Table> pt_update, + const utils::SharedPtr<policy_table::Table> snapshot); + bool CheckPTURemoteCtrlChange( + const utils::SharedPtr<policy_table::Table> pt_update, + const utils::SharedPtr<policy_table::Table> snapshot); + + void CheckRemoteGroupsChange( + const utils::SharedPtr<policy_table::Table> pt_update, + const utils::SharedPtr<policy_table::Table> snapshot); + + void SendHMILevelChanged(const Subject& who); + void UpdateDeviceRank(const Subject& who, const std::string& rank); + + void OnPrimaryGroupsChanged(const std::string& application_id); + void OnNonPrimaryGroupsChanged(const std::string& application_id); +#endif // SDL_REMOTE_CONTROL virtual void RemoveAppConsentForGroup(const std::string& app_id, const std::string& group_name); @@ -319,10 +356,43 @@ class PolicyManagerImpl : public PolicyManager { void RetrySequence(); private: +#ifdef SDL_REMOTE_CONTROL + void GetPermissions(const std::string device_id, + const std::string application_id, + Permissions* data); + virtual TypeAccess CheckAccess(const PTString& device_id, + const PTString& app_id, + const PTString& module, + const PTString& rpc, + const RemoteControlParams& params); + virtual bool CheckModule(const PTString& app_id, const PTString& module); + virtual void SetAccess(const PTString& dev_id, + const PTString& app_id, + const PTString& module, + bool allowed); + virtual void ResetAccess(const PTString& dev_id, const PTString& app_id); + virtual void ResetAccess(const PTString& module); + virtual void SetPrimaryDevice(const PTString& dev_id); + virtual void ResetPrimaryDevice(); + virtual PTString PrimaryDevice() const; + virtual void SetRemoteControl(bool enabled); + virtual bool GetRemoteControl() const; + virtual void OnChangedPrimaryDevice(const std::string& device_id, + const std::string& application_id); + virtual void OnChangedRemoteControl(const std::string& device_id, + const std::string& application_id); + virtual void SendAppPermissionsChanged(const std::string& device_id, + const std::string& application_id); + virtual bool GetModuleTypes(const std::string& policy_app_id, + std::vector<std::string>* modules) const; +#endif // SDL_REMOTE_CONTROL PolicyListener* listener_; UpdateStatusManager update_status_manager_; CacheManagerInterfaceSPtr cache_; +#ifdef SDL_REMOTE_CONTROL + utils::SharedPtr<AccessRemote> access_remote_; +#endif sync_primitives::Lock apps_registration_lock_; sync_primitives::Lock app_permissions_diff_lock_; std::map<std::string, AppPermissions> app_permissions_diff_; diff --git a/src/components/policy/policy_regular/include/policy/policy_table/types.h b/src/components/policy/policy_regular/include/policy/policy_table/types.h index 8b9a872a5b..d9d2ad34eb 100644 --- a/src/components/policy/policy_regular/include/policy/policy_table/types.h +++ b/src/components/policy/policy_regular/include/policy/policy_table/types.h @@ -96,6 +96,12 @@ typedef Map<DeviceParams, 0, 255> DeviceData; typedef Array<Enum<RequestType>, 0, 255> RequestTypes; +#ifdef SDL_REMOTE_CONTROL +typedef Map<Strings, 0, 255> RemoteRpcs; +typedef Map<RemoteRpcs, 0, 255> AccessModules; +typedef Array<Enum<ModuleType>, 0, 255> ModuleTypes; +#endif // SDL_REMOTE_CONTROL + typedef AppHMIType AppHmiType; typedef std::vector<AppHMIType> AppHmiTypes; @@ -136,6 +142,11 @@ struct ApplicationParams : PolicyBase { Optional<Integer<uint16_t, 0, 65225> > memory_kb; Optional<Integer<uint32_t, 0, UINT_MAX> > heart_beat_timeout_ms; Optional<String<0, 255> > certificate; +#ifdef SDL_REMOTE_CONTROL + Optional<Strings> groups_primaryRC; + Optional<Strings> groups_nonPrimaryRC; + mutable Optional<ModuleTypes> moduleType; +#endif // SDL_REMOTE_CONTROL public: ApplicationParams(); @@ -151,6 +162,9 @@ struct ApplicationParams : PolicyBase { private: bool Validate() const; +#ifdef SDL_REMOTE_CONTROL + bool ValidateModuleTypes() const; +#endif // SDL_REMOTE_CONTROL }; struct ApplicationPoliciesSection : CompositeType { @@ -233,6 +247,10 @@ struct ModuleConfig : CompositeType { Optional<String<4, 4> > vehicle_year; Optional<String<0, 10> > preloaded_date; Optional<String<0, 65535> > certificate; +#ifdef SDL_REMOTE_CONTROL + Optional<Boolean> user_consent_passengersRC; + Optional<Boolean> country_consent_passengersRC; +#endif // SDL_REMOTE_CONTROL public: ModuleConfig(); diff --git a/src/components/policy/policy_regular/include/policy/policy_types.h b/src/components/policy/policy_regular/include/policy/policy_types.h index 25aa126a03..09df043197 100644 --- a/src/components/policy/policy_regular/include/policy/policy_types.h +++ b/src/components/policy/policy_regular/include/policy/policy_types.h @@ -56,6 +56,7 @@ const std::string kDefaultDeviceConnectionType = "UNKNOWN"; */ const std::string kPreDataConsentId = "pre_DataConsent"; const std::string kDefaultId = "default"; +const std::string kPreConsentPassengersRC = "pre_consent_passengersRC"; const std::string kDeviceId = "device"; /* diff --git a/src/components/policy/policy_regular/include/policy/sql_pt_queries.h b/src/components/policy/policy_regular/include/policy/sql_pt_queries.h index 79a66ba41a..20f5d5aed4 100644 --- a/src/components/policy/policy_regular/include/policy/sql_pt_queries.h +++ b/src/components/policy/policy_regular/include/policy/sql_pt_queries.h @@ -114,6 +114,27 @@ extern const std::string kInsertApplicationFull; extern const std::string kDeletePreconsentedGroupsByApplicationId; extern const std::string kSelectApplicationFull; extern const std::string kUpdatePreloaded; +extern const std::string kUpdateRemoteControlDenied; +extern const std::string kSelectRemoteControlDenied; +extern const std::string kDeleteAppGroupPrimaryByApplicationId; +extern const std::string kDeleteAppGroupNonPrimaryByApplicationId; +extern const std::string kCollectFriendlyMsg; +extern const std::string kSelectAppGroupsPrimary; +extern const std::string kSelectAppGroupsNonPrimary; +extern const std::string kSelectModuleTypes; +extern const std::string kInsertAppGroupPrimary; +extern const std::string kInsertAppGroupNonPrimary; +extern const std::string kInsertModuleType; +extern const std::string kInsertAccessModule; +extern const std::string kSelectAccessModules; +extern const std::string kDeleteAccessModules; +extern const std::string kInsertRemoteRpc; +extern const std::string kSelectRemoteRpcs; +extern const std::string kDeleteRemoteRpc; +extern const std::string kDeleteAppGroupPrimary; +extern const std::string kDeleteAppGroupNonPrimary; +extern const std::string kDeleteModuleTypes; +extern const std::string kDeleteAllDevices; extern const std::string kSelectDBVersion; extern const std::string kUpdateDBVersion; extern const std::string kSaveModuleMeta; diff --git a/src/components/policy/policy_regular/include/policy/sql_pt_representation.h b/src/components/policy/policy_regular/include/policy/sql_pt_representation.h index bd867389ab..e152c040b1 100644 --- a/src/components/policy/policy_regular/include/policy/sql_pt_representation.h +++ b/src/components/policy/policy_regular/include/policy/sql_pt_representation.h @@ -97,6 +97,31 @@ class SQLPTRepresentation : public virtual PTRepresentation { } #endif // BUILD_TESTS protected: +#ifdef SDL_REMOTE_CONTROL + enum TypeAccess { kAllowed, kManual }; + bool GatherAppGroupPrimary(const std::string& app_id, + policy_table::Strings* app_groups) const; + bool GatherAppGroupNonPrimary(const std::string& app_id, + policy_table::Strings* app_groups) const; + bool GatherModuleType(const std::string& app_id, + policy_table::ModuleTypes* module_types) const; + bool GatherRemoteControlDenied(const std::string& app_id, bool* denied) const; + bool GatherAccessModule(TypeAccess access, + policy_table::AccessModules* modules) const; + bool GatherRemoteRpc(int module_id, policy_table::RemoteRpcs* rpcs) const; + bool SaveAppGroupPrimary(const std::string& app_id, + const policy_table::Strings& app_groups); + bool SaveAppGroupNonPrimary(const std::string& app_id, + const policy_table::Strings& app_groups); + bool SaveModuleType(const std::string& app_id, + const policy_table::ModuleTypes& types); + bool SaveRemoteControlDenied(const std::string& app_id, bool deny); + + bool SaveAccessModule(TypeAccess access, + const policy_table::AccessModules& modules); + bool SaveRemoteRpc(int module_id, const policy_table::RemoteRpcs& rpcs); +#endif // SDL_REMOTE_CONTROL + virtual void GatherModuleMeta(policy_table::ModuleMeta* meta) const; virtual void GatherModuleConfig(policy_table::ModuleConfig* config) const; virtual bool GatherUsageAndErrorCounts( diff --git a/src/components/policy/policy_regular/include/policy/usage_statistics/app_stopwatch.h b/src/components/policy/policy_regular/include/policy/usage_statistics/app_stopwatch.h deleted file mode 100644 index 8093c11467..0000000000 --- a/src/components/policy/policy_regular/include/policy/usage_statistics/app_stopwatch.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2016, 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_USAGE_STATISTICS_APP_STOPWATCH_H_ -#define SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_USAGE_STATISTICS_APP_STOPWATCH_H_ - -#include "policy/usage_statistics/statistics_manager.h" - -namespace usage_statistics { - -class AppStopwatch { - public: - virtual ~AppStopwatch() {} - virtual void Start(AppStopwatchId stopwatch_type) = 0; - virtual void Switch(AppStopwatchId stopwatch_type) = 0; - virtual void WriteTime() = 0; -}; - -} // namespace usage_statistics - -#endif // SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_USAGE_STATISTICS_APP_STOPWATCH_H_ diff --git a/src/components/policy/policy_regular/src/access_remote_impl.cc b/src/components/policy/policy_regular/src/access_remote_impl.cc new file mode 100644 index 0000000000..9ae76fc19a --- /dev/null +++ b/src/components/policy/policy_regular/src/access_remote_impl.cc @@ -0,0 +1,377 @@ +/* + * 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 "policy/access_remote_impl.h" + +#include <algorithm> +#include <iterator> +#include "policy/cache_manager.h" +#include "utils/logger.h" + +CREATE_LOGGERPTR_GLOBAL(logger_, "PolicyManagerImpl") + +using policy_table::DeviceData; +using policy_table::FunctionalGroupings; +using rpc::policy_table_interface_base::EnumFromJsonString; + +namespace policy { + +struct Erase { + private: + const Subject& who_; + + public: + explicit Erase(const Subject& who) : who_(who) {} + void operator()(AccessRemoteImpl::AccessControlList::value_type& row) const { + row.second.erase(who_); + } +}; + +struct IsTypeAccess { + private: + const TypeAccess& type_; + + public: + explicit IsTypeAccess(const TypeAccess& type) : type_(type) {} + bool operator()( + const AccessRemoteImpl::AccessControlRow::value_type& item) const { + return item.second == type_; + } +}; + +struct ToHMIType { + policy_table::AppHMITypes::value_type operator()(int item) const { + policy_table::AppHMIType type = static_cast<policy_table::AppHMIType>(item); + if (!IsValidEnum(type)) { + LOG4CXX_WARN(logger_, "HMI type isn't known " << item); + type = policy_table::AHT_DEFAULT; + } + LOG4CXX_DEBUG(logger_, + "HMI type: " << item << " - " << EnumToJsonString(type)); + return policy_table::AppHMITypes::value_type(type); + } +}; + +struct Contained { + private: + const policy_table::Strings& params_; + + public: + explicit Contained(const policy_table::Strings& params) : params_(params) {} + bool operator()(const RemoteControlParams::value_type& item) const { + return std::find_if(params_.begin(), params_.end(), CompareString(item)) != + params_.end(); + } + struct CompareString { + private: + const RemoteControlParams::value_type& value_; + + public: + explicit CompareString(const RemoteControlParams::value_type& value) + : value_(value) {} + bool operator()(const policy_table::Strings::value_type& item) const { + return value_ == static_cast<std::string>(item); + } + }; +}; + +struct ToModuleType { + std::string operator()(policy_table::ModuleTypes::value_type item) const { + policy_table::ModuleType type = static_cast<policy_table::ModuleType>(item); + return EnumToJsonString(type); + } +}; + +AccessRemoteImpl::AccessRemoteImpl() + : cache_(new CacheManager()), primary_device_(), enabled_(true), acl_() {} + +AccessRemoteImpl::AccessRemoteImpl(utils::SharedPtr<CacheManager> cache) + : cache_(cache), primary_device_(), enabled_(true), acl_() {} + +void AccessRemoteImpl::Init() { + LOG4CXX_AUTO_TRACE(logger_); + DCHECK(cache_->pt()); + + policy_table::ModuleConfig& config = cache_->pt()->policy_table.module_config; + enabled_ = country_consent() && + (!config.user_consent_passengersRC.is_initialized() || + *config.user_consent_passengersRC); +} + +bool AccessRemoteImpl::IsPrimaryDevice(const PTString& dev_id) const { + LOG4CXX_AUTO_TRACE(logger_); + return primary_device_ == dev_id; +} + +TypeAccess AccessRemoteImpl::Check(const Subject& who, + const Object& what) const { + LOG4CXX_AUTO_TRACE(logger_); + AccessControlList::const_iterator i = acl_.find(what); + if (i != acl_.end()) { + const AccessControlRow& row = i->second; + AccessControlRow::const_iterator j = row.find(who); + if (j != row.end()) { + // who has permissions + TypeAccess ret = j->second; + LOG4CXX_TRACE(logger_, + "Subject " << who << " has permissions " << ret + << " to object " << what); + return ret; + } + } + return TypeAccess::kManual; +} + +bool AccessRemoteImpl::CheckModuleType(const PTString& app_id, + policy_table::ModuleType module) const { + LOG4CXX_AUTO_TRACE(logger_); + if (!cache_->IsApplicationRepresented(app_id)) { + return false; + } + + const policy_table::ApplicationParams& app = + cache_->pt()->policy_table.app_policies_section.apps[app_id]; + if (!app.moduleType.is_initialized()) { + return false; + } + + const policy_table::ModuleTypes& modules = *app.moduleType; + if (modules.empty()) { + return true; + } + + return std::find(modules.begin(), modules.end(), module) != modules.end(); +} + +bool AccessRemoteImpl::IsAllowed(const policy_table::AccessModules& modules, + const std::string& module_name, + const std::string& rpc_name, + RemoteControlParams* input) const { + LOG4CXX_AUTO_TRACE(logger_); + policy_table::AccessModules::const_iterator i = modules.find(module_name); + if (i == modules.end()) { + LOG4CXX_DEBUG(logger_, "Module " << module_name << " wasn't found"); + return false; + } + + const policy_table::RemoteRpcs& rpcs = i->second; + if (rpcs.empty()) { + return true; + } + policy_table::RemoteRpcs::const_iterator j = rpcs.find(rpc_name); + if (j != rpcs.end()) { + const policy_table::Strings& parameters = j->second; + return CompareParameters(parameters, input); + } + LOG4CXX_DEBUG(logger_, "RPC " << rpc_name << " wasn't found"); + return false; +} + +bool AccessRemoteImpl::CompareParameters( + const policy_table::Strings& parameters, RemoteControlParams* input) const { + LOG4CXX_AUTO_TRACE(logger_); + if (parameters.empty()) { + return true; + } + + if (input->empty()) { + LOG4CXX_DEBUG(logger_, "Input is empty"); + return false; + } + + input->erase( + std::remove_if(input->begin(), input->end(), Contained(parameters)), + input->end()); + return input->empty(); +} + +void AccessRemoteImpl::Allow(const Subject& who, const Object& what) { + LOG4CXX_AUTO_TRACE(logger_); + acl_[what][who] = TypeAccess::kAllowed; +} + +void AccessRemoteImpl::Deny(const Subject& who, const Object& what) { + LOG4CXX_AUTO_TRACE(logger_); + acl_[what][who] = TypeAccess::kDisallowed; +} + +void AccessRemoteImpl::Reset(const Subject& who) { + LOG4CXX_AUTO_TRACE(logger_); + std::for_each(acl_.begin(), acl_.end(), Erase(who)); +} + +void AccessRemoteImpl::Reset(const Object& what) { + LOG4CXX_AUTO_TRACE(logger_); + acl_.erase(what); +} + +void AccessRemoteImpl::Reset() { + acl_.clear(); +} + +void AccessRemoteImpl::SetPrimaryDevice(const PTString& dev_id) { + LOG4CXX_AUTO_TRACE(logger_); + primary_device_ = dev_id; +} + +PTString AccessRemoteImpl::PrimaryDevice() const { + return primary_device_; +} + +void AccessRemoteImpl::Enable() { + LOG4CXX_AUTO_TRACE(logger_); + set_enabled(true); +} + +void AccessRemoteImpl::Disable() { + LOG4CXX_AUTO_TRACE(logger_); + set_enabled(false); +} + +void AccessRemoteImpl::set_enabled(bool value) { + enabled_ = country_consent() && value; + *cache_->pt()->policy_table.module_config.user_consent_passengersRC = value; + cache_->Backup(); +} + +bool AccessRemoteImpl::country_consent() const { + policy_table::ModuleConfig& config = cache_->pt()->policy_table.module_config; + return !config.country_consent_passengersRC.is_initialized() || + *config.country_consent_passengersRC; +} + +bool AccessRemoteImpl::IsEnabled() const { + LOG4CXX_AUTO_TRACE(logger_); + return enabled_; +} + +void AccessRemoteImpl::SetDefaultHmiTypes(const Subject& who, + const std::vector<int>& hmi_types) { + LOG4CXX_AUTO_TRACE(logger_); + HMIList::mapped_type types; + std::transform(hmi_types.begin(), + hmi_types.end(), + std::back_inserter(types), + ToHMIType()); + hmi_types_[who] = types; +} + +const policy_table::AppHMITypes& AccessRemoteImpl::HmiTypes( + const Subject& who) { + LOG4CXX_AUTO_TRACE(logger_); + if (cache_->IsDefaultPolicy(who.app_id)) { + return hmi_types_[who]; + } else { + return *cache_->pt() + ->policy_table.app_policies_section.apps[who.app_id] + .AppHMIType; + } +} + +const policy_table::Strings& AccessRemoteImpl::GetGroups(const Subject& who) { + LOG4CXX_AUTO_TRACE(logger_); + if (IsAppRemoteControl(who)) { + if (IsPrimaryDevice(who.dev_id)) { + return *cache_->pt() + ->policy_table.app_policies_section.apps[who.app_id] + .groups_primaryRC; + } else if (IsEnabled()) { + return *cache_->pt() + ->policy_table.app_policies_section.apps[who.app_id] + .groups_nonPrimaryRC; + } else { + return cache_->GetGroups(kPreConsentPassengersRC); + } + } + return cache_->GetGroups(who.app_id); +} + +bool AccessRemoteImpl::IsAppRemoteControl(const Subject& who) { + LOG4CXX_AUTO_TRACE(logger_); + const policy_table::AppHMITypes& hmi_types = HmiTypes(who); + return std::find(hmi_types.begin(), + hmi_types.end(), + policy_table::AHT_REMOTE_CONTROL) != hmi_types.end(); +} + +bool AccessRemoteImpl::GetPermissionsForApp(const std::string& device_id, + const std::string& app_id, + FunctionalIdType& group_types) { + LOG4CXX_AUTO_TRACE(logger_); + GetGroupsIds(device_id, app_id, group_types[kTypeGeneral]); + GetGroupsIds(device_id, kDefaultId, group_types[kTypeDefault]); + GetGroupsIds( + device_id, kPreDataConsentId, group_types[kTypePreDataConsented]); + return true; +} + +std::ostream& operator<<(std::ostream& output, + const FunctionalGroupIDs& types) { + std::copy(types.begin(), + types.end(), + std::ostream_iterator<FunctionalGroupIDs::value_type>(output, " ")); + return output; +} + +void AccessRemoteImpl::GetGroupsIds(const std::string& device_id, + const std::string& app_id, + FunctionalGroupIDs& groups_ids) { + Subject who = {device_id, app_id}; + const policy_table::Strings& groups = GetGroups(who); + groups_ids.resize(groups.size()); + std::transform(groups.begin(), + groups.end(), + groups_ids.begin(), + &CacheManager::GenerateHash); + LOG4CXX_DEBUG(logger_, "Groups Ids: " << groups_ids); +} + +bool AccessRemoteImpl::GetModuleTypes(const std::string& application_id, + std::vector<std::string>* modules) { + DCHECK(modules); + policy_table::ApplicationPolicies& apps = + cache_->pt()->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::iterator i = apps.find(application_id); + if (i == apps.end()) { + return false; + } + rpc::Optional<policy_table::ModuleTypes> moduleTypes = i->second.moduleType; + if (!moduleTypes.is_initialized()) { + return false; + } + std::transform(moduleTypes->begin(), + moduleTypes->end(), + std::back_inserter(*modules), + ToModuleType()); + return true; +} + +} // namespace policy diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index 6184320306..decf526677 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -127,6 +127,17 @@ uint32_t CacheManager::HeartBeatTimeout(const std::string& app_id) const { return result; } +const policy_table::AppHMITypes* CacheManager::GetHMITypes( + const std::string& app_id) { + const policy_table::ApplicationPolicies& apps = + pt_->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies::const_iterator i = apps.find(app_id); + if (i != apps.end()) { + return &(*i->second.AppHMIType); + } + return NULL; +} + bool CacheManager::CanAppStealFocus(const std::string& app_id) const { CACHE_MANAGER_CHECK(false); bool result = true; @@ -136,8 +147,8 @@ bool CacheManager::CanAppStealFocus(const std::string& app_id) const { bool CacheManager::GetDefaultHMI(const std::string& app_id, std::string& default_hmi) const { CACHE_MANAGER_CHECK(false); - bool result = true; - return result; + default_hmi = "NONE"; + return true; } bool CacheManager::ResetUserConsent() { diff --git a/src/components/policy/policy_regular/src/policy_helper.cc b/src/components/policy/policy_regular/src/policy_helper.cc index b72a041a83..7ee8153e8b 100644 --- a/src/components/policy/policy_regular/src/policy_helper.cc +++ b/src/components/policy/policy_regular/src/policy_helper.cc @@ -802,4 +802,53 @@ bool UnwrapAppPolicies(policy_table::ApplicationPolicies& app_policies) { return true; } + +#ifdef SDL_REMOTE_CONTROL +bool HaveGroupsChanged(const rpc::Optional<policy_table::Strings>& old_groups, + const rpc::Optional<policy_table::Strings>& new_groups) { + if (!old_groups.is_initialized() && !new_groups.is_initialized()) { + return false; + } + if (!old_groups.is_initialized() || !new_groups.is_initialized()) { + return true; + } + policy_table::Strings old_groups_abs = *old_groups; + policy_table::Strings new_groups_abs = *new_groups; + if (old_groups_abs.size() != new_groups_abs.size()) { + return true; + } + std::sort(new_groups_abs.begin(), new_groups_abs.end(), Compare); + std::sort(old_groups_abs.begin(), old_groups_abs.end(), Compare); + + return std::equal(new_groups_abs.begin(), + new_groups_abs.end(), + old_groups_abs.begin(), + Compare); +} + +void ProccessAppGroups::operator()( + const policy_table::ApplicationPolicies::value_type& app) { + policy_table::ApplicationPolicies::const_iterator i = + new_apps_.find(app.first); + if (i == new_apps_.end() && default_ != new_apps_.end()) { + i = default_; + } + if (i != new_apps_.end()) { + if (HaveGroupsChanged(i->second.groups_primaryRC, + app.second.groups_primaryRC)) { + LOG4CXX_DEBUG(logger_, + "Primary groups for " << app.first << " have changed"); + + pm_->OnPrimaryGroupsChanged(app.first); + } + if (HaveGroupsChanged(i->second.groups_nonPrimaryRC, + app.second.groups_nonPrimaryRC)) { + LOG4CXX_DEBUG(logger_, + "Non-primary groups for " << app.first << " have changed"); + pm_->OnNonPrimaryGroupsChanged(app.first); + } + } +} + +#endif // SDL_REMOTE_CONTROL } diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc index f05ac9cb67..562539eb0c 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -51,6 +51,11 @@ #include "utils/timer_task_impl.h" #include "utils/make_shared.h" +#ifdef SDL_REMOTE_CONTROL +#include "policy/access_remote.h" +#include "policy/access_remote_impl.h" +#endif // SDL_REMOTE_CONTROL + policy::PolicyManager* CreateManager() { return new policy::PolicyManagerImpl(); } @@ -71,6 +76,10 @@ PolicyManagerImpl::PolicyManagerImpl() : PolicyManager() , listener_(NULL) , cache_(new CacheManager) +#ifdef SDL_REMOTE_CONTROL + , access_remote_(new AccessRemoteImpl( + CacheManagerInterfaceSPtr::static_pointer_cast<CacheManager>(cache_))) +#endif // SDL_REMOTE_CONTROL , retry_sequence_timeout_(kDefaultRetryTimeoutInMSec) , retry_sequence_index_(0) , timer_retry_sequence_("Retry sequence timer", @@ -80,7 +89,8 @@ PolicyManagerImpl::PolicyManagerImpl() , retry_sequence_url_(0, 0, "") , wrong_ptu_update_received_(false) , send_on_update_sent_out_(false) - , trigger_ptu_(false) {} + , trigger_ptu_(false) { +} void PolicyManagerImpl::set_listener(PolicyListener* listener) { listener_ = listener; @@ -204,6 +214,10 @@ bool PolicyManagerImpl::LoadPT(const std::string& file, listener_->OnCertificateUpdated( *(pt_update->policy_table.module_config.certificate)); } +#ifdef SDL_REMOTE_CONTROL + access_remote_->Init(); + CheckPTUUpdatesChange(pt_update, policy_table_snapshot); +#endif // SDL_REMOTE_CONTROL std::map<std::string, StringArray> app_hmi_types; cache_->GetHMIAppTypeAfterUpdate(app_hmi_types); @@ -381,7 +395,13 @@ void PolicyManagerImpl::CheckPermissions(const PTString& device_id, "CheckPermissions for " << app_id << " and rpc " << rpc << " for " << hmi_level << " level."); +#ifdef SDL_REMOTE_CONTROL + Subject who = {device_id, app_id}; + const policy_table::Strings& groups = access_remote_->GetGroups(who); +#else // SDL_REMOTE_CONTROL const policy_table::Strings& groups = cache_->GetGroups(app_id); +#endif // SDL_REMOTE_CONTROL + cache_->CheckPermissions(groups, hmi_level, rpc, result); if (cache_->IsApplicationRevoked(app_id)) { // SDL must be able to notify mobile side with its status after app has @@ -438,6 +458,17 @@ void PolicyManagerImpl::SendNotificationOnPermissionsUpdated( std::string default_hmi; default_hmi = "NONE"; +#ifdef SDL_REMOTE_CONTROL + const Subject who = {device_id, application_id}; + if (access_remote_->IsAppRemoteControl(who)) { + const std::string rank = + access_remote_->IsPrimaryDevice(who.dev_id) ? "DRIVER" : "PASSENGER"; + UpdateDeviceRank(who, rank); + listener()->OnPermissionsUpdated(application_id, notification_data); + return; + } +#endif // SDL_REMOTE_CONTROL + listener()->OnPermissionsUpdated( application_id, notification_data, default_hmi); } @@ -674,7 +705,16 @@ void PolicyManagerImpl::GetPermissionsForApp( } FunctionalIdType group_types; - if (!cache_->GetPermissionsForApp(device_id, app_id_to_check, group_types)) { +#ifdef SDL_REMOTE_CONTROL + allowed_by_default = false; + bool ret = access_remote_->GetPermissionsForApp( + device_id, policy_app_id, group_types); +#else + bool ret = + cache_->GetPermissionsForApp(device_id, app_id_to_check, group_types); +#endif // REMOTE_CONTROL + + if (!ret) { LOG4CXX_WARN(logger_, "Can't get user permissions for app " << policy_app_id); return; @@ -1020,6 +1060,7 @@ StatusNotifier PolicyManagerImpl::AddApplication( return utils::MakeShared<utils::CallNothing>(); } } + void PolicyManagerImpl::RemoveAppConsentForGroup( const std::string& app_id, const std::string& group_name) { cache_->RemoveAppConsentForGroup(app_id, group_name); @@ -1093,6 +1134,9 @@ bool PolicyManagerImpl::InitPT(const std::string& file_name, if (ret) { RefreshRetrySequence(); update_status_manager_.OnPolicyInit(cache_->UpdateRequired()); +#ifdef SDL_REMOTE_CONTROL + access_remote_->Init(); +#endif // SDL_REMOTE_CONTROL } return ret; } @@ -1127,4 +1171,336 @@ void PolicyManagerImpl::RetrySequence() { timer_retry_sequence_.Start(timeout_msec, timer::kPeriodic); } +#ifdef SDL_REMOTE_CONTROL +void PolicyManagerImpl::SetDefaultHmiTypes(const std::string& application_id, + const std::vector<int>& hmi_types) { + LOG4CXX_INFO(logger_, "SetDefaultHmiTypes"); + const std::string device_id = GetCurrentDeviceId(application_id); + Subject who = {device_id, application_id}; + access_remote_->SetDefaultHmiTypes(who, hmi_types); +} + +struct HMITypeToInt { + int operator()(const policy_table::AppHMITypes::value_type item) { + return policy_table::AppHMIType(item); + } +}; + +bool PolicyManagerImpl::GetHMITypes(const std::string& application_id, + std::vector<int>* app_types) { + LOG4CXX_AUTO_TRACE(logger_); + if (cache_->IsDefaultPolicy(application_id)) { + return false; + } + const policy_table::AppHMITypes* hmi_types = + cache_->GetHMITypes(application_id); + if (hmi_types) { + std::transform(hmi_types->begin(), + hmi_types->end(), + std::back_inserter(*app_types), + HMITypeToInt()); + } + return hmi_types; +} + +TypeAccess PolicyManagerImpl::CheckAccess(const PTString& device_id, + const PTString& app_id, + const PTString& module, + const PTString& rpc, + const RemoteControlParams& params) { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Module type: " << module); + + policy_table::ModuleType module_type; + bool is_valid = EnumFromJsonString(module, &module_type); + if (is_valid && access_remote_->CheckModuleType(app_id, module_type)) { + if (access_remote_->IsPrimaryDevice(device_id)) { + return TypeAccess::kAllowed; + } else { + Subject who = {device_id, app_id}; + Object what = {module_type}; + return CheckDriverConsent(who, what, rpc, params); + } + } + LOG4CXX_DEBUG(logger_, TypeAccess::kDisallowed); + return TypeAccess::kDisallowed; +} + +bool PolicyManagerImpl::CheckModule(const PTString& app_id, + const PTString& module) { + LOG4CXX_AUTO_TRACE(logger_); + policy_table::ModuleType module_type; + return EnumFromJsonString(module, &module_type) && + access_remote_->CheckModuleType(app_id, module_type); +} + +TypeAccess PolicyManagerImpl::CheckDriverConsent( + const Subject& who, + const Object& what, + const std::string& rpc, + const RemoteControlParams& params) { + LOG4CXX_AUTO_TRACE(logger_); + if (!access_remote_->IsEnabled()) { + return TypeAccess::kDisallowed; + } + + return access_remote_->Check(who, what); +} + +void PolicyManagerImpl::SetAccess(const PTString& dev_id, + const PTString& app_id, + const PTString& module, + bool allowed) { + LOG4CXX_AUTO_TRACE(logger_); + policy_table::ModuleType module_type; + bool is_valid = EnumFromJsonString(module, &module_type); + if (!is_valid) { + return; + } + + Subject who = {dev_id, app_id}; + Object what = {module_type}; + LOG4CXX_DEBUG(logger_, + "Driver's consent: " << who << ", " << what << " is " + << std::boolalpha << allowed); + if (allowed) { + access_remote_->Allow(who, what); + } else { + access_remote_->Deny(who, what); + } +} + +void PolicyManagerImpl::ResetAccess(const PTString& dev_id, + const PTString& app_id) { + LOG4CXX_AUTO_TRACE(logger_); + Subject who = {dev_id, app_id}; + access_remote_->Reset(who); +} + +void PolicyManagerImpl::ResetAccess(const PTString& module) { + LOG4CXX_AUTO_TRACE(logger_); + policy_table::ModuleType module_type; + bool is_valid = EnumFromJsonString(module, &module_type); + if (!is_valid) { + return; + } + + Object what = {module_type}; + access_remote_->Reset(what); +} + +void PolicyManagerImpl::SetPrimaryDevice(const PTString& dev_id) { + LOG4CXX_AUTO_TRACE(logger_); + access_remote_->SetPrimaryDevice(dev_id); +} + +void PolicyManagerImpl::ResetPrimaryDevice() { + LOG4CXX_AUTO_TRACE(logger_); + access_remote_->SetPrimaryDevice(""); +} + +PTString PolicyManagerImpl::PrimaryDevice() const { + LOG4CXX_AUTO_TRACE(logger_); + return access_remote_->PrimaryDevice(); +} + +void PolicyManagerImpl::SetRemoteControl(bool enabled) { + LOG4CXX_AUTO_TRACE(logger_); + if (enabled) { + access_remote_->Enable(); + } else { + access_remote_->Disable(); + } +} + +bool PolicyManagerImpl::GetRemoteControl() const { + return access_remote_->IsEnabled(); +} + +void PolicyManagerImpl::OnChangedPrimaryDevice( + const std::string& device_id, const std::string& application_id) { + LOG4CXX_AUTO_TRACE(logger_); + Subject who = {device_id, application_id}; + if (!access_remote_->IsAppRemoteControl(who)) { + LOG4CXX_INFO(logger_, "Application " << who << " isn't remote"); + return; + } + + const std::string rank = + access_remote_->IsPrimaryDevice(who.dev_id) ? "DRIVER" : "PASSENGER"; + UpdateDeviceRank(who, rank); + SendAppPermissionsChanged(who.dev_id, who.app_id); +} + +void PolicyManagerImpl::OnChangedRemoteControl( + const std::string& device_id, const std::string& application_id) { + LOG4CXX_AUTO_TRACE(logger_); + Subject who = {device_id, application_id}; + if (!access_remote_->IsAppRemoteControl(who)) { + LOG4CXX_INFO(logger_, "Application " << who << " isn't remote"); + return; + } + + if (access_remote_->IsPrimaryDevice(who.dev_id)) { + LOG4CXX_INFO(logger_, "Device " << who.dev_id << " is primary"); + return; + } + + if (!access_remote_->IsEnabled()) { + SendHMILevelChanged(who); + } + + SendAppPermissionsChanged(who.dev_id, who.app_id); +} + +void PolicyManagerImpl::UpdateDeviceRank(const Subject& who, + const std::string& rank) { + std::string default_hmi("NONE"); + if (GetDefaultHmi(who.app_id, &default_hmi)) { + access_remote_->Reset(who); + listener()->OnUpdateHMIStatus(who.dev_id, who.app_id, default_hmi, rank); + } else { + LOG4CXX_WARN(logger_, + "Couldn't get default HMI level for application " + << who.app_id); + } +} + +void PolicyManagerImpl::SendHMILevelChanged(const Subject& who) { + std::string default_hmi("NONE"); + if (GetDefaultHmi(who.app_id, &default_hmi)) { + access_remote_->Reset(who); + listener()->OnUpdateHMIStatus(who.dev_id, who.app_id, default_hmi); + } else { + LOG4CXX_WARN(logger_, + "Couldn't get default HMI level for application " + << who.app_id); + } +} + +void PolicyManagerImpl::GetPermissions(const std::string device_id, + const std::string application_id, + Permissions* data) { + LOG4CXX_AUTO_TRACE(logger_); + DCHECK(data); + std::vector<FunctionalGroupPermission> app_group_permissions; + GetPermissionsForApp(device_id, application_id, app_group_permissions); + + policy_table::FunctionalGroupings functional_groupings; + cache_->GetFunctionalGroupings(functional_groupings); + + policy_table::Strings app_groups; + std::vector<FunctionalGroupPermission>::const_iterator it = + app_group_permissions.begin(); + std::vector<FunctionalGroupPermission>::const_iterator it_end = + app_group_permissions.end(); + for (; it != it_end; ++it) { + app_groups.push_back((*it).group_name); + } + + PrepareNotificationData( + functional_groupings, app_groups, app_group_permissions, *data); +} + +void PolicyManagerImpl::SendAppPermissionsChanged( + const std::string& device_id, const std::string& application_id) { + Permissions notification_data; + GetPermissions(device_id, application_id, ¬ification_data); + listener()->OnPermissionsUpdated(application_id, notification_data); +} + +void PolicyManagerImpl::CheckPTUUpdatesChange( + const utils::SharedPtr<policy_table::Table> pt_update, + const utils::SharedPtr<policy_table::Table> snapshot) { + CheckPTURemoteCtrlChange(pt_update, snapshot); + CheckRemoteGroupsChange(pt_update, snapshot); +} + +bool PolicyManagerImpl::CheckPTURemoteCtrlChange( + const utils::SharedPtr<policy_table::Table> pt_update, + const utils::SharedPtr<policy_table::Table> snapshot) { + LOG4CXX_AUTO_TRACE(logger_); + + rpc::Optional<rpc::Boolean>& new_consent = + pt_update->policy_table.module_config.country_consent_passengersRC; + rpc::Optional<rpc::Boolean>& old_consent = + snapshot->policy_table.module_config.country_consent_passengersRC; + + if (!new_consent.is_initialized() && !old_consent.is_initialized()) { + return false; + } + + bool result = false; + if (new_consent.is_initialized() && old_consent.is_initialized()) { + result = (*new_consent != *old_consent); + } else { + bool not_changed_consent1 = !new_consent.is_initialized() && *old_consent; + bool not_changed_consent2 = !old_consent.is_initialized() && *new_consent; + + result = !(not_changed_consent1 || not_changed_consent2); + } + + if (result) { + listener()->OnRemoteAllowedChanged(result); + } + + return result; +} + +void PolicyManagerImpl::CheckRemoteGroupsChange( + const utils::SharedPtr<policy_table::Table> pt_update, + const utils::SharedPtr<policy_table::Table> snapshot) { + LOG4CXX_AUTO_TRACE(logger_); + + policy_table::ApplicationPolicies& new_apps = + pt_update->policy_table.app_policies_section.apps; + policy_table::ApplicationPolicies& old_apps = + snapshot->policy_table.app_policies_section.apps; + std::for_each( + old_apps.begin(), old_apps.end(), ProccessAppGroups(new_apps, this)); +} + +void PolicyManagerImpl::OnPrimaryGroupsChanged( + const std::string& application_id) { + const std::vector<std::string> devices = + listener()->GetDevicesIds(application_id); + for (std::vector<std::string>::const_iterator i = devices.begin(); + i != devices.end(); + ++i) { + const Subject who = {*i, application_id}; + if (access_remote_->IsAppRemoteControl(who) && + access_remote_->IsPrimaryDevice(who.dev_id)) { + SendAppPermissionsChanged(who.dev_id, who.app_id); + } + } +} + +void PolicyManagerImpl::OnNonPrimaryGroupsChanged( + const std::string& application_id) { + const std::vector<std::string> devices = + listener()->GetDevicesIds(application_id); + for (std::vector<std::string>::const_iterator i = devices.begin(); + i != devices.end(); + ++i) { + const Subject who = {*i, application_id}; + if (access_remote_->IsAppRemoteControl(who) && + !access_remote_->IsPrimaryDevice(who.dev_id) && + access_remote_->IsEnabled()) { + SendAppPermissionsChanged(who.dev_id, who.app_id); + } + } +} + +bool PolicyManagerImpl::GetModuleTypes( + const std::string& application_id, + std::vector<std::string>* modules) const { + return access_remote_->GetModuleTypes(application_id, modules); +} + +void PolicyManagerImpl::set_access_remote( + utils::SharedPtr<AccessRemote> access_remote) { + access_remote_ = access_remote; +} +#endif // SDL_REMOTE_CONTROL + } // namespace policy diff --git a/src/components/policy/policy_regular/src/policy_table/enums.cc b/src/components/policy/policy_regular/src/policy_table/enums.cc index 6de065148a..e0f77be989 100644 --- a/src/components/policy/policy_regular/src/policy_table/enums.cc +++ b/src/components/policy/policy_regular/src/policy_table/enums.cc @@ -326,6 +326,8 @@ bool IsValidEnum(AppHMIType val) { return true; case AHT_PROJECTION: return true; + case AHT_REMOTE_CONTROL: + return true; default: return false; } @@ -354,6 +356,8 @@ const char* EnumToJsonString(AppHMIType val) { return "SYSTEM"; case AHT_PROJECTION: return "PROJECTION"; + case AHT_REMOTE_CONTROL: + return "REMOTE_CONTROL"; default: return ""; } @@ -392,6 +396,9 @@ bool EnumFromJsonString(const std::string& literal, AppHMIType* result) { } else if ("PROJECTION" == literal) { *result = AHT_PROJECTION; return true; + } else if ("REMOTE_CONTROL" == literal) { + *result = AHT_REMOTE_CONTROL; + return true; } else { return false; } @@ -576,6 +583,41 @@ bool EnumFromJsonString(const std::string& literal, RequestType* result) { } } +#ifdef SDL_REMOTE_CONTROL +bool IsValidEnum(ModuleType val) { + switch (val) { + case MT_CLIMATE: + return true; + case MT_RADIO: + return true; + default: + return false; + } +} +const char* EnumToJsonString(ModuleType val) { + switch (val) { + case MT_CLIMATE: + return "CLIMATE"; + case MT_RADIO: + return "RADIO"; + default: + return ""; + } +} + +bool EnumFromJsonString(const std::string& literal, ModuleType* result) { + if ("CLIMATE" == literal) { + *result = MT_CLIMATE; + return true; + } else if ("RADIO" == literal) { + *result = MT_RADIO; + return true; + } else { + return false; + } +} +#endif // SDL_REMOTE_CONTROL + const std::string kDefaultApp = "default"; const std::string kPreDataConsentApp = "pre_DataConsent"; const std::string kDeviceApp = "device"; diff --git a/src/components/policy/policy_regular/src/policy_table/types.cc b/src/components/policy/policy_regular/src/policy_table/types.cc index 7928973919..2c445d4bff 100644 --- a/src/components/policy/policy_regular/src/policy_table/types.cc +++ b/src/components/policy/policy_regular/src/policy_table/types.cc @@ -166,7 +166,14 @@ ApplicationParams::ApplicationParams(const Json::Value* value__) , RequestType(impl::ValueMember(value__, "RequestType")) , memory_kb(impl::ValueMember(value__, "memory_kb"), 0) , heart_beat_timeout_ms(impl::ValueMember(value__, "heart_beat_timeout_ms")) - , certificate(impl::ValueMember(value__, "certificate"), "not_specified") {} + , certificate(impl::ValueMember(value__, "certificate"), "not_specified") +#ifdef SDL_REMOTE_CONTROL + , groups_primaryRC(impl::ValueMember(value__, "groups_primaryRC")) + , groups_nonPrimaryRC(impl::ValueMember(value__, "groups_nonPrimaryRC")) + , moduleType(impl::ValueMember(value__, "moduleType")) +#endif // SDL_REMOTE_CONTROL +{ +} Json::Value ApplicationParams::ToJsonValue() const { Json::Value result__(PolicyBase::ToJsonValue()); @@ -177,6 +184,11 @@ Json::Value ApplicationParams::ToJsonValue() const { impl::WriteJsonField("memory_kb", memory_kb, &result__); impl::WriteJsonField( "heart_beat_timeout_ms", heart_beat_timeout_ms, &result__); +#ifdef SDL_REMOTE_CONTROL + impl::WriteJsonField("groups_primaryRC", groups_primaryRC, &result__); + impl::WriteJsonField("groups_nonPrimaryRC", groups_nonPrimaryRC, &result__); + impl::WriteJsonField("moduleType", moduleType, &result__); +#endif // SDL_REMOTE_CONTROL return result__; } @@ -204,6 +216,17 @@ bool ApplicationParams::is_valid() const { if (!certificate.is_valid()) { return false; } +#ifdef SDL_REMOTE_CONTROL + if (!groups_primaryRC.is_valid()) { + return false; + } + if (!groups_nonPrimaryRC.is_valid()) { + return false; + } + if (!moduleType.is_valid()) { + return false; + } +#endif // SDL_REMOTE_CONTROL return Validate(); } @@ -236,6 +259,17 @@ bool ApplicationParams::struct_empty() const { if (certificate.is_initialized()) { return false; } +#ifdef SDL_REMOTE_CONTROL + if (groups_primaryRC.is_initialized()) { + return false; + } + if (groups_nonPrimaryRC.is_initialized()) { + return false; + } + if (moduleType.is_initialized()) { + return false; + } +#endif // SDL_REMOTE_CONTROL return true; } @@ -268,6 +302,19 @@ void ApplicationParams::ReportErrors(rpc::ValidationReport* report__) const { if (!certificate.is_valid()) { certificate.ReportErrors(&report__->ReportSubobject("certificate")); } +#ifdef SDL_REMOTE_CONTROL + if (!groups_primaryRC.is_valid()) { + groups_primaryRC.ReportErrors( + &report__->ReportSubobject("groups_primaryRC")); + } + if (!groups_nonPrimaryRC.is_valid()) { + groups_nonPrimaryRC.ReportErrors( + &report__->ReportSubobject("groups_nonPrimaryRC")); + } + if (!moduleType.is_valid()) { + moduleType.ReportErrors(&report__->ReportSubobject("moduleType")); + } +#endif // SDL_REMOTE_CONTROL } void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) { @@ -278,6 +325,11 @@ void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) { memory_kb.SetPolicyTableType(pt_type); heart_beat_timeout_ms.SetPolicyTableType(pt_type); certificate.SetPolicyTableType(pt_type); +#ifdef SDL_REMOTE_CONTROL + groups_primaryRC.SetPolicyTableType(pt_type); + groups_nonPrimaryRC.SetPolicyTableType(pt_type); + moduleType.SetPolicyTableType(pt_type); +#endif // SDL_REMOTE_CONTROL } // RpcParameters methods @@ -430,7 +482,15 @@ ModuleConfig::ModuleConfig(const Json::Value* value__) , vehicle_model(impl::ValueMember(value__, "vehicle_model")) , vehicle_year(impl::ValueMember(value__, "vehicle_year")) , preloaded_date(impl::ValueMember(value__, "preloaded_date")) - , certificate(impl::ValueMember(value__, "certificate")) {} + , certificate(impl::ValueMember(value__, "certificate")) +#ifdef SDL_REMOTE_CONTROL + , user_consent_passengersRC( + impl::ValueMember(value__, "user_consent_passengersRC")) + , country_consent_passengersRC( + impl::ValueMember(value__, "country_consent_passengersRC")) +#endif // SDL_REMOTE_CONTROL +{ +} void ModuleConfig::SafeCopyFrom(const ModuleConfig& from) { // device_certificates = from.device_certificates; // According to the @@ -448,6 +508,11 @@ void ModuleConfig::SafeCopyFrom(const ModuleConfig& from) { vehicle_model.assign_if_valid(from.vehicle_model); vehicle_year.assign_if_valid(from.vehicle_year); certificate.assign_if_valid(from.certificate); +#ifdef SDL_REMOTE_CONTROL + user_consent_passengersRC.assign_if_valid(from.user_consent_passengersRC); + country_consent_passengersRC.assign_if_valid( + from.country_consent_passengersRC); +#endif // SDL_REMOTE_CONTROL } Json::Value ModuleConfig::ToJsonValue() const { @@ -473,6 +538,12 @@ Json::Value ModuleConfig::ToJsonValue() const { impl::WriteJsonField("vehicle_year", vehicle_year, &result__); impl::WriteJsonField("certificate", certificate, &result__); impl::WriteJsonField("preloaded_date", preloaded_date, &result__); +#ifdef SDL_REMOTE_CONTROL + impl::WriteJsonField( + "user_consent_passengersRC", user_consent_passengersRC, &result__); + impl::WriteJsonField( + "country_consent_passengersRC", country_consent_passengersRC, &result__); +#endif // SDL_REMOTE_CONTROL return result__; } bool ModuleConfig::is_valid() const { @@ -515,6 +586,14 @@ bool ModuleConfig::is_valid() const { if (!preloaded_date.is_valid()) { return false; } +#ifdef SDL_REMOTE_CONTROL + if (!user_consent_passengersRC.is_valid()) { + return false; + } + if (!country_consent_passengersRC.is_valid()) { + return false; + } +#endif // SDL_REMOTE_CONTROL return Validate(); } bool ModuleConfig::is_initialized() const { @@ -559,7 +638,14 @@ bool ModuleConfig::struct_empty() const { if (vehicle_year.is_initialized()) { return false; } - +#ifdef SDL_REMOTE_CONTROL + if (user_consent_passengersRC.is_initialized()) { + return false; + } + if (country_consent_passengersRC.is_initialized()) { + return false; + } +#endif // SDL_REMOTE_CONTROL return true; } void ModuleConfig::ReportErrors(rpc::ValidationReport* report__) const { @@ -609,6 +695,16 @@ void ModuleConfig::ReportErrors(rpc::ValidationReport* report__) const { if (!vehicle_year.is_valid()) { vehicle_year.ReportErrors(&report__->ReportSubobject("vehicle_year")); } +#ifdef SDL_REMOTE_CONTROL + if (!user_consent_passengersRC.is_valid()) { + user_consent_passengersRC.ReportErrors( + &report__->ReportSubobject("user_consent_passengersRC")); + } + if (!country_consent_passengersRC.is_valid()) { + country_consent_passengersRC.ReportErrors( + &report__->ReportSubobject("country_consent_passengersRC")); + } +#endif // SDL_REMOTE_CONTROL if (PT_PRELOADED == GetPolicyTableType()) { std::string validation_info = omitted_validation_info + PolicyTableTypeToString(GetPolicyTableType()); @@ -625,6 +721,13 @@ void ModuleConfig::ReportErrors(rpc::ValidationReport* report__) const { omitted_field_report = &report__->ReportSubobject("vehicle_model"); omitted_field_report->set_validation_info(validation_info); } +#ifdef SDL_REMOTE_CONTROL + if (user_consent_passengersRC.is_initialized()) { + omitted_field_report = + &report__->ReportSubobject("user_consent_passengersRC"); + omitted_field_report->set_validation_info(validation_info); + } +#endif // SDL_REMOTE_CONTROL } } @@ -641,6 +744,10 @@ void ModuleConfig::SetPolicyTableType(PolicyTableType pt_type) { vehicle_make.SetPolicyTableType(pt_type); vehicle_model.SetPolicyTableType(pt_type); vehicle_year.SetPolicyTableType(pt_type); +#ifdef SDL_REMOTE_CONTROL + user_consent_passengersRC.SetPolicyTableType(pt_type); + country_consent_passengersRC.SetPolicyTableType(pt_type); +#endif // SDL_REMOTE_CONTROL } // MessageString methods diff --git a/src/components/policy/policy_regular/src/policy_table/validation.cc b/src/components/policy/policy_regular/src/policy_table/validation.cc index 18a30d9f77..10b8e4bf7c 100644 --- a/src/components/policy/policy_regular/src/policy_table/validation.cc +++ b/src/components/policy/policy_regular/src/policy_table/validation.cc @@ -114,14 +114,46 @@ bool ApplicationPoliciesSection::Validate() const { return true; } -bool ApplicationParams::Validate() const { - // Check for empty "groups" sub-sections - if (groups.empty()) { - return false; +#ifdef SDL_REMOTE_CONTROL +bool ApplicationParams::ValidateModuleTypes() const { + // moduleType is optional so see Optional<T>::is_valid() + bool is_initialized = moduleType->is_initialized(); + if (!is_initialized) { + // valid if not initialized + return true; + } + bool is_valid = moduleType->is_valid(); + if (is_valid) { + return true; + } + + struct IsInvalid { + bool operator()(Enum<ModuleType> item) const { + return !item.is_valid(); + } + }; + // cut invalid items + moduleType->erase( + std::remove_if(moduleType->begin(), moduleType->end(), IsInvalid()), + moduleType->end()); + bool empty = moduleType->empty(); + if (empty) { + // set non initialized value + ModuleTypes non_initialized; + moduleType = Optional<ModuleTypes>(non_initialized); } return true; } +bool ApplicationParams::Validate() const { + return ValidateModuleTypes(); +} +#else // SDL_REMOTE_CONTROL +bool ApplicationParams::Validate() const { + return true; +} +#endif // SDL_REMOTE_CONTROL + bool RpcParameters::Validate() const { return true; } diff --git a/src/components/policy/policy_regular/src/sql_pt_queries.cc b/src/components/policy/policy_regular/src/sql_pt_queries.cc index df4bc74cc2..d573e79816 100644 --- a/src/components/policy/policy_regular/src/sql_pt_queries.cc +++ b/src/components/policy/policy_regular/src/sql_pt_queries.cc @@ -71,7 +71,9 @@ const std::string kCreateSchema = " `certificate` TEXT, " " `vehicle_make` VARCHAR(45), " " `vehicle_model` VARCHAR(45), " - " `vehicle_year` VARCHAR(4) " + " `vehicle_year` VARCHAR(4), " + " `user_consent_passengersRC` BOOL, " + " `country_consent_passengersRC` BOOL " "); " "CREATE TABLE IF NOT EXISTS `functional_group`( " " `id` INTEGER PRIMARY KEY NOT NULL, " @@ -134,6 +136,7 @@ const std::string kCreateSchema = " `memory_kb` INTEGER NOT NULL, " " `heart_beat_timeout_ms` INTEGER NOT NULL, " " `certificate` VARCHAR(45), " + " `remote_control_denied` BOOLEAN NOT NULL DEFAULT 0, " " CONSTRAINT `fk_application_hmi_level1` " " FOREIGN KEY(`default_hmi`) " " REFERENCES `hmi_level`(`value`), " @@ -316,6 +319,78 @@ const std::string kCreateSchema = " FOREIGN KEY(`message_type_name`) " " REFERENCES `message_type`(`name`) " "); " + + "CREATE TABLE IF NOT EXISTS `app_group_primary`( " + " `application_id` VARCHAR(45) NOT NULL, " + " `functional_group_id` INTEGER NOT NULL, " + " PRIMARY KEY(`application_id`,`functional_group_id`), " + " CONSTRAINT `fk_application_has_functional_group_application1` " + " FOREIGN KEY(`application_id`) " + " REFERENCES `application`(`id`), " + " CONSTRAINT `fk_application_has_functional_group_functional_group1` " + " FOREIGN KEY(`functional_group_id`) " + " REFERENCES `functional_group`(`id`) " + "); " + "CREATE INDEX IF NOT EXISTS " + "`app_group_primary.fk_application_has_functional_group_functional_group1_" + "idx` " + " ON `app_group_primary`(`functional_group_id`); " + "CREATE INDEX IF NOT EXISTS " + "`app_group_primary.fk_application_has_functional_group_application1_idx` " + " ON `app_group_primary`(`application_id`); " + + "CREATE TABLE IF NOT EXISTS `app_group_non_primary`( " + " `application_id` VARCHAR(45) NOT NULL, " + " `functional_group_id` INTEGER NOT NULL, " + " PRIMARY KEY(`application_id`,`functional_group_id`), " + " CONSTRAINT `fk_application_has_functional_group_application1` " + " FOREIGN KEY(`application_id`) " + " REFERENCES `application`(`id`), " + " CONSTRAINT `fk_application_has_functional_group_functional_group1` " + " FOREIGN KEY(`functional_group_id`) " + " REFERENCES `functional_group`(`id`) " + "); " + "CREATE INDEX IF NOT EXISTS " + "`app_group_non_primary.fk_application_has_functional_group_functional_" + "group1_idx` " + " ON `app_group_non_primary`(`functional_group_id`); " + "CREATE INDEX IF NOT EXISTS " + "`app_group_non_primary.fk_application_has_functional_group_application1_" + "idx` " + " ON `app_group_non_primary`(`application_id`); " + + /* access_module */ + "CREATE TABLE `access_module`( " + " `id` INTEGER PRIMARY KEY NOT NULL, " + " `name` VARCHAR(45) NOT NULL, " + " `user_consent_needed` INTEGER NOT NULL " + "); " + + /* remote_rpc */ + "CREATE TABLE `remote_rpc`( " + " `id` INTEGER PRIMARY KEY NOT NULL, " + " `name` VARCHAR(255) NOT NULL, " + " `parameter` VARCHAR(45), " + " `module_id` INTEGER NOT NULL, " + "CONSTRAINT `fk_remote_rpc_1` " + " FOREIGN KEY(`module_id`) " + " REFERENCES `access_module`(`id`) " + "); " + "CREATE INDEX `remote_rpc.fk_remote_rpc_1_idx` ON " + "`remote_rpc`(`module_id`); " + + /* module type */ + "CREATE TABLE IF NOT EXISTS `module_type`( " + " `name` VARCHAR(50) NOT NULL, " + " `application_id` VARCHAR(45) NOT NULL, " + " PRIMARY KEY(`name`,`application_id`), " + " CONSTRAINT `fk_module_type_application1` " + " FOREIGN KEY(`application_id`) " + " REFERENCES `application`(`id`) " + "); " + "CREATE INDEX IF NOT EXISTS `module_type.fk_module_type_application1_idx` " + " ON `module_type`(`application_id`); " + "CREATE INDEX IF NOT EXISTS `message.fk_messages_languages1_idx` " " ON `message`(`language_code`);" "CREATE INDEX IF NOT EXISTS " @@ -353,8 +428,79 @@ const std::string kInsertInitData = "INSERT OR IGNORE INTO `_internal_data` (`db_version_hash`) VALUES(0); " ""; +const std::string kDeleteAppGroupPrimary = "DELETE FROM `app_group_primary`"; + +const std::string kDeleteAppGroupNonPrimary = + "DELETE FROM `app_group_non_primary`"; + +const std::string kDeleteModuleTypes = "DELETE FROM `module_type`"; + +const std::string kDeleteAllDevices = "DELETE FROM `device`;"; + +const std::string kSelectAppGroupsPrimary = + "SELECT `f`.`name` FROM `app_group_primary` AS `a`" + " LEFT JOIN `functional_group` AS `f` " + " ON (`f`.`id` = `a`.`functional_group_id`)" + " WHERE `a`.`application_id` = ?"; + +const std::string kSelectAppGroupsNonPrimary = + "SELECT `f`.`name` FROM `app_group_non_primary` AS `a`" + " LEFT JOIN `functional_group` AS `f` " + " ON (`f`.`id` = `a`.`functional_group_id`)" + " WHERE `a`.`application_id` = ?"; + +const std::string kSelectRemoteControlDenied = + "SELECT `remote_control_denied` FROM `application` WHERE `id` = ? LIMIT 1"; + +const std::string kInsertAppGroupPrimary = + "INSERT INTO `app_group_primary` (`application_id`, `functional_group_id`)" + " SELECT ?, `id` FROM `functional_group` WHERE `name` = ? LIMIT 1"; + +const std::string kInsertAppGroupNonPrimary = + "INSERT INTO `app_group_non_primary` (`application_id`, " + "`functional_group_id`)" + " SELECT ?, `id` FROM `functional_group` WHERE `name` = ? LIMIT 1"; + +const std::string kUpdateRemoteControlDenied = + "UPDATE `application` SET `remote_control_denied` = ? WHERE `id` = ?"; + +const std::string kDeleteAccessModules = "DELETE FROM `access_module`"; + +const std::string kDeleteRemoteRpc = "DELETE FROM `remote_rpc`"; + +const std::string kInsertAccessModule = + "INSERT INTO `access_module` (`name`, `user_consent_needed`) " + " VALUES(?, ?, ?)"; + +const std::string kDeleteAppGroupPrimaryByApplicationId = + "DELETE FROM `app_group_primary` WHERE `application_id` = ?"; + +const std::string kDeleteAppGroupNonPrimaryByApplicationId = + "DELETE FROM `app_group_non_primary` WHERE `application_id` = ?"; + +const std::string kSelectAccessModules = + "SELECT `id`, `name` FROM `access_module` " + " WHERE `user_consent_needed` = ?"; + +const std::string kInsertRemoteRpc = + "INSERT INTO `remote_rpc` (`module_id`, `name`, `parameter`) " + " VALUES(?, ?, ?)"; + +const std::string kSelectRemoteRpcs = + "SELECT `name`, `parameter` FROM `remote_rpc` " + " WHERE `module_id` = ?"; + +const std::string kInsertModuleType = + "INSERT OR IGNORE INTO `module_type` (`application_id`, `name`) VALUES (?, " + "?)"; + +const std::string kSelectModuleTypes = + "SELECT DISTINCT `name` FROM `module_type` WHERE `application_id` = ?"; + const std::string kDropSchema = "BEGIN; " + "DROP INDEX IF EXISTS `module_type.fk_module_type_application1_idx`; " + "DROP TABLE IF EXISTS `module_type`; " "DROP INDEX IF EXISTS `message.fk_messages_languages1_idx`; " "DROP INDEX IF EXISTS " "`message.fk_message_consumer_friendly_messages1_idx`; " @@ -388,6 +534,21 @@ const std::string kDropSchema = "idx`; " "DROP TABLE IF EXISTS `preconsented_group`; " "DROP INDEX IF EXISTS " + "`app_group_primary.fk_application_has_functional_group_application1_idx`; " + "DROP INDEX IF EXISTS " + "`app_group_primary.fk_application_has_functional_group_functional_group1_" + "idx`; " + "DROP TABLE IF EXISTS `app_group_primary`; " + "DROP INDEX IF EXISTS " + "`app_group_non_primary.fk_application_has_functional_group_application1_" + "idx`; " + "DROP INDEX IF EXISTS " + "`app_group_non_primary.fk_application_has_functional_group_functional_" + "group1_idx`; " + "DROP TABLE IF EXISTS `app_group_non_primary`; " + "DROP TABLE IF EXISTS `access_module`; " + "DROP INDEX IF EXISTS `access_module.fk_module_1_idx`; " + "DROP INDEX IF EXISTS " "`app_group.fk_application_has_functional_group_application1_idx`; " "DROP INDEX IF EXISTS " "`app_group.fk_application_has_functional_group_functional_group1_idx`; " @@ -409,6 +570,8 @@ const std::string kDropSchema = "DROP TABLE IF EXISTS `priority`; " "DROP TABLE IF EXISTS `functional_group`; " "DROP TABLE IF EXISTS `module_config`; " + "DROP TABLE IF EXISTS `remote_rpc`; " + "DROP INDEX IF EXISTS `remote_rpc.fk_remote_rpc_1_idx`; " "DROP TABLE IF EXISTS `module_meta`; " "DROP TABLE IF EXISTS `usage_and_error_count`; " "DROP TABLE IF EXISTS `device`; " @@ -419,6 +582,7 @@ const std::string kDropSchema = const std::string kDeleteData = "BEGIN; " "DELETE FROM `message`; " + "DELETE FROM `module_type`; " "DELETE FROM `endpoint`; " "DELETE FROM `consent_group`; " "DELETE FROM `app_type`; " @@ -430,6 +594,9 @@ const std::string kDeleteData = "DELETE FROM `app_group`; " "DELETE FROM `application`; " "DELETE FROM `rpc`; " + "DELETE FROM `app_group_primary`; " + "DELETE FROM `app_group_non_primary`; " + "DELETE FROM `access_module`; " "DELETE FROM `version`; " "DELETE FROM `message_type`; " "DELETE FROM `language`; " @@ -439,6 +606,7 @@ const std::string kDeleteData = "DELETE FROM `functional_group`; " "DELETE FROM `module_config`; " "DELETE FROM `module_meta`; " + "DELETE FROM `remote_rpc`; " "DELETE FROM `usage_and_error_count`; " "DELETE FROM `device`; " "COMMIT; " @@ -522,7 +690,8 @@ const std::string kUpdateModuleConfig = " `exchange_after_x_ignition_cycles` = ?," " `exchange_after_x_kilometers` = ?, `exchange_after_x_days` = ?, " " `timeout_after_x_seconds` = ?, `certificate` = ?, `vehicle_make` = ?, " - " `vehicle_model` = ?, `vehicle_year` = ?"; + " `vehicle_model` = ?, `vehicle_year` = ?, " + " `user_consent_passengersRC` = ?, `country_consent_passengersRC` = ?"; const std::string kInsertEndpoint = "INSERT INTO `endpoint` (`service`, `url`, `application_id`) " @@ -562,7 +731,8 @@ const std::string kSelectModuleConfig = "SELECT `preloaded_pt`, `exchange_after_x_ignition_cycles`, " " `exchange_after_x_kilometers`, `exchange_after_x_days`, " " `timeout_after_x_seconds`, `certificate`, `vehicle_make`," - " `vehicle_model`, `vehicle_year` " + " `vehicle_model`, `vehicle_year`, " + " `user_consent_passengersRC` , `country_consent_passengersRC` " " FROM `module_config`"; const std::string kSelectEndpoints = 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 e94c853414..854b6e4804 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -526,6 +526,12 @@ void SQLPTRepresentation::GatherModuleConfig( *config->vehicle_model = query.GetString(7); *config->vehicle_year = query.GetString(8); *config->preloaded_date = query.GetString(9); +#ifdef SDL_REMOTE_CONTROL + *config->user_consent_passengersRC = + query.IsNull(8) ? true : query.GetBoolean(8); + *config->country_consent_passengersRC = + query.IsNull(9) ? true : query.GetBoolean(9); +#endif // SDL_REMOTE_CONTROL } utils::dbms::SQLQuery endpoints(db()); @@ -705,6 +711,23 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection( if (!GatherAppGroup(app_id, ¶ms.groups)) { return false; } +#ifdef SDL_REMOTE_CONTROL + if (!GatherAppGroupPrimary(app_id, &*params.groups_primaryRC)) { + return false; + } + if (!GatherAppGroupNonPrimary(app_id, &*params.groups_nonPrimaryRC)) { + return false; + } + bool denied = false; + if (!GatherRemoteControlDenied(app_id, &denied)) { + return false; + } + if (!denied) { + if (!GatherModuleType(app_id, &*params.moduleType)) { + return false; + } + } +#endif // SDL_REMOTE_CONTROL if (!GatherNickName(app_id, &*params.nicknames)) { return false; } @@ -859,6 +882,20 @@ bool SQLPTRepresentation::SaveApplicationPoliciesSection( LOG4CXX_WARN(logger_, "Incorrect delete from app_group."); return false; } +#ifdef SDL_REMOTE_CONTROL + if (!query_delete.Exec(sql_pt::kDeleteAppGroupPrimary)) { + LOG4CXX_WARN(logger_, "Incorrect delete from app_group_primary."); + return false; + } + if (!query_delete.Exec(sql_pt::kDeleteAppGroupNonPrimary)) { + LOG4CXX_WARN(logger_, "Incorrect delete from app_group_non_primary."); + return false; + } + if (!query_delete.Exec(sql_pt::kDeleteModuleTypes)) { + LOG4CXX_WARN(logger_, "Incorrect delete from module_type."); + return false; + } +#endif // SDL_REMOTE_CONTROL if (!query_delete.Exec(sql_pt::kDeleteApplication)) { LOG4CXX_WARN(logger_, "Incorrect delete from application."); return false; @@ -941,6 +978,20 @@ bool SQLPTRepresentation::SaveSpecificAppPolicy( if (!SaveAppGroup(app.first, app.second.groups)) { return false; } +#ifdef SDL_REMOTE_CONTROL + if (!SaveAppGroupPrimary(app.first, *app.second.groups_primaryRC)) { + return false; + } + if (!SaveAppGroupNonPrimary(app.first, *app.second.groups_nonPrimaryRC)) { + return false; + } + + bool denied = !app.second.moduleType->is_initialized(); + if (!SaveRemoteControlDenied(app.first, denied) || + !SaveModuleType(app.first, *app.second.moduleType)) { + return false; + } +#endif // SDL_REMOTE_CONTROL if (!SaveNickname(app.first, *app.second.nicknames)) { return false; } @@ -1111,7 +1162,14 @@ bool SQLPTRepresentation::SaveModuleConfig( : query.Bind(7); config.vehicle_year.is_initialized() ? query.Bind(8, *(config.vehicle_year)) : query.Bind(8); - +#ifdef SDL_REMOTE_CONTROL + config.user_consent_passengersRC.is_initialized() + ? query.Bind(9, *(config.user_consent_passengersRC)) + : query.Bind(9); + config.country_consent_passengersRC.is_initialized() + ? query.Bind(10, *(config.country_consent_passengersRC)) + : query.Bind(10); +#endif // SDL_REMOTE_CONTROL if (!query.Exec()) { LOG4CXX_WARN(logger_, "Incorrect update module config"); return false; @@ -1506,6 +1564,280 @@ bool SQLPTRepresentation::GatherAppGroup( return true; } +#ifdef SDL_REMOTE_CONTROL +bool SQLPTRepresentation::GatherAppGroupPrimary( + const std::string& app_id, policy_table::Strings* app_groups) const { + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kSelectAppGroupsPrimary)) { + LOG4CXX_WARN(logger_, "Incorrect select from app groups for primary RC"); + return false; + } + + query.Bind(0, app_id); + while (query.Next()) { + app_groups->push_back(query.GetString(0)); + } + return true; +} + +bool SQLPTRepresentation::GatherAppGroupNonPrimary( + const std::string& app_id, policy_table::Strings* app_groups) const { + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kSelectAppGroupsNonPrimary)) { + LOG4CXX_WARN(logger_, + "Incorrect select from app groups for non primary RC"); + return false; + } + + query.Bind(0, app_id); + while (query.Next()) { + app_groups->push_back(query.GetString(0)); + } + return true; +} + +bool SQLPTRepresentation::GatherRemoteControlDenied(const std::string& app_id, + bool* denied) const { + LOG4CXX_AUTO_TRACE(logger_); + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kSelectRemoteControlDenied)) { + LOG4CXX_WARN(logger_, "Incorrect select remote control flag"); + return false; + } + query.Bind(0, app_id); + if (query.Next()) { + *denied = query.GetBoolean(0); + } else { + return false; + } + return true; +} + +bool SQLPTRepresentation::GatherModuleType( + const std::string& app_id, policy_table::ModuleTypes* app_types) const { + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kSelectModuleTypes)) { + LOG4CXX_WARN(logger_, "Incorrect select from app types"); + return false; + } + + query.Bind(0, app_id); + while (query.Next()) { + policy_table::ModuleType type; + if (!policy_table::EnumFromJsonString(query.GetString(0), &type)) { + return false; + } + app_types->push_back(type); + } + return true; +} + +bool SQLPTRepresentation::SaveAppGroupPrimary( + const std::string& app_id, const policy_table::Strings& app_groups) { + LOG4CXX_AUTO_TRACE(logger_); + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertAppGroupPrimary)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for app group primary"); + return false; + } + policy_table::Strings::const_iterator it; + for (it = app_groups.begin(); it != app_groups.end(); ++it) { + std::string ssss = *it; + LOG4CXX_INFO(logger_, "Group: " << ssss); + query.Bind(0, app_id); + query.Bind(1, *it); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, + "Incorrect insert into app group primary." + << query.LastError().text()); + return false; + } + } + + return true; +} + +bool SQLPTRepresentation::SaveAppGroupNonPrimary( + const std::string& app_id, const policy_table::Strings& app_groups) { + LOG4CXX_AUTO_TRACE(logger_); + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertAppGroupNonPrimary)) { + LOG4CXX_WARN(logger_, + "Incorrect insert statement for app group non primary"); + return false; + } + policy_table::Strings::const_iterator it; + for (it = app_groups.begin(); it != app_groups.end(); ++it) { + std::string ssss = *it; + LOG4CXX_INFO(logger_, "Group: " << ssss); + query.Bind(0, app_id); + query.Bind(1, *it); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, + "Incorrect insert into app group non primary." + << query.LastError().text()); + return false; + } + } + + return true; +} + +bool SQLPTRepresentation::SaveRemoteControlDenied(const std::string& app_id, + bool deny) { + LOG4CXX_AUTO_TRACE(logger_); + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kUpdateRemoteControlDenied)) { + LOG4CXX_WARN(logger_, "Incorrect update statement for remote control flag"); + return false; + } + LOG4CXX_DEBUG(logger_, "App: " << app_id << std::boolalpha << " - " << deny); + query.Bind(0, deny); + query.Bind(1, app_id); + if (!query.Exec()) { + LOG4CXX_WARN(logger_, "Incorrect update remote control flag."); + return false; + } + return true; +} + +bool SQLPTRepresentation::SaveModuleType( + const std::string& app_id, const policy_table::ModuleTypes& types) { + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertModuleType)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for module type"); + return false; + } + + policy_table::ModuleTypes::const_iterator it; + for (it = types.begin(); it != types.end(); ++it) { + query.Bind(0, app_id); + std::string module(policy_table::EnumToJsonString(*it)); + query.Bind(1, module); + LOG4CXX_DEBUG(logger_, + "Module(app: " << app_id << ", type: " << module << ")"); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into module type."); + return false; + } + } + + return true; +} + +bool SQLPTRepresentation::SaveAccessModule( + TypeAccess access, const policy_table::AccessModules& modules) { + LOG4CXX_AUTO_TRACE(logger_); + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertAccessModule)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for access module"); + return false; + } + + policy_table::AccessModules::const_iterator i; + for (i = modules.begin(); i != modules.end(); ++i) { + const std::string& name = i->first; + const policy_table::RemoteRpcs& rpcs = i->second; + query.Bind(0, name); + query.Bind(1, access); + if (!query.Exec()) { + LOG4CXX_WARN(logger_, "Incorrect insert into access module."); + return false; + } + int id = query.LastInsertId(); + if (!query.Reset()) { + LOG4CXX_WARN(logger_, "Couldn't reset query access module."); + return false; + } + if (!SaveRemoteRpc(id, rpcs)) { + return false; + } + } + return true; +} + +bool SQLPTRepresentation::GatherAccessModule( + TypeAccess access, policy_table::AccessModules* modules) const { + LOG4CXX_AUTO_TRACE(logger_); + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kSelectAccessModules)) { + LOG4CXX_WARN(logger_, "Incorrect select from access module"); + return false; + } + + query.Bind(0, access); + while (query.Next()) { + int id = query.GetInteger(0); + std::string name = query.GetString(1); + policy_table::RemoteRpcs rpcs; + if (!GatherRemoteRpc(id, &rpcs)) { + return false; + } + modules->insert(std::make_pair(name, rpcs)); + } + return true; +} + +bool SQLPTRepresentation::SaveRemoteRpc(int module_id, + const policy_table::RemoteRpcs& rpcs) { + LOG4CXX_AUTO_TRACE(logger_); + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kInsertRemoteRpc)) { + LOG4CXX_WARN(logger_, "Incorrect insert statement for remote rpc"); + return false; + } + policy_table::RemoteRpcs::const_iterator i; + for (i = rpcs.begin(); i != rpcs.end(); ++i) { + const std::string& name = i->first; + const policy_table::Strings& params = i->second; + policy_table::Strings::const_iterator j; + if (params.empty()) { + query.Bind(0, module_id); + query.Bind(1, name); + query.Bind(2); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into remote rpc."); + return false; + } + } else { + for (j = params.begin(); j != params.end(); ++j) { + const std::string& param = *j; + query.Bind(0, module_id); + query.Bind(1, name); + query.Bind(2, param); + if (!query.Exec() || !query.Reset()) { + LOG4CXX_WARN(logger_, "Incorrect insert into remote rpc."); + return false; + } + } + } + } + return true; +} + +bool SQLPTRepresentation::GatherRemoteRpc( + int module_id, policy_table::RemoteRpcs* rpcs) const { + LOG4CXX_AUTO_TRACE(logger_); + utils::dbms::SQLQuery query(db()); + if (!query.Prepare(sql_pt::kSelectRemoteRpcs)) { + LOG4CXX_WARN(logger_, "Incorrect select from remote rpc"); + return false; + } + + query.Bind(0, module_id); + while (query.Next()) { + std::string name = query.GetString(0); + if (!query.IsNull(1)) { + std::string parameter = query.GetString(1); + (*rpcs)[name].push_back(parameter); + } else { + rpcs->insert(std::make_pair(name, policy_table::Strings())); + } + } + return true; +} +#endif // SDL_REMOTE_CONTROL + bool SQLPTRepresentation::SaveApplicationCustomData(const std::string& app_id, bool is_revoked, bool is_default, @@ -1590,6 +1922,31 @@ bool SQLPTRepresentation::SetDefaultPolicy(const std::string& app_id) { LOG4CXX_ERROR(logger_, "Failed deleting from app_group."); return false; } +#ifdef SDL_REMOTE_CONTROL + utils::dbms::SQLQuery query_p(db()); + if (!query_p.Prepare(sql_pt::kDeleteAppGroupPrimaryByApplicationId)) { + LOG4CXX_ERROR(logger_, + "Incorrect statement to delete from app_group_primary."); + return false; + } + query_p.Bind(0, app_id); + if (!query_p.Exec()) { + LOG4CXX_ERROR(logger_, "Failed deleting from app_group_primary."); + return false; + } + + utils::dbms::SQLQuery query_np(db()); + if (!query_np.Prepare(sql_pt::kDeleteAppGroupNonPrimaryByApplicationId)) { + LOG4CXX_ERROR(logger_, + "Incorrect statement to delete from app_group_non_primary."); + return false; + } + query_np.Bind(0, app_id); + if (!query_np.Exec()) { + LOG4CXX_ERROR(logger_, "Failed deleting from app_group_non_primary."); + return false; + } +#endif // SDL_REMOTE_CONTROL if (!CopyApplication(kDefaultId, app_id)) { return false; @@ -1612,7 +1969,22 @@ bool SQLPTRepresentation::SetDefaultPolicy(const std::string& app_id) { !SaveAppType(app_id, app_types)) { return false; } - return SetIsDefault(app_id, true); + + bool ret = (GatherAppGroup(kDefaultId, &default_groups) && + SaveAppGroup(app_id, default_groups)); +#ifdef SDL_REMOTE_CONTROL + policy_table::Strings groups_primary; + ret = ret && (GatherAppGroupPrimary(kDefaultId, &groups_primary) && + SaveAppGroupPrimary(app_id, groups_primary)); + policy_table::Strings groups_non_primary; + ret = ret && (GatherAppGroupNonPrimary(kDefaultId, &groups_non_primary) && + SaveAppGroupNonPrimary(app_id, groups_non_primary)); +#endif // SDL_REMOTE_CONTROL + + if (ret) { + return SetIsDefault(app_id, true); + } + return false; } bool SQLPTRepresentation::SetIsDefault(const std::string& app_id, diff --git a/src/components/policy/policy_regular/test/CMakeLists.txt b/src/components/policy/policy_regular/test/CMakeLists.txt index 997c3637e8..62ff691f83 100644 --- a/src/components/policy/policy_regular/test/CMakeLists.txt +++ b/src/components/policy/policy_regular/test/CMakeLists.txt @@ -39,11 +39,17 @@ include_directories( ${COMPONENTS_DIR}/rpc_base/include ${COMPONENTS_DIR}/config_profile/include ${COMPONENTS_DIR}/utils/include/ + ${COMPONENTS_DIR}/include/test/policy/policy_regular/ ${POLICY_PATH}/test/include/ ${POLICY_MOCK_INCLUDE_PATH}/ ) collect_sources(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}") +if (NOT REMOTE_CONTROL) + list (REMOVE_ITEM SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/access_remote_impl_test.cc + ) +endif () set(LIBRARIES gmock diff --git a/src/components/policy/policy_regular/test/access_remote_impl_test.cc b/src/components/policy/policy_regular/test/access_remote_impl_test.cc new file mode 100644 index 0000000000..4b2a9b02eb --- /dev/null +++ b/src/components/policy/policy_regular/test/access_remote_impl_test.cc @@ -0,0 +1,265 @@ +/* + * 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 "gtest/gtest.h" +#include "policy/access_remote_impl.h" + +namespace policy { + +TEST(AccessRemoteImplTest, Allow) { + AccessRemoteImpl access_remote; + Subject who = {"dev1", "12345"}; + Object what = {policy_table::MT_RADIO}; + access_remote.Allow(who, what); + AccessRemoteImpl::AccessControlList::const_iterator i = + access_remote.acl_.find(what); + ASSERT_NE(access_remote.acl_.end(), i); + AccessRemoteImpl::AccessControlRow::const_iterator j = i->second.find(who); + ASSERT_NE(i->second.end(), j); + EXPECT_EQ(TypeAccess::kAllowed, j->second); +} + +TEST(AccessRemoteImplTest, KeyMapTest) { + // Testing operator < to use as key of map + AccessRemoteImpl access_remote; + Subject who = {"dev1", "12345"}; + Object what1 = {policy_table::MT_RADIO}; + Object what2 = {policy_table::MT_CLIMATE}; + access_remote.Allow(who, what1); + access_remote.Allow(who, what2); + ASSERT_EQ(2u, access_remote.acl_.size()); +} + +TEST(AccessRemoteImplTest, Deny) { + AccessRemoteImpl access_remote; + Subject who = {"dev1", "12345"}; + Object what = {policy_table::MT_RADIO}; + access_remote.Deny(who, what); + AccessRemoteImpl::AccessControlList::const_iterator i = + access_remote.acl_.find(what); + ASSERT_NE(access_remote.acl_.end(), i); + AccessRemoteImpl::AccessControlRow::const_iterator j = i->second.find(who); + ASSERT_NE(i->second.end(), j); + EXPECT_EQ(TypeAccess::kDisallowed, j->second); +} + +TEST(AccessRemoteImplTest, ChangeAccess) { + AccessRemoteImpl access_remote; + Subject who = {"dev1", "12345"}; + Object what = {policy_table::MT_RADIO}; + access_remote.Allow(who, what); + ASSERT_EQ(TypeAccess::kAllowed, access_remote.acl_[what][who]); + access_remote.Deny(who, what); + ASSERT_EQ(TypeAccess::kDisallowed, access_remote.acl_[what][who]); + access_remote.Allow(who, what); + EXPECT_EQ(TypeAccess::kAllowed, access_remote.acl_[what][who]); +} + +TEST(AccessRemoteImplTest, ResetBySubject) { + AccessRemoteImpl access_remote; + Subject who = {"dev1", "12345"}; + Object what1 = {policy_table::MT_RADIO}; + Object what2 = {policy_table::MT_CLIMATE}; + access_remote.Allow(who, what1); + access_remote.Deny(who, what2); + ASSERT_EQ(2u, access_remote.acl_.size()); + ASSERT_EQ(1u, access_remote.acl_[what1].size()); + ASSERT_EQ(1u, access_remote.acl_[what2].size()); + + access_remote.Reset(who); + ASSERT_EQ(2u, access_remote.acl_.size()); + EXPECT_TRUE(access_remote.acl_[what1].empty()); + EXPECT_TRUE(access_remote.acl_[what2].empty()); +} + +TEST(AccessRemoteImplTest, ResetByObject) { + AccessRemoteImpl access_remote; + Subject who1 = {"dev1", "12345"}; + Subject who2 = {"dev2", "123456"}; + Object what = {policy_table::MT_RADIO}; + access_remote.Allow(who1, what); + access_remote.Deny(who2, what); + ASSERT_EQ(1u, access_remote.acl_.size()); + ASSERT_EQ(2u, access_remote.acl_[what].size()); + + access_remote.Reset(what); + EXPECT_TRUE(access_remote.acl_.empty()); +} + +TEST(AccessRemoteImplTest, CheckAllowed) { + AccessRemoteImpl access_remote; + Subject who = {"dev1", "12345"}; + Object what = {policy_table::MT_RADIO}; + access_remote.Allow(who, what); + + EXPECT_EQ(TypeAccess::kAllowed, access_remote.Check(who, what)); +} + +TEST(AccessRemoteImplTest, CheckDisallowed) { + AccessRemoteImpl access_remote; + Subject who = {"dev1", "12345"}; + Subject who1 = {"dev1", "123456"}; + Object what = {policy_table::MT_RADIO}; + + access_remote.Allow(who, what); + EXPECT_EQ(TypeAccess::kManual, access_remote.Check(who1, what)); + + access_remote.Reset(who); + access_remote.Deny(who1, what); + EXPECT_EQ(TypeAccess::kDisallowed, access_remote.Check(who1, what)); +} + +TEST(AccessRemoteImplTest, CheckManual) { + AccessRemoteImpl access_remote; + Subject who = {"dev1", "12345"}; + Subject who1 = {"dev1", "123456"}; + Object what = {policy_table::MT_RADIO}; + + EXPECT_EQ(TypeAccess::kManual, access_remote.Check(who, what)); + + access_remote.Deny(who1, what); + EXPECT_EQ(TypeAccess::kManual, access_remote.Check(who, what)); +} + +TEST(AccessRemoteImplTest, CheckModuleType) { + AccessRemoteImpl access_remote; + access_remote.cache_->pt_ = new policy_table::Table(); + + // No application + EXPECT_FALSE(access_remote.CheckModuleType("1234", policy_table::MT_RADIO)); + + // No modules + policy_table::ApplicationPolicies& apps = + access_remote.cache_->pt_->policy_table.app_policies_section.apps; + apps["1234"]; + EXPECT_FALSE(access_remote.CheckModuleType("1234", policy_table::MT_RADIO)); + + // Empty modules + policy_table::ModuleTypes& modules = *apps["1234"].moduleType; + modules.mark_initialized(); + EXPECT_TRUE(access_remote.CheckModuleType("1234", policy_table::MT_RADIO)); + EXPECT_TRUE(access_remote.CheckModuleType("1234", policy_table::MT_CLIMATE)); + + // Specific modules + modules.push_back(policy_table::MT_RADIO); + EXPECT_TRUE(access_remote.CheckModuleType("1234", policy_table::MT_RADIO)); + EXPECT_FALSE(access_remote.CheckModuleType("1234", policy_table::MT_CLIMATE)); +} + +TEST(AccessRemoteImplTest, EnableDisable) { + AccessRemoteImpl access_remote; + access_remote.cache_->pt_ = new policy_table::Table(); + policy_table::ModuleConfig& config = + access_remote.cache_->pt_->policy_table.module_config; + + // Country is enabled + access_remote.enabled_ = true; + *config.country_consent_passengersRC = true; + access_remote.Enable(); + EXPECT_TRUE(*config.user_consent_passengersRC); + EXPECT_TRUE(*config.country_consent_passengersRC); + EXPECT_TRUE(access_remote.IsEnabled()); + + access_remote.Disable(); + EXPECT_FALSE(*config.user_consent_passengersRC); + EXPECT_TRUE(*config.country_consent_passengersRC); + EXPECT_FALSE(access_remote.IsEnabled()); + + // Country is disabled + access_remote.enabled_ = false; + *config.country_consent_passengersRC = false; + access_remote.Enable(); + EXPECT_TRUE(*config.user_consent_passengersRC); + EXPECT_FALSE(*config.country_consent_passengersRC); + EXPECT_FALSE(access_remote.IsEnabled()); + + access_remote.Disable(); + EXPECT_FALSE(*config.user_consent_passengersRC); + EXPECT_FALSE(*config.country_consent_passengersRC); + EXPECT_FALSE(access_remote.IsEnabled()); +} + +TEST(AccessRemoteImplTest, SetDefaultHmiTypes) { + AccessRemoteImpl access_remote; + + std::vector<int> hmi_expected; + hmi_expected.push_back(2); + hmi_expected.push_back(6); + Subject who = {"dev1", "1234"}; + access_remote.SetDefaultHmiTypes(who, hmi_expected); + + EXPECT_NE(access_remote.hmi_types_.end(), access_remote.hmi_types_.find(who)); + policy_table::AppHMITypes& hmi_output = access_remote.hmi_types_[who]; + EXPECT_EQ(2u, hmi_output.size()); + EXPECT_EQ(policy_table::AHT_MEDIA, hmi_output[0]); + EXPECT_EQ(policy_table::AHT_SOCIAL, hmi_output[1]); +} + +TEST(AccessRemoteImplTest, GetGroups) { + AccessRemoteImpl access_remote; + access_remote.primary_device_ = "dev1"; + access_remote.enabled_ = true; + Subject who = {"dev1", "1234"}; + access_remote.hmi_types_[who].push_back(policy_table::AHT_REMOTE_CONTROL); + + access_remote.cache_->pt_ = new policy_table::Table(); + policy_table::ApplicationPolicies& apps = + access_remote.cache_->pt_->policy_table.app_policies_section.apps; + apps["1234"].groups.push_back("group_default"); + apps["1234"].groups_nonPrimaryRC->push_back("group_non_primary"); + apps["1234"].groups_primaryRC->push_back("group_primary"); + apps["1234"].AppHMIType->push_back(policy_table::AHT_MEDIA); + + // Default groups + const policy_table::Strings& groups1 = access_remote.GetGroups(who); + EXPECT_EQ(std::string("group_default"), std::string(groups1[0])); + + // Primary groups + apps["1234"].set_to_string(policy::kDefaultId); + const policy_table::Strings& groups2 = access_remote.GetGroups(who); + EXPECT_EQ(std::string("group_primary"), std::string(groups2[0])); + + // Non primary groups + apps["1234"].set_to_string(policy::kDefaultId); + Subject who2 = {"dev2", "1234"}; + access_remote.hmi_types_[who2].push_back(policy_table::AHT_REMOTE_CONTROL); + const policy_table::Strings& groups3 = access_remote.GetGroups(who2); + EXPECT_EQ(std::string("group_non_primary"), std::string(groups3[0])); + + // Empty groups + access_remote.enabled_ = false; + apps["1234"].set_to_string(policy::kDefaultId); + const policy_table::Strings& groups4 = access_remote.GetGroups(who2); + EXPECT_TRUE(groups4.empty()); +} + +} // namespace policy diff --git a/src/components/policy/policy_regular/test/include/policy/mock_access_remote.h b/src/components/policy/policy_regular/test/include/policy/mock_access_remote.h new file mode 100644 index 0000000000..8c5bf75ba5 --- /dev/null +++ b/src/components/policy/policy_regular/test/include/policy/mock_access_remote.h @@ -0,0 +1,97 @@ +/* + * 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. + */ +#ifndef SRC_COMPONENTS_POLICY_TEST_INCLUDE_MOCK_ACCESS_REMOTE_H_ +#define SRC_COMPONENTS_POLICY_TEST_INCLUDE_MOCK_ACCESS_REMOTE_H_ + +#include "gmock/gmock.h" +#include "policy/access_remote.h" + +namespace test { +namespace components { +namespace access_remote_test { + +class MockSubject : public policy::Subject { + public: +}; + +class MockObject : public policy::Object { + public: +}; + +class MockAccessRemote : public policy::AccessRemote { + public: + MOCK_METHOD0(Init, void()); + MOCK_METHOD0(Enable, void()); + MOCK_METHOD0(Disable, void()); + MOCK_CONST_METHOD0(IsEnabled, bool()); + MOCK_CONST_METHOD1(IsPrimaryDevice, bool(const policy::PTString& dev_id)); + MOCK_METHOD1(SetPrimaryDevice, void(const policy::PTString& dev_id)); + MOCK_CONST_METHOD0(PrimaryDevice, policy::PTString()); + + MOCK_METHOD2(Allow, + void(const policy::Subject& who, const policy::Object& what)); + MOCK_METHOD2(Deny, + void(const policy::Subject& who, const policy::Object& what)); + MOCK_METHOD1(Reset, void(const policy::Subject& who)); + MOCK_METHOD1(Reset, void(const policy::Object& what)); + MOCK_CONST_METHOD2(Check, + policy::TypeAccess(const policy::Subject& who, + const policy::Object& what)); + MOCK_CONST_METHOD3( + FindGroup, + policy::PTString(const policy::Subject& who, + const policy::PTString& rpc, + const policy::RemoteControlParams& params)); + MOCK_METHOD2(SetDefaultHmiTypes, + void(const policy::Subject& who, + const std::vector<int>& hmi_types)); + MOCK_METHOD1(GetGroups, + const policy_table::Strings&(const policy::Subject& who)); + MOCK_METHOD3(GetPermissionsForApp, + bool(const std::string& device_id, + const std::string& app_id, + policy::FunctionalIdType& group_types)); + MOCK_CONST_METHOD2(CheckModuleType, + bool(const policy::PTString& app_id, + policy_table::ModuleType module)); + MOCK_METHOD1(IsAppRemoteControl, bool(const policy::Subject& who)); + MOCK_METHOD0(Reset, void()); + MOCK_METHOD2(GetModuleTypes, + bool(const std::string& application_id, + std::vector<std::string>* modules)); +}; + +} // namespace access_remote_test +} // namespace components +} // namespace test + +#endif // SRC_COMPONENTS_POLICY_TEST_INCLUDE_MOCK_ACCESS_REMOTE_H_ diff --git a/src/components/policy/policy_regular/test/include/policy/mock_cache_manager.h b/src/components/policy/policy_regular/test/include/policy/mock_cache_manager.h deleted file mode 100644 index 7569e2195d..0000000000 --- a/src/components/policy/policy_regular/test/include/policy/mock_cache_manager.h +++ /dev/null @@ -1,218 +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_CACHE_MANAGER_H_ -#define SRC_COMPONENTS_POLICY_POLICY_REGULAR_TEST_INCLUDE_MOCK_CACHE_MANAGER_H_ - -#include <string> -#include <vector> - -#include "gmock/gmock.h" - -#include "policy/cache_manager_interface.h" - -namespace test { -namespace components { -namespace policy_test { -namespace policy_table = rpc::policy_table_interface_base; -using namespace ::policy; - -class MockCacheManagerInterface : public CacheManagerInterface { - public: - MOCK_METHOD4(CheckPermissions, - void(const policy_table::Strings& groups, - const PTString& hmi_level, - const PTString& rpc, - CheckPermissionResult& result)); - MOCK_METHOD0(IsPTPreloaded, bool()); - MOCK_METHOD0(IgnitionCyclesBeforeExchange, int()); - MOCK_METHOD1(KilometersBeforeExchange, int(int current)); - MOCK_METHOD2(SetCountersPassedForSuccessfulUpdate, - bool(Counters counter, int value)); - MOCK_METHOD1(DaysBeforeExchange, int(int current)); - MOCK_METHOD0(IncrementIgnitionCycles, void()); - MOCK_METHOD0(ResetIgnitionCycles, void()); - MOCK_METHOD0(TimeoutResponse, int()); - MOCK_METHOD1(SecondsBetweenRetries, bool(std::vector<int>& seconds)); - MOCK_CONST_METHOD0(GetVehicleInfo, const VehicleInfo()); - MOCK_METHOD1(SetVINValue, bool(const std::string& value)); - MOCK_METHOD2(GetUserFriendlyMsg, - std::vector<UserFriendlyMessage>( - const std::vector<std::string>& msg_codes, - const std::string& language)); - - MOCK_METHOD1( - GetNotificationsNumber, - policy_table::NumberOfNotificationsType(const std::string& priority)); - MOCK_CONST_METHOD2(GetPriority, - bool(const std::string& policy_app_id, - std::string& priority)); - MOCK_METHOD2(GetUpdateUrls, - void(const std::string& service_type, - EndpointUrls& out_end_points)); - MOCK_METHOD2(GetUpdateUrls, - void(const uint32_t service_type, EndpointUrls& out_end_points)); - MOCK_CONST_METHOD0(GetLockScreenIconUrl, std::string()); - MOCK_METHOD2(Init, - bool(const std::string& file_name, - const PolicySettings* settings)); - MOCK_METHOD0(GenerateSnapshot, utils::SharedPtr<policy_table::Table>()); - MOCK_METHOD1(ApplyUpdate, bool(const policy_table::Table& update_pt)); - MOCK_METHOD1(Save, bool(const policy_table::Table& table)); - MOCK_CONST_METHOD0(UpdateRequired, bool()); - MOCK_METHOD1(SaveUpdateRequired, void(bool status)); - MOCK_METHOD3(GetInitialAppData, - bool(const std::string& app_id, - StringArray& nicknames, - StringArray& app_hmi_types)); - MOCK_CONST_METHOD1(IsApplicationRevoked, bool(const std::string& app_id)); - MOCK_METHOD1(GetFunctionalGroupings, - bool(policy_table::FunctionalGroupings& groups)); - MOCK_CONST_METHOD1(IsApplicationRepresented, bool(const std::string& app_id)); - MOCK_CONST_METHOD1(IsDefaultPolicy, bool(const std::string& app_id)); - MOCK_METHOD1(SetIsDefault, bool(const std::string& app_id)); - MOCK_CONST_METHOD1(IsPredataPolicy, bool(const std::string& app_id)); - MOCK_METHOD1(SetDefaultPolicy, bool(const std::string& app_id)); - MOCK_CONST_METHOD1(CanAppKeepContext, bool(const std::string& app_id)); - MOCK_CONST_METHOD1(CanAppStealFocus, bool(const std::string& app_id)); - MOCK_CONST_METHOD2(GetDefaultHMI, - bool(const std::string& app_id, std::string& default_hmi)); - MOCK_METHOD0(ResetUserConsent, bool()); - MOCK_CONST_METHOD3(GetUserPermissionsForDevice, - bool(const std::string& device_id, - StringArray& consented_groups, - StringArray& disallowed_groups)); - MOCK_METHOD3(GetPermissionsForApp, - bool(const std::string& device_id, - const std::string& app_id, - FunctionalIdType& group_types)); - MOCK_CONST_METHOD2( - GetDeviceGroupsFromPolicies, - bool(rpc::policy_table_interface_base::Strings& groups, - rpc::policy_table_interface_base::Strings& preconsented_groups)); - MOCK_METHOD2(AddDevice, - bool(const std::string& device_id, - const std::string& connection_type)); - 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_METHOD3(SetUserPermissionsForDevice, - bool(const std::string& device_id, - const StringArray& consented_groups, - const StringArray& disallowed_groups)); - MOCK_METHOD2(ReactOnUserDevConsentForApp, - bool(const std::string& app_id, bool is_device_allowed)); - MOCK_METHOD1(SetUserPermissionsForApp, - bool(const PermissionConsent& permissions)); - MOCK_METHOD3(SetMetaInfo, - bool(const std::string& ccpu_version, - const std::string& wers_country_code, - const std::string& language)); - MOCK_CONST_METHOD0(IsMetaInfoPresent, bool()); - MOCK_METHOD1(SetSystemLanguage, bool(const std::string& language)); - MOCK_METHOD1(Increment, void(usage_statistics::GlobalCounterId type)); - MOCK_METHOD2(Increment, - void(const std::string& app_id, - usage_statistics::AppCounterId type)); - MOCK_METHOD3(Set, - void(const std::string& app_id, - usage_statistics::AppInfoId type, - const std::string& value)); - MOCK_METHOD3(Add, - void(const std::string& app_id, - usage_statistics::AppStopwatchId type, - int seconds)); - MOCK_METHOD2(CountUnconsentedGroups, - int(const std::string& policy_app_id, - const std::string& device_id)); - MOCK_METHOD1(GetFunctionalGroupNames, bool(FunctionalGroupNames& names)); - MOCK_METHOD2(GetAllAppGroups, - void(const std::string& app_id, - FunctionalGroupIDs& all_group_ids)); - MOCK_METHOD2(GetPreConsentedGroups, - void(const std::string& app_id, - FunctionalGroupIDs& preconsented_groups)); - MOCK_METHOD4(GetConsentedGroups, - void(const std::string& device_id, - const std::string& app_id, - FunctionalGroupIDs& allowed_groups, - FunctionalGroupIDs& disallowed_groups)); - MOCK_METHOD3(GetUnconsentedGroups, - void(const std::string& device_id, - const std::string& policy_app_id, - FunctionalGroupIDs& unconsented_groups)); - MOCK_METHOD2(RemoveAppConsentForGroup, - void(const std::string& app_id, const std::string& group_name)); - MOCK_METHOD1(SetPredataPolicy, bool(const std::string& app_id)); - MOCK_METHOD0(CleanupUnpairedDevices, bool()); - MOCK_METHOD2(SetUnpairedDevice, - bool(const std::string& device_id, bool unpaired)); - MOCK_METHOD1(UnpairedDevicesList, bool(DeviceIds& device_ids)); - MOCK_METHOD1(ResetPT, bool(const std::string& file_name)); - MOCK_METHOD0(LoadFromBackup, bool()); - MOCK_METHOD2(LoadFromFile, - bool(const std::string& file_name, policy_table::Table&)); - MOCK_METHOD0(Backup, void()); - MOCK_CONST_METHOD1(HeartBeatTimeout, uint32_t(const std::string& app_id)); - MOCK_CONST_METHOD2(GetAppRequestTypes, - void(const std::string& policy_app_id, - std::vector<std::string>& request_types)); - MOCK_METHOD1(GetHMIAppTypeAfterUpdate, - void(std::map<std::string, StringArray>& app_hmi_types)); - MOCK_METHOD0(ResetCalculatedPermissions, void()); - MOCK_METHOD3(AddCalculatedPermissions, - void(const std::string& device_id, - const std::string& policy_app_id, - const policy::Permissions& permissions)); - MOCK_METHOD3(IsPermissionsCalculated, - bool(const std::string& device_id, - const std::string& policy_app_id, - policy::Permissions& permission)); - MOCK_CONST_METHOD0(GetPT, utils::SharedPtr<policy_table::Table>()); - MOCK_CONST_METHOD0(GetCertificate, std::string()); - MOCK_METHOD1(SetDecryptedCertificate, void(const std::string&)); - MOCK_METHOD1(GetGroups, const policy_table::Strings&(const PTString& app_id)); - MOCK_CONST_METHOD2(AppHasHMIType, - bool(const std::string& application_id, - policy_table::AppHMIType hmi_type)); -}; - -} // namespace policy_test -} // namespace components -} // namespace test - -#endif // SRC_COMPONENTS_POLICY_POLICY_REGULAR_TEST_INCLUDE_MOCK_CACHE_MANAGER_H_ diff --git a/src/components/policy/policy_regular/test/include/policy/mock_policy_listener.h b/src/components/policy/policy_regular/test/include/policy/mock_policy_listener.h deleted file mode 100644 index 2e4073aae9..0000000000 --- a/src/components/policy/policy_regular/test/include/policy/mock_policy_listener.h +++ /dev/null @@ -1,83 +0,0 @@ -/* Copyright (c) 2016, 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_POLICY_LISTENER_H_ -#define SRC_COMPONENTS_POLICY_POLICY_REGULAR_TEST_INCLUDE_MOCK_POLICY_LISTENER_H_ - -#include <string> - -#include "gmock/gmock.h" - -#include "policy/policy_listener.h" -#include "rpc_base/rpc_base.h" -#include "policy/policy_table/types.h" -#include "utils/custom_string.h" - -namespace policy_table = ::rpc::policy_table_interface_base; - -namespace policy { - -namespace custom_str = utils::custom_string; - -class MockPolicyListener : public PolicyListener { - public: - MOCK_METHOD3(OnPermissionsUpdated, - void(const std::string& policy_app_id, - const Permissions& permissions, - const policy::HMILevel& default_hmi)); - MOCK_METHOD2(OnPermissionsUpdated, - void(const std::string& policy_app_id, - const Permissions& permissions)); - MOCK_METHOD1(OnPendingPermissionChange, - void(const std::string& policy_app_id)); - MOCK_METHOD1(OnUpdateStatusChanged, void(const std::string& status)); - MOCK_METHOD1(OnCurrentDeviceIdUpdateRequired, - std::string(const std::string& policy_app_id)); - MOCK_METHOD0(OnSystemInfoUpdateRequired, void()); - MOCK_METHOD1(GetAppName, - custom_str::CustomString(const std::string& policy_app_id)); - MOCK_METHOD0(OnUserRequestedUpdateCheckRequired, void()); - MOCK_METHOD2(OnDeviceConsentChanged, - void(const std::string& device_id, bool is_allowed)); - MOCK_METHOD1(OnUpdateHMIAppType, void(std::map<std::string, StringArray>)); - MOCK_METHOD1(GetAvailableApps, void(std::queue<std::string>&)); - MOCK_METHOD1(OnSnapshotCreated, void(const BinaryMessage& pt_string)); - MOCK_METHOD0(CanUpdate, bool()); - MOCK_METHOD1(OnCertificateUpdated, void(const std::string&)); - MOCK_CONST_METHOD2(SendOnAppPermissionsChanged, - void(const AppPermissions&, const std::string&)); - MOCK_CONST_METHOD1(GetRegisteredLinks, - void(std::map<std::string, std::string>&)); -}; - -} // namespace policy - -#endif // SRC_COMPONENTS_POLICY_POLICY_REGULAR_TEST_INCLUDE_MOCK_POLICY_LISTENER_H_ diff --git a/src/components/policy/policy_regular/test/include/policy/mock_policy_manager.h b/src/components/policy/policy_regular/test/include/policy/mock_policy_manager.h deleted file mode 100644 index 7ab4b518cd..0000000000 --- a/src/components/policy/policy_regular/test/include/policy/mock_policy_manager.h +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 2016, 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_POLICY_MANAGER_H_ -#define SRC_COMPONENTS_POLICY_POLICY_REGULAR_TEST_INCLUDE_MOCK_POLICY_MANAGER_H_ - -#include <string> -#include <vector> -#include "gmock/gmock.h" -#include "policy/policy_listener.h" -#include "policy/policy_types.h" -#include "policy/usage_statistics/statistics_manager.h" - -#include "rpc_base/rpc_base.h" -#include "policy/policy_table/types.h" -#include "policy/policy_manager.h" - -namespace policy_table = ::rpc::policy_table_interface_base; - -namespace policy_manager { - -using namespace policy; - -class MockPolicyManager : public PolicyManager { - public: - MOCK_METHOD1(set_listener, void(PolicyListener* listener)); - MOCK_METHOD2(InitPT, - bool(const std::string& file_name, - const PolicySettings* settings)); - MOCK_METHOD2(LoadPT, - bool(const std::string& file, const BinaryMessage& pt_content)); - MOCK_METHOD1(ResetPT, bool(const std::string& file_name)); - MOCK_METHOD2(GetUpdateUrls, - void(const uint32_t service_type, EndpointUrls& out_end_points)); - MOCK_METHOD2(GetUpdateUrls, - void(const std::string& service_type, - EndpointUrls& out_end_points)); - MOCK_METHOD0(RequestPTUpdate, bool()); - - MOCK_METHOD6(CheckPermissions, - void(const PTString& device_id, - const PTString& app_id, - const PTString& hmi_level, - const PTString& rpc, - const RPCParams& rpc_params, - CheckPermissionResult& result)); - MOCK_METHOD0(ResetUserConsent, bool()); - MOCK_CONST_METHOD0(GetPolicyTableStatus, std::string()); - MOCK_METHOD1(KmsChanged, void(int kilometers)); - MOCK_METHOD0(IncrementIgnitionCycles, void()); - MOCK_METHOD0(ForcePTExchange, std::string()); - MOCK_METHOD0(ResetRetrySequence, void()); - MOCK_METHOD0(NextRetryTimeout, int()); - MOCK_METHOD0(TimeoutExchangeMSec, uint32_t()); - MOCK_METHOD0(RetrySequenceDelaysSeconds, const std::vector<int>()); - MOCK_METHOD0(OnExceededTimeout, void()); - MOCK_METHOD0(OnUpdateStarted, void()); - MOCK_CONST_METHOD1(GetUserConsentForDevice, - DeviceConsent(const std::string& device_id)); - MOCK_METHOD3( - GetUserConsentForApp, - void(const std::string& device_id, - const std::string& policy_app_id, - std::vector<policy::FunctionalGroupPermission>& permissions)); - MOCK_METHOD2(SetUserConsentForDevice, - void(const std::string& device_id, bool is_allowed)); - MOCK_METHOD2(ReactOnUserDevConsentForApp, - bool(const std::string app_id, bool is_device_allowed)); - MOCK_METHOD2(PTUpdatedAt, void(policy::Counters counter, int value)); - - MOCK_METHOD3(GetInitialAppData, - bool(const std::string&, - policy::StringArray*, - policy::StringArray*)); - - MOCK_METHOD2(AddDevice, - void(const std::string& device_id, - const std::string& connection_type)); - MOCK_METHOD2(SetDeviceInfo, - void(const std::string& device_id, - const policy::DeviceInfo& device_info)); - MOCK_METHOD1(SetUserConsentForApp, - void(const policy::PermissionConsent& permissions)); - MOCK_CONST_METHOD2(GetDefaultHmi, - bool(const std::string& policy_app_id, - std::string* default_hmi)); - MOCK_CONST_METHOD2(GetPriority, - bool(const std::string& policy_app_id, - std::string* priority)); - MOCK_METHOD2(GetUserFriendlyMessages, - std::vector<policy::UserFriendlyMessage>( - const std::vector<std::string>& message_code, - const std::string& language)); - MOCK_CONST_METHOD1(IsApplicationRevoked, bool(const std::string& app_id)); - MOCK_METHOD3( - GetPermissionsForApp, - void(const std::string& device_id, - const std::string& policy_app_id, - std::vector<policy::FunctionalGroupPermission>& permissions)); - MOCK_METHOD1(GetAppPermissionsChanges, - policy::AppPermissions(const std::string& policy_app_id)); - MOCK_METHOD1(RemovePendingPermissionChanges, void(const std::string& app_id)); - MOCK_CONST_METHOD1(GetCurrentDeviceId, - std::string&(const std::string& policy_app_id)); - MOCK_METHOD1(SetSystemLanguage, void(const std::string& language)); - MOCK_METHOD3(SetSystemInfo, - void(const std::string& ccpu_version, - const std::string& wers_country_code, - const std::string& language)); - MOCK_METHOD1(SendNotificationOnPermissionsUpdated, - void(const std::string& application_id)); - MOCK_METHOD1(MarkUnpairedDevice, void(const std::string& device_id)); - MOCK_METHOD1(AddApplication, - StatusNotifier(const std::string& application_id)); - MOCK_METHOD0(CleanupUnpairedDevices, bool()); - MOCK_CONST_METHOD1(CanAppKeepContext, bool(const std::string& app_id)); - MOCK_CONST_METHOD1(CanAppStealFocus, bool(const std::string& app_id)); - MOCK_METHOD0(OnSystemReady, void()); - MOCK_CONST_METHOD1(GetNotificationsNumber, - uint32_t(const std::string& priority)); - MOCK_METHOD1(SetVINValue, void(const std::string& value)); - MOCK_CONST_METHOD1(IsPredataPolicy, bool(const std::string& policy_app_id)); - MOCK_CONST_METHOD1(HeartBeatTimeout, uint32_t(const std::string& app_id)); - MOCK_METHOD1(SaveUpdateStatusRequired, void(bool is_update_needed)); - MOCK_METHOD0(OnAppsSearchStarted, void()); - MOCK_METHOD0(OnAppsSearchCompleted, void()); - MOCK_METHOD1(OnAppRegisteredOnMobile, - void(const std::string& application_id)); - MOCK_CONST_METHOD1( - GetAppRequestTypes, - const std::vector<std::string>(const std::string policy_app_id)); - MOCK_CONST_METHOD0(GetVehicleInfo, const policy::VehicleInfo()); - MOCK_CONST_METHOD0(RetrieveCertificate, std::string()); - MOCK_METHOD1(SetDecryptedCertificate, void(const std::string&)); - MOCK_METHOD0(ExceededIgnitionCycles, bool()); - MOCK_METHOD0(ExceededDays, bool()); - MOCK_METHOD0(StartPTExchange, void()); - MOCK_METHOD1(Increment, void(usage_statistics::GlobalCounterId type)); - MOCK_METHOD2(Increment, - void(const std::string& app_id, - usage_statistics::AppCounterId type)); - MOCK_METHOD3(Set, - void(const std::string& app_id, - usage_statistics::AppInfoId type, - const std::string& value)); - MOCK_METHOD3(Add, - void(const std::string& app_id, - usage_statistics::AppStopwatchId type, - int32_t timespan_seconds)); - MOCK_CONST_METHOD0(get_settings, const PolicySettings&()); - MOCK_METHOD1(set_settings, void(const PolicySettings* get_settings)); -}; - -} // namespace policy_manager - -#endif // SRC_COMPONENTS_POLICY_POLICY_REGULAR_TEST_INCLUDE_MOCK_POLICY_MANAGER_H_ diff --git a/src/components/policy/policy_regular/test/policy_manager_impl_test.cc b/src/components/policy/policy_regular/test/policy_manager_impl_test.cc index e8bca3061f..799b6c2999 100644 --- a/src/components/policy/policy_regular/test/policy_manager_impl_test.cc +++ b/src/components/policy/policy_regular/test/policy_manager_impl_test.cc @@ -53,7 +53,9 @@ #include "utils/date_time.h" #include "utils/make_shared.h" #include "utils/gen_hash.h" - +#ifdef SDL_REMOTE_CONTROL +#include "policy/mock_access_remote.h" +#endif // SDL_REMOTE_CONTROL using ::testing::ReturnRef; using ::testing::DoAll; using ::testing::SetArgReferee; @@ -144,12 +146,20 @@ class PolicyManagerImplTest : public ::testing::Test { MockCacheManagerInterface* cache_manager; NiceMock<MockPolicyListener> listener; const std::string device_id; +#ifdef SDL_REMOTE_CONTROL + utils::SharedPtr<access_remote_test::MockAccessRemote> access_remote; +#endif // SDL_REMOTE_CONTROL void SetUp() OVERRIDE { manager = new PolicyManagerImpl(); manager->set_listener(&listener); cache_manager = new MockCacheManagerInterface(); manager->set_cache_manager(cache_manager); + +#ifdef SDL_REMOTE_CONTROL + access_remote = new access_remote_test::MockAccessRemote(); + manager->set_access_remote(access_remote); +#endif // SDL_REMOTE_CONTROL } void TearDown() OVERRIDE { @@ -165,6 +175,15 @@ class PolicyManagerImplTest : public ::testing::Test { return ::testing::AssertionFailure() << ::rpc::PrettyFormat(report); } } + +#ifdef SDL_REMOTE_CONTROL + public: + bool CheckPTURemoteCtrlChange( + const utils::SharedPtr<policy_table::Table> pt_update, + const utils::SharedPtr<policy_table::Table> snapshot) { + return manager->CheckPTURemoteCtrlChange(pt_update, snapshot); + } +#endif // SDL_REMOTE_CONTROL }; class PolicyManagerImplTest2 : public ::testing::Test { @@ -189,10 +208,10 @@ class PolicyManagerImplTest2 : public ::testing::Test { const std::string dev_id2; Json::Value PTU_request_types; NiceMock<policy_handler_test::MockPolicySettings> policy_settings_; - const std::string kAppStorageFolder = "storage1"; + const std::string kAppStorageFolder = "storage_PolicyManagerImplTest2"; void SetUp() OVERRIDE { - file_system::CreateDirectory("storage1"); + file_system::CreateDirectory(kAppStorageFolder); file_system::DeleteFile("policy.sqlite"); manager = new PolicyManagerImpl(); @@ -231,7 +250,7 @@ class PolicyManagerImplTest2 : public ::testing::Test { } void CreateLocalPT(const std::string& file_name) { - file_system::remove_directory_content("storage1"); + file_system::remove_directory_content(kAppStorageFolder); ON_CALL(policy_settings_, app_storage_folder()) .WillByDefault(ReturnRef(kAppStorageFolder)); ASSERT_TRUE(manager->InitPT(file_name, &policy_settings_)); @@ -355,6 +374,8 @@ class PolicyManagerImplTest2 : public ::testing::Test { void TearDown() OVERRIDE { delete manager; + file_system::remove_directory_content(kAppStorageFolder); + file_system::RemoveDirectory(kAppStorageFolder, true); } }; @@ -1247,7 +1268,7 @@ TEST_F(PolicyManagerImplTest2, // Arrange CreateLocalPT("sdl_preloaded_pt.json"); GetPTU("valid_sdl_pt_update.json"); - utils::SharedPtr<policy_table::Table> pt = (manager->GetCache())->GetPT(); + utils::SharedPtr<policy_table::Table> pt = (manager->GetCache())->pt(); policy_table::ModuleConfig& module_config = pt->policy_table.module_config; ::policy::VehicleInfo vehicle_info = manager->GetVehicleInfo(); @@ -1328,7 +1349,7 @@ TEST_F( HertBeatTimeout_AddApp_UpdateAppPolicies_ExpectReceivedHertBeatTimeoutCorrect) { // Arrange CreateLocalPT("sdl_preloaded_pt.json"); - utils::SharedPtr<policy_table::Table> pt = (manager->GetCache())->GetPT(); + utils::SharedPtr<policy_table::Table> pt = (manager->GetCache())->pt(); ::policy_table::PolicyTableType type1 = ::policy_table::PolicyTableType::PT_PRELOADED; pt->SetPolicyTableType(type1); diff --git a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc index a313ce6d7f..cef5cdeb38 100644 --- a/src/components/policy/policy_regular/test/sql_pt_representation_test.cc +++ b/src/components/policy/policy_regular/test/sql_pt_representation_test.cc @@ -68,22 +68,23 @@ namespace test { namespace components { namespace policy_test { +using policy_handler_test::MockPolicySettings; + class SQLPTRepresentationTest : public SQLPTRepresentation, public ::testing::Test { protected: - static DBMS* dbms; - static SQLPTRepresentation* reps; + DBMS* dbms; + SQLPTRepresentation* reps; static const std::string kDatabaseName; static const std::string kAppStorageFolder; // Gtest can show message that this object doesn't destroyed - static std::auto_ptr<policy_handler_test::MockPolicySettings> - policy_settings_; + std::auto_ptr<NiceMock<MockPolicySettings> > policy_settings_; - static void SetUpTestCase() { - file_system::DeleteFile(kAppStorageFolder + "/policy.sqlite"); + void SetUp() OVERRIDE { + file_system::CreateDirectory(kAppStorageFolder); reps = new SQLPTRepresentation; - policy_settings_ = std::auto_ptr<policy_handler_test::MockPolicySettings>( - new policy_handler_test::MockPolicySettings()); + policy_settings_ = std::auto_ptr<NiceMock<MockPolicySettings> >( + new NiceMock<MockPolicySettings>()); ON_CALL(*policy_settings_, app_storage_folder()) .WillByDefault(ReturnRef(kAppStorageFolder)); EXPECT_EQ(::policy::SUCCESS, reps->Init(policy_settings_.get())); @@ -93,15 +94,13 @@ class SQLPTRepresentationTest : public SQLPTRepresentation, void TearDown() OVERRIDE { EXPECT_TRUE(reps->Clear()); - } - - static void TearDownTestCase() { EXPECT_TRUE(reps->Drop()); EXPECT_TRUE(reps->Close()); reps->RemoveDB(); delete reps; dbms->Close(); - file_system::RemoveDirectory(kAppStorageFolder); + file_system::remove_directory_content(kAppStorageFolder); + file_system::RemoveDirectory(kAppStorageFolder, true); policy_settings_.reset(); } @@ -346,12 +345,9 @@ class SQLPTRepresentationTest : public SQLPTRepresentation, } }; -DBMS* SQLPTRepresentationTest::dbms = 0; -SQLPTRepresentation* SQLPTRepresentationTest::reps = 0; const std::string SQLPTRepresentationTest::kDatabaseName = "policy.sqlite"; -const std::string SQLPTRepresentationTest::kAppStorageFolder = "storage1"; -std::auto_ptr<policy_handler_test::MockPolicySettings> - SQLPTRepresentationTest::policy_settings_; +const std::string SQLPTRepresentationTest::kAppStorageFolder = + "storage_SQLPTRepresentationTest"; class SQLPTRepresentationTest2 : public ::testing::Test { protected: @@ -378,7 +374,7 @@ class SQLPTRepresentationTest2 : public ::testing::Test { } SQLPTRepresentation* reps; - NiceMock<policy_handler_test::MockPolicySettings> policy_settings_; + NiceMock<MockPolicySettings> policy_settings_; const std::string kAppStorageFolder; const uint16_t kOpenAttemptTimeoutMs; const uint16_t kAttemptsToOpenPolicyDB; @@ -399,7 +395,7 @@ class SQLPTRepresentationTest3 : public ::testing::Test { } SQLPTRepresentation* reps; - NiceMock<policy_handler_test::MockPolicySettings> policy_settings_; + NiceMock<MockPolicySettings> policy_settings_; const std::string kAppStorageFolder; }; @@ -424,7 +420,7 @@ TEST_F(SQLPTRepresentationTest, ASSERT_EQ(0, dbms->FetchOneInt(query_select)); ASSERT_TRUE(reps->RefreshDB()); // Check PT structure destroyed and tables number is 0 - ASSERT_EQ(25, dbms->FetchOneInt(query_select)); + ASSERT_EQ(30, dbms->FetchOneInt(query_select)); const char* query_select_count_of_iap_buffer_full = "SELECT `count_of_iap_buffer_full` FROM `usage_and_error_count`"; const char* query_select_count_sync_out_of_memory = @@ -1102,7 +1098,7 @@ TEST_F(SQLPTRepresentationTest, GetInitialAppData_SetData_ExpectCorrectValuesReceived) { // Arrange const char* query_insert = - "INSERT INTO `nickname` (`application_id`, `name`)" + "INSERT INTO `nickname` (`application_id`, `name`) " "VALUES ('1111', 'first_app') , " "('2222', 'second_app'), ('3333', 'third_app')"; ASSERT_TRUE(dbms->Exec(query_insert)); |