diff options
author | SKobziev <skobziev@luxoft.com> | 2018-10-25 15:20:50 +0300 |
---|---|---|
committer | SKobziev <skobziev@luxoft.com> | 2018-10-26 11:55:24 +0300 |
commit | 072bba71a3b553da369dd8b8e63edf94ab61bff6 (patch) | |
tree | b4a98e0f584df6e1b7b6411bcaa08defd13aa92a /src/components/policy/policy_external | |
parent | 0d5b3c4dc01844880f46b752076278578b77781f (diff) | |
parent | d36316738785c96dab2ee892762ed08c059fffde (diff) | |
download | sdl_core-fix/Fix_log_severity_level_in_on_vehicle_data_notification_cc.tar.gz |
Fix log severity level and various typosfix/Fix_log_severity_level_in_on_vehicle_data_notification_cc
There are following minor issues was fixed:
log severity level in on_vehicle_data_notification.cc: ERROR -> DEBUG
typo in on_vehicle_data_notification.cc: nanme -> name
typo in request_controller.cc: HmiConnectoinKey -> HmiConnectionKey
typo in request_info.cc: HmiConnectoinKey -> HmiConnectionKey
Also OnSystemError_SUCCESS was changed to DISABLED_OnSystemError_SUCCESS
in policy_handler_test.cpp because the running this test case was successful
locally and was unsuccess on Jenkins
Diffstat (limited to 'src/components/policy/policy_external')
16 files changed, 1006 insertions, 142 deletions
diff --git a/src/components/policy/policy_external/include/policy/policy_helper.h b/src/components/policy/policy_external/include/policy/policy_helper.h index 6f916b7cd0..e3cb509c15 100644 --- a/src/components/policy/policy_external/include/policy/policy_helper.h +++ b/src/components/policy/policy_external/include/policy/policy_helper.h @@ -100,7 +100,8 @@ struct CheckAppPolicy { * @param result Result of check of updated policy */ void SetPendingPermissions(const AppPoliciesValueType& app_policy, - PermissionsCheckResult result) const; + PermissionsCheckResult result, + AppPermissions& permissions_diff) const; /** * @brief Analyzes updated application policy whether any changes received. If * yes - provides appropriate result code @@ -200,6 +201,18 @@ struct CheckAppPolicy { */ bool IsRequestSubTypeChanged(const AppPoliciesValueType& app_policy) const; + /** + * @brief Helper function that inserts permissions into app_permissions_diff_ + * map. + * udpated + * @param app_policy Reference to updated application policy + * @param permissions_diff Reference to app permissions to be inserted into + * map. + * @return void + */ + void InsertPermission(const std::string& app_id, + const AppPermissions& permissions_diff); + private: PolicyManagerImpl* pm_; const std::shared_ptr<policy_table::Table> update_; diff --git a/src/components/policy/policy_external/include/policy/policy_table/enums.h b/src/components/policy/policy_external/include/policy/policy_table/enums.h index a31e955d99..34864c5602 100644 --- a/src/components/policy/policy_external/include/policy/policy_table/enums.h +++ b/src/components/policy/policy_external/include/policy/policy_table/enums.h @@ -44,6 +44,7 @@ enum Priority { P_VOICECOM, P_COMMUNICATION, P_NORMAL, + P_PROJECTION, P_NONE, }; @@ -180,6 +181,372 @@ bool IsValidEnum(ModuleType val); const char* EnumToJsonString(ModuleType val); bool EnumFromJsonString(const std::string& literal, ModuleType* result); +/** + * @brief Enumeration FunctionID. + * + * Enumeration linking function names with function IDs in AppLink protocol. + * Assumes enumeration starts at value 0. + */ +enum FunctionID { + /** + * @brief RESERVED. + */ + RESERVED = 0, + + /** + * @brief RegisterAppInterfaceID. + */ + RegisterAppInterfaceID = 1, + + /** + * @brief UnregisterAppInterfaceID. + */ + UnregisterAppInterfaceID = 2, + + /** + * @brief SetGlobalPropertiesID. + */ + SetGlobalPropertiesID = 3, + + /** + * @brief ResetGlobalPropertiesID. + */ + ResetGlobalPropertiesID = 4, + + /** + * @brief AddCommandID. + */ + AddCommandID = 5, + + /** + * @brief DeleteCommandID. + */ + DeleteCommandID = 6, + + /** + * @brief AddSubMenuID. + */ + AddSubMenuID = 7, + + /** + * @brief DeleteSubMenuID. + */ + DeleteSubMenuID = 8, + + /** + * @brief CreateInteractionChoiceSetID. + */ + CreateInteractionChoiceSetID = 9, + + /** + * @brief PerformInteractionID. + */ + PerformInteractionID = 10, + + /** + * @brief DeleteInteractionChoiceSetID. + */ + DeleteInteractionChoiceSetID = 11, + + /** + * @brief AlertID. + */ + AlertID = 12, + + /** + * @brief ShowID. + */ + ShowID = 13, + + /** + * @brief SpeakID. + */ + SpeakID = 14, + + /** + * @brief SetMediaClockTimerID. + */ + SetMediaClockTimerID = 15, + + /** + * @brief PerformAudioPassThruID. + */ + PerformAudioPassThruID = 16, + + /** + * @brief EndAudioPassThruID. + */ + EndAudioPassThruID = 17, + + /** + * @brief SubscribeButtonID. + */ + SubscribeButtonID = 18, + + /** + * @brief UnsubscribeButtonID. + */ + UnsubscribeButtonID = 19, + + /** + * @brief SubscribeVehicleDataID. + */ + SubscribeVehicleDataID = 20, + + /** + * @brief UnsubscribeVehicleDataID. + */ + UnsubscribeVehicleDataID = 21, + + /** + * @brief GetVehicleDataID. + */ + GetVehicleDataID = 22, + + /** + * @brief ReadDIDID. + */ + ReadDIDID = 23, + + /** + * @brief GetDTCsID. + */ + GetDTCsID = 24, + + /** + * @brief ScrollableMessageID. + */ + ScrollableMessageID = 25, + + /** + * @brief SliderID. + */ + SliderID = 26, + + /** + * @brief ShowConstantTBTID. + */ + ShowConstantTBTID = 27, + + /** + * @brief AlertManeuverID. + */ + AlertManeuverID = 28, + + /** + * @brief UpdateTurnListID. + */ + UpdateTurnListID = 29, + + /** + * @brief ChangeRegistrationID. + */ + ChangeRegistrationID = 30, + + /** + * @brief GenericResponseID. + */ + GenericResponseID = 31, + + /** + * @brief PutFileID. + */ + PutFileID = 32, + + /** + * @brief DeleteFileID. + */ + DeleteFileID = 33, + + /** + * @brief ListFilesID. + */ + ListFilesID = 34, + + /** + * @brief SetAppIconID. + */ + SetAppIconID = 35, + + /** + * @brief SetDisplayLayoutID. + */ + SetDisplayLayoutID = 36, + + /** + * @brief DiagnosticMessageID. + */ + DiagnosticMessageID = 37, + + /** + * @brief SystemRequestID. + */ + SystemRequestID = 38, + + /** + * @brief SendLocationID. + */ + SendLocationID = 39, + + /** + * @brief DialNumberID. + */ + DialNumberID = 40, + + /** + * @brief ButtonPressID. + */ + ButtonPressID = 41, + + /** + * @brief GetInteriorVehicleDataID. + */ + GetInteriorVehicleDataID = 43, + + /** + * @brief SetInteriorVehicleDataID. + */ + SetInteriorVehicleDataID = 44, + + /** + * @brief GetWayPointsID. + */ + GetWayPointsID = 45, + + /** + * @brief SubscribeWayPointsID. + */ + SubscribeWayPointsID = 46, + + /** + * @brief UnsubscribeWayPointsID. + */ + UnsubscribeWayPointsID = 47, + + /** + * @brief GetSystemCapabilityID. + */ + GetSystemCapabilityID = 48, + + /** + * @brief SendHapticDataID. + */ + SendHapticDataID = 49, + + /** + * @brief OnHMIStatusID. + */ + OnHMIStatusID = 32768, + + /** + * @brief OnAppInterfaceUnregisteredID. + */ + OnAppInterfaceUnregisteredID = 32769, + + /** + * @brief OnButtonEventID. + */ + OnButtonEventID = 32770, + + /** + * @brief OnButtonPressID. + */ + OnButtonPressID = 32771, + + /** + * @brief OnVehicleDataID. + */ + OnVehicleDataID = 32772, + + /** + * @brief OnCommandID. + */ + OnCommandID = 32773, + + /** + * @brief OnTBTClientStateID. + */ + OnTBTClientStateID = 32774, + + /** + * @brief OnDriverDistractionID. + */ + OnDriverDistractionID = 32775, + + /** + * @brief OnPermissionsChangeID. + */ + OnPermissionsChangeID = 32776, + + /** + * @brief OnAudioPassThruID. + */ + OnAudioPassThruID = 32777, + + /** + * @brief OnLanguageChangeID. + */ + OnLanguageChangeID = 32778, + + /** + * @brief OnKeyboardInputID. + */ + OnKeyboardInputID = 32779, + + /** + * @brief OnTouchEventID. + */ + OnTouchEventID = 32780, + + /** + * @brief OnSystemRequestID. + */ + OnSystemRequestID = 32781, + + /** + * @brief OnHashChangeID. + */ + OnHashChangeID = 32782, + + /** + * @brief OnInteriorVehicleDataID. + */ + OnInteriorVehicleDataID = 32783, + + /** + * @brief OnWayPointChangeID. + */ + OnWayPointChangeID = 32784, + + /** + * @brief OnRCStatusID. + */ + OnRCStatusID = 32785, + + /** + * @brief EncodedSyncPDataID. + */ + EncodedSyncPDataID = 65536, + + /** + * @brief SyncPDataID. + */ + SyncPDataID = 65537, + + /** + * @brief OnEncodedSyncPDataID. + */ + OnEncodedSyncPDataID = 98304, + + /** + * @brief OnSyncPDataID. + */ + OnSyncPDataID = 98305 +}; +bool IsValidEnum(FunctionID val); +const char* EnumToJsonString(FunctionID val); +bool EnumFromJsonString(const std::string& literal, FunctionID* result); + extern const std::string kDefaultApp; extern const std::string kPreDataConsentApp; extern const std::string kDeviceApp; diff --git a/src/components/policy/policy_external/include/policy/sql_pt_queries.h b/src/components/policy/policy_external/include/policy/sql_pt_queries.h index 646cc7663b..dd9e0204e7 100644 --- a/src/components/policy/policy_external/include/policy/sql_pt_queries.h +++ b/src/components/policy/policy_external/include/policy/sql_pt_queries.h @@ -79,8 +79,6 @@ extern const std::string kInsertAppGroup; extern const std::string kInsertNickname; extern const std::string kInsertAppType; extern const std::string kInsertRequestType; -extern const std::string kInsertOmittedRequestType; -extern const std::string kInsertOmittedRequestSubType; extern const std::string kInsertRequestSubType; extern const std::string kInsertMessageType; extern const std::string kInsertLanguage; diff --git a/src/components/policy/policy_external/include/policy/update_status_manager.h b/src/components/policy/policy_external/include/policy/update_status_manager.h index b4a373d1cf..3a9e13b83f 100644 --- a/src/components/policy/policy_external/include/policy/update_status_manager.h +++ b/src/components/policy/policy_external/include/policy/update_status_manager.h @@ -114,15 +114,15 @@ class UpdateStatusManager { void OnResetRetrySequence(); /** - * @brief Update status handler on new application registering + * @brief Update status handler on existed application registering + * @param is_update_required Update necessity flag */ - void OnNewApplicationAdded(const DeviceConsent consent); + void OnExistedApplicationAdded(const bool is_update_required); /** - * @brief Update status handler for policy initialization - * @param is_update_required Update necessity flag + * @brief Update status handler on new application registering */ - void OnPolicyInit(bool is_update_required); + void OnNewApplicationAdded(const DeviceConsent consent); /** * @brief In case application from non-consented device has been registered diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index e4a4151fa4..c2c2e91257 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -207,6 +207,21 @@ struct ExternalConsentConsentGroupAppender } }; +struct DefaultPolicyUpdater { + DefaultPolicyUpdater(const policy_table::ApplicationParams& default_params) + : default_params_(default_params) {} + + void operator()(policy_table::ApplicationPolicies::value_type& pt_value) { + if (policy::kDefaultId == pt_value.second.get_string()) { + pt_value.second = default_params_; + pt_value.second.set_to_string(policy::kDefaultId); + } + } + + private: + const policy_table::ApplicationParams& default_params_; +}; + } // namespace namespace policy { @@ -681,6 +696,13 @@ void CacheManager::ProcessUpdate( initial_policy_iter->second; *(pt_->policy_table.app_policies_section.apps[app_id].RequestType) = merged_pt_request_types; + + if (app_id == kDefaultId) { + std::for_each(pt_->policy_table.app_policies_section.apps.begin(), + pt_->policy_table.app_policies_section.apps.end(), + DefaultPolicyUpdater( + pt_->policy_table.app_policies_section.apps[app_id])); + } } bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) { diff --git a/src/components/policy/policy_external/src/policy_helper.cc b/src/components/policy/policy_external/src/policy_helper.cc index 2358c54bef..c9df969bd1 100644 --- a/src/components/policy/policy_external/src/policy_helper.cc +++ b/src/components/policy/policy_external/src/policy_helper.cc @@ -299,9 +299,20 @@ void CheckAppPolicy::AddResult(const std::string& app_id, out_results_.insert(std::make_pair(app_id, result)); } +void CheckAppPolicy::InsertPermission(const std::string& app_id, + const AppPermissions& permissions_diff) { + pm_->app_permissions_diff_lock_.Acquire(); + auto result = pm_->app_permissions_diff_.insert( + std::make_pair(app_id, permissions_diff)); + if (!result.second) { + LOG4CXX_ERROR(logger_, "App ID: " << app_id << " already exists in map."); + } + pm_->app_permissions_diff_lock_.Release(); +} + bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) { const std::string app_id = app_policy.first; - + AppPermissions permissions_diff(app_id); if (!IsKnownAppication(app_id)) { LOG4CXX_WARN(logger_, "Application:" << app_id << " is not present in snapshot."); @@ -309,14 +320,17 @@ bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) { } if (!IsPredefinedApp(app_policy) && IsAppRevoked(app_policy)) { - SetPendingPermissions(app_policy, RESULT_APP_REVOKED); + SetPendingPermissions(app_policy, RESULT_APP_REVOKED, permissions_diff); AddResult(app_id, RESULT_APP_REVOKED); + InsertPermission(app_id, permissions_diff); return true; } if (!IsPredefinedApp(app_policy) && !NicknamesMatch(app_policy)) { - SetPendingPermissions(app_policy, RESULT_NICKNAME_MISMATCH); + SetPendingPermissions( + app_policy, RESULT_NICKNAME_MISMATCH, permissions_diff); AddResult(app_id, RESULT_NICKNAME_MISMATCH); + InsertPermission(app_id, permissions_diff); return true; } @@ -328,14 +342,20 @@ bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) { if (is_request_type_changed) { LOG4CXX_TRACE(logger_, "Request types were changed for application: " << app_id); - SetPendingPermissions(app_policy, RESULT_REQUEST_TYPE_CHANGED); + SetPendingPermissions( + app_policy, RESULT_REQUEST_TYPE_CHANGED, permissions_diff); AddResult(app_id, RESULT_REQUEST_TYPE_CHANGED); + result = + (RESULT_NO_CHANGES == result) ? RESULT_REQUEST_TYPE_CHANGED : result; } if (is_request_subtype_changed) { LOG4CXX_TRACE( logger_, "Request subtypes were changed for application: " << app_id); - SetPendingPermissions(app_policy, RESULT_REQUEST_SUBTYPE_CHANGED); + SetPendingPermissions( + app_policy, RESULT_REQUEST_SUBTYPE_CHANGED, permissions_diff); AddResult(app_id, RESULT_REQUEST_SUBTYPE_CHANGED); + result = (RESULT_NO_CHANGES == result) ? RESULT_REQUEST_SUBTYPE_CHANGED + : result; } } @@ -352,19 +372,20 @@ bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) { << " have been changed."); if (!IsPredefinedApp(app_policy)) { - SetPendingPermissions(app_policy, result); + SetPendingPermissions(app_policy, result, permissions_diff); AddResult(app_id, result); } + InsertPermission(app_id, permissions_diff); return true; } void policy::CheckAppPolicy::SetPendingPermissions( const AppPoliciesValueType& app_policy, - PermissionsCheckResult result) const { + PermissionsCheckResult result, + AppPermissions& permissions_diff) const { using namespace rpc::policy_table_interface_base; const std::string app_id = app_policy.first; - AppPermissions permissions_diff(app_id); const std::string priority = policy_table::EnumToJsonString(app_policy.second.priority); @@ -421,10 +442,6 @@ void policy::CheckAppPolicy::SetPendingPermissions( if (need_send_priority) { permissions_diff.priority = priority; } - - pm_->app_permissions_diff_lock_.Acquire(); - pm_->app_permissions_diff_.insert(std::make_pair(app_id, permissions_diff)); - pm_->app_permissions_diff_lock_.Release(); } PermissionsCheckResult CheckAppPolicy::CheckPermissionsChanges( diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index e2b0d6524f..a603f122e2 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -271,6 +271,154 @@ std::string PolicyManagerImpl::GetLockScreenIconUrl() const { return cache_->GetLockScreenIconUrl(); } +/** + * @brief FilterInvalidFunctions filter functions that are absent in schema + * @param rpcs list of functions to filter + */ +void FilterInvalidFunctions(policy_table::Rpc& rpcs) { + policy_table::Rpc valid_rpcs; + for (const auto& rpc : rpcs) { + const std::string& rpc_name = rpc.first; + policy_table::FunctionID function_id; + if (policy_table::EnumFromJsonString(rpc_name, &function_id)) { + valid_rpcs.insert(rpc); + } + } + rpcs.swap(valid_rpcs); +} + +/** + * @brief FilterInvalidRPCParameters filter parameters that not present in + * schema + * @param rpc_parameters parameters to filter + */ +void FilterInvalidRPCParameters(policy_table::RpcParameters& rpc_parameters) { + policy_table::HmiLevels valid_hmi_levels; + for (const auto& hmi_level : rpc_parameters.hmi_levels) { + if (hmi_level.is_valid()) { + valid_hmi_levels.push_back(hmi_level); + } + } + rpc_parameters.hmi_levels.swap(valid_hmi_levels); + + policy_table::Parameters valid_params; + const policy_table::Parameters& params = *(rpc_parameters.parameters); + for (const auto& param : params) { + if (param.is_valid()) { + valid_params.push_back(param); + } + } + rpc_parameters.parameters->swap(valid_params); +} + +/** + * @brief FilterInvalidPriorityValues filter notification priorities that are + * not present in schema + * @param notifications priorities to filter + */ +void FilterInvalidPriorityValues( + policy_table::NumberOfNotificationsPerMinute& notifications) { + policy_table::NumberOfNotificationsPerMinute valid_notifications; + for (const auto& notification : notifications) { + policy_table::Priority priority; + if (policy_table::EnumFromJsonString(notification.first, &priority)) { + valid_notifications.insert(notification); + } + } + notifications.swap(valid_notifications); +} + +/** + * @brief FilterInvalidApplicationParameters filter app params that are not + * present in schema + * @param app_params object of app policy params to filter + */ +void FilterInvalidApplicationParameters( + policy_table::ApplicationParams& app_params) { + // Filter AppHMIType array + policy_table::AppHMITypes valid_app_hmi_types; + const policy_table::AppHMITypes& app_hmi_types = *(app_params.AppHMIType); + for (const auto& app_hmi_type : app_hmi_types) { + if (app_hmi_type.is_valid()) { + valid_app_hmi_types.push_back(app_hmi_type); + } + } + app_params.AppHMIType->swap(valid_app_hmi_types); + + // Filter RquestTypes array + policy_table::RequestTypes valid_request_types; + const policy_table::RequestTypes& request_types = *(app_params.RequestType); + for (const auto& request_type : request_types) { + if (request_type.is_valid()) { + valid_request_types.push_back(request_type); + } + } + if (valid_request_types.empty() && !request_types.empty()) { + // An empty RequestType array will allow all request types. No valid + // parameters are in the filtered array, so assign an uninitialized value to + // for array to be "omitted" + *(app_params.RequestType) = policy_table::RequestTypes(); + } else { + app_params.RequestType->swap(valid_request_types); + } + + // Filter moduleType array + policy_table::ModuleTypes valid_module_types; + const policy_table::ModuleTypes& module_types = *(app_params.moduleType); + for (const auto& module_type : module_types) { + if (module_type.is_valid()) { + valid_module_types.push_back(module_type); + } + } + if (valid_module_types.empty() && !module_types.empty()) { + // An empty moduleType array will allow all request types. No valid + // parameters are in the filtered array, so assign an uninitialized value to + // for array to be "omitted" + *(app_params.moduleType) = policy_table::ModuleTypes(); + } else { + app_params.moduleType->swap(valid_module_types); + } + + // Filter default_hmi + if (!app_params.default_hmi.is_valid()) { + app_params.default_hmi = policy_table::HmiLevel(); + } + + // Filter priority + if (!app_params.priority.is_valid()) { + app_params.priority = policy_table::Priority(); + } +} + +/** + * @brief FilterPolicyTable filter values that not present in schema + * @param pt policy table to filter + */ +void FilterPolicyTable(policy_table::PolicyTable& pt) { + policy_table::ModuleConfig& module_config = pt.module_config; + if (module_config.is_initialized() && + module_config.notifications_per_minute_by_priority.is_initialized()) { + FilterInvalidPriorityValues( + module_config.notifications_per_minute_by_priority); + } + + if (pt.app_policies_section.is_initialized()) { + policy_table::ApplicationPolicies& apps = pt.app_policies_section.apps; + for (auto& app_policy : apps) { + FilterInvalidApplicationParameters(app_policy.second); + } + } + + for (auto& group : pt.functional_groupings) { + policy_table::Rpc& rpcs = group.second.rpcs; + FilterInvalidFunctions(rpcs); + + for (auto& func : rpcs) { + FilterInvalidRPCParameters(func.second); + } + } +} + bool PolicyManagerImpl::LoadPT(const std::string& file, const BinaryMessage& pt_content) { LOG4CXX_INFO(logger_, "LoadPT of size " << pt_content.size()); @@ -287,7 +435,7 @@ bool PolicyManagerImpl::LoadPT(const std::string& file, } file_system::DeleteFile(file); - + FilterPolicyTable(pt_update->policy_table); if (!IsPTValid(pt_update, policy_table::PT_UPDATE)) { wrong_ptu_update_received_ = true; update_status_manager_.OnWrongUpdateReceived(); @@ -1098,10 +1246,6 @@ void PolicyManagerImpl::GetUserConsentForApp( FunctionalGroupIDs preconsented_groups = group_types[kTypePreconsented]; FunctionalGroupIDs consent_allowed_groups = group_types[kTypeAllowed]; FunctionalGroupIDs consent_disallowed_groups = group_types[kTypeDisallowed]; - FunctionalGroupIDs default_groups = group_types[kTypeDefault]; - FunctionalGroupIDs predataconsented_groups = - group_types[kTypePreDataConsented]; - FunctionalGroupIDs device_groups = group_types[kTypeDevice]; // Sorting groups by consent FunctionalGroupIDs preconsented_wo_auto = @@ -1113,15 +1257,8 @@ void PolicyManagerImpl::GetUserConsentForApp( FunctionalGroupIDs allowed_groups = Merge(consent_allowed_groups, preconsented_wo_disallowed_auto); - FunctionalGroupIDs merged_stage_1 = - Merge(default_groups, predataconsented_groups); - - FunctionalGroupIDs merged_stage_2 = Merge(merged_stage_1, device_groups); - - FunctionalGroupIDs merged_stage_3 = - Merge(merged_stage_2, auto_allowed_groups); - - FunctionalGroupIDs excluded_stage_1 = ExcludeSame(all_groups, merged_stage_3); + FunctionalGroupIDs excluded_stage_1 = + ExcludeSame(all_groups, auto_allowed_groups); FunctionalGroupIDs excluded_stage_2 = ExcludeSame(excluded_stage_1, consent_disallowed_groups); @@ -1774,13 +1911,15 @@ StatusNotifier PolicyManagerImpl::AddApplication( DeviceConsent device_consent = GetUserConsentForDevice(device_id); sync_primitives::AutoLock lock(apps_registration_lock_); if (IsNewApplication(application_id)) { + LOG4CXX_DEBUG(logger_, "Adding new application"); AddNewApplication(application_id, device_consent); return std::make_shared<CallStatusChange>(update_status_manager_, device_consent); - } else { - PromoteExistedApplication(application_id, device_consent); - return std::make_shared<utils::CallNothing>(); } + LOG4CXX_DEBUG(logger_, "Promote existed application"); + PromoteExistedApplication(application_id, device_consent); + update_status_manager_.OnExistedApplicationAdded(cache_->UpdateRequired()); + return std::make_shared<utils::CallNothing>(); } void PolicyManagerImpl::RemoveAppConsentForGroup( @@ -1894,7 +2033,6 @@ bool PolicyManagerImpl::InitPT(const std::string& file_name, const bool ret = cache_->Init(file_name, settings); if (ret) { RefreshRetrySequence(); - update_status_manager_.OnPolicyInit(cache_->UpdateRequired()); } return ret; } diff --git a/src/components/policy/policy_external/src/policy_table/enums.cc b/src/components/policy/policy_external/src/policy_table/enums.cc index 31a6fc86e6..27db505e3f 100644 --- a/src/components/policy/policy_external/src/policy_table/enums.cc +++ b/src/components/policy/policy_external/src/policy_table/enums.cc @@ -14,6 +14,8 @@ bool IsValidEnum(Priority val) { return true; case P_NORMAL: return true; + case P_PROJECTION: + return true; case P_NONE: return true; default: @@ -32,6 +34,8 @@ const char* EnumToJsonString(Priority val) { return "COMMUNICATION"; case P_NORMAL: return "NORMAL"; + case P_PROJECTION: + return "PROJECTION"; case P_NONE: return "NONE"; default: @@ -54,6 +58,9 @@ bool EnumFromJsonString(const std::string& literal, Priority* result) { } else if ("NORMAL" == literal) { *result = P_NORMAL; return true; + } else if ("PROJECTION" == literal) { + *result = P_PROJECTION; + return true; } else if ("NONE" == literal) { *result = P_NONE; return true; @@ -833,6 +840,359 @@ bool EnumFromJsonString(const std::string& literal, ModuleType* result) { } } +bool EnumFromJsonString(const std::string& literal, FunctionID* result) { + if ("RegisterAppInterface" == literal) { + *result = RegisterAppInterfaceID; + return true; + } + + if ("UnregisterAppInterface" == literal) { + *result = UnregisterAppInterfaceID; + return true; + } + + if ("SetGlobalProperties" == literal) { + *result = SetGlobalPropertiesID; + return true; + } + + if ("ResetGlobalProperties" == literal) { + *result = ResetGlobalPropertiesID; + return true; + } + + if ("AddCommand" == literal) { + *result = AddCommandID; + return true; + } + + if ("DeleteCommand" == literal) { + *result = DeleteCommandID; + return true; + } + + if ("AddSubMenu" == literal) { + *result = AddSubMenuID; + return true; + } + + if ("DeleteSubMenu" == literal) { + *result = DeleteSubMenuID; + return true; + } + + if ("CreateInteractionChoiceSet" == literal) { + *result = CreateInteractionChoiceSetID; + return true; + } + + if ("PerformInteraction" == literal) { + *result = PerformInteractionID; + return true; + } + + if ("DeleteInteractionChoiceSet" == literal) { + *result = DeleteInteractionChoiceSetID; + return true; + } + + if ("Alert" == literal) { + *result = AlertID; + return true; + } + + if ("Show" == literal) { + *result = ShowID; + return true; + } + + if ("Speak" == literal) { + *result = SpeakID; + return true; + } + + if ("SetMediaClockTimer" == literal) { + *result = SetMediaClockTimerID; + return true; + } + + if ("PerformAudioPassThru" == literal) { + *result = PerformAudioPassThruID; + return true; + } + + if ("EndAudioPassThru" == literal) { + *result = EndAudioPassThruID; + return true; + } + + if ("SubscribeButton" == literal) { + *result = SubscribeButtonID; + return true; + } + + if ("UnsubscribeButton" == literal) { + *result = UnsubscribeButtonID; + return true; + } + + if ("SubscribeVehicleData" == literal) { + *result = SubscribeVehicleDataID; + return true; + } + + if ("UnsubscribeVehicleData" == literal) { + *result = UnsubscribeVehicleDataID; + return true; + } + + if ("GetVehicleData" == literal) { + *result = GetVehicleDataID; + return true; + } + + if ("ReadDID" == literal) { + *result = ReadDIDID; + return true; + } + + if ("GetDTCs" == literal) { + *result = GetDTCsID; + return true; + } + + if ("ScrollableMessage" == literal) { + *result = ScrollableMessageID; + return true; + } + + if ("Slider" == literal) { + *result = SliderID; + return true; + } + + if ("ShowConstantTBT" == literal) { + *result = ShowConstantTBTID; + return true; + } + + if ("AlertManeuver" == literal) { + *result = AlertManeuverID; + return true; + } + + if ("UpdateTurnList" == literal) { + *result = UpdateTurnListID; + return true; + } + + if ("ChangeRegistration" == literal) { + *result = ChangeRegistrationID; + return true; + } + + if ("GenericResponse" == literal) { + *result = GenericResponseID; + return true; + } + + if ("PutFile" == literal) { + *result = PutFileID; + return true; + } + + if ("DeleteFile" == literal) { + *result = DeleteFileID; + return true; + } + + if ("ListFiles" == literal) { + *result = ListFilesID; + return true; + } + + if ("SetAppIcon" == literal) { + *result = SetAppIconID; + return true; + } + + if ("SetDisplayLayout" == literal) { + *result = SetDisplayLayoutID; + return true; + } + + if ("DiagnosticMessage" == literal) { + *result = DiagnosticMessageID; + return true; + } + + if ("SystemRequest" == literal) { + *result = SystemRequestID; + return true; + } + + if ("SendLocation" == literal) { + *result = SendLocationID; + return true; + } + + if ("DialNumber" == literal) { + *result = DialNumberID; + return true; + } + + if ("ButtonPress" == literal) { + *result = ButtonPressID; + return true; + } + + if ("GetInteriorVehicleData" == literal) { + *result = GetInteriorVehicleDataID; + return true; + } + + if ("SetInteriorVehicleData" == literal) { + *result = SetInteriorVehicleDataID; + return true; + } + + if ("GetWayPoints" == literal) { + *result = GetWayPointsID; + return true; + } + + if ("SubscribeWayPoints" == literal) { + *result = SubscribeWayPointsID; + return true; + } + + if ("UnsubscribeWayPoints" == literal) { + *result = UnsubscribeWayPointsID; + return true; + } + + if ("GetSystemCapability" == literal) { + *result = GetSystemCapabilityID; + return true; + } + + if ("SendHapticData" == literal) { + *result = SendHapticDataID; + return true; + } + + if ("OnHMIStatus" == literal) { + *result = OnHMIStatusID; + return true; + } + + if ("OnAppInterfaceUnregistered" == literal) { + *result = OnAppInterfaceUnregisteredID; + return true; + } + + if ("OnButtonEvent" == literal) { + *result = OnButtonEventID; + return true; + } + + if ("OnButtonPress" == literal) { + *result = OnButtonPressID; + return true; + } + + if ("OnVehicleData" == literal) { + *result = OnVehicleDataID; + return true; + } + + if ("OnCommand" == literal) { + *result = OnCommandID; + return true; + } + + if ("OnTBTClientState" == literal) { + *result = OnTBTClientStateID; + return true; + } + + if ("OnDriverDistraction" == literal) { + *result = OnDriverDistractionID; + return true; + } + + if ("OnPermissionsChange" == literal) { + *result = OnPermissionsChangeID; + return true; + } + + if ("OnAudioPassThru" == literal) { + *result = OnAudioPassThruID; + return true; + } + + if ("OnLanguageChange" == literal) { + *result = OnLanguageChangeID; + return true; + } + + if ("OnKeyboardInput" == literal) { + *result = OnKeyboardInputID; + return true; + } + + if ("OnTouchEvent" == literal) { + *result = OnTouchEventID; + return true; + } + + if ("OnSystemRequest" == literal) { + *result = OnSystemRequestID; + return true; + } + + if ("OnHashChange" == literal) { + *result = OnHashChangeID; + return true; + } + + if ("OnInteriorVehicleData" == literal) { + *result = OnInteriorVehicleDataID; + return true; + } + + if ("OnWayPointChange" == literal) { + *result = OnWayPointChangeID; + return true; + } + + if ("OnRCStatus" == literal) { + *result = OnRCStatusID; + return true; + } + + if ("EncodedSyncPData" == literal) { + *result = EncodedSyncPDataID; + return true; + } + + if ("SyncPData" == literal) { + *result = SyncPDataID; + return true; + } + + if ("OnEncodedSyncPData" == literal) { + *result = OnEncodedSyncPDataID; + return true; + } + + if ("OnSyncPData" == literal) { + *result = OnSyncPDataID; + return true; + } + return false; +}; + const std::string kDefaultApp = "default"; const std::string kPreDataConsentApp = "pre_DataConsent"; const std::string kDeviceApp = "device"; diff --git a/src/components/policy/policy_external/src/sql_pt_ext_representation.cc b/src/components/policy/policy_external/src/sql_pt_ext_representation.cc index f26264ddf9..a43b22a3b8 100644 --- a/src/components/policy/policy_external/src/sql_pt_ext_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_ext_representation.cc @@ -874,30 +874,39 @@ bool SQLPTExtRepresentation::GatherApplicationPoliciesSection( *params.memory_kb = query.GetInteger(5); *params.heart_beat_timeout_ms = query.GetUInteger(6); - if (!GatherAppGroup(app_id, ¶ms.groups)) { + const auto& gather_app_id = ((*policies).apps[app_id].is_string()) + ? (*policies).apps[app_id].get_string() + : app_id; + // Data should be gathered from db by "default" key if application has + // default policies + + if (!GatherAppGroup(gather_app_id, ¶ms.groups)) { return false; } bool denied = false; - if (!GatherRemoteControlDenied(app_id, &denied)) { + if (!GatherRemoteControlDenied(gather_app_id, &denied)) { return false; } if (!denied) { - if (!GatherModuleType(app_id, &*params.moduleType)) { + if (!GatherModuleType(gather_app_id, &*params.moduleType)) { return false; } } - if (!GatherNickName(app_id, &*params.nicknames)) { + if (!GatherNickName(gather_app_id, &*params.nicknames)) { + return false; + } + if (!GatherAppType(gather_app_id, &*params.AppHMIType)) { return false; } - if (!GatherAppType(app_id, &*params.AppHMIType)) { + if (!GatherRequestType(gather_app_id, &*params.RequestType)) { return false; } - if (!GatherRequestType(app_id, &*params.RequestType)) { + if (!GatherRequestSubType(gather_app_id, &*params.RequestSubType)) { return false; } - GatherPreconsentedGroup(app_id, &*params.preconsented_groups); + GatherPreconsentedGroup(gather_app_id, &*params.preconsented_groups); (*policies).apps[app_id] = params; } return true; diff --git a/src/components/policy/policy_external/src/sql_pt_queries.cc b/src/components/policy/policy_external/src/sql_pt_queries.cc index ee53eb1487..97d75731ea 100644 --- a/src/components/policy/policy_external/src/sql_pt_queries.cc +++ b/src/components/policy/policy_external/src/sql_pt_queries.cc @@ -645,19 +645,11 @@ const std::string kInsertRequestType = "INSERT OR IGNORE INTO `request_type` (`application_id`, `request_type`) " "VALUES (?, ?)"; -const std::string kInsertOmittedRequestType = - "INSERT INTO `request_type` (`application_id`) " - "VALUES (?)"; - const std::string kInsertRequestSubType = "INSERT INTO `request_subtype` (`application_id`, " "`request_subtype`) " "VALUES (?, ?)"; -const std::string kInsertOmittedRequestSubType = - "INSERT INTO `request_subtype` (`application_id`) " - "VALUES (?)"; - const std::string kUpdateVersion = "UPDATE `version` SET `number`= ?"; const std::string kInsertMessageType = diff --git a/src/components/policy/policy_external/src/sql_pt_representation.cc b/src/components/policy/policy_external/src/sql_pt_representation.cc index 34c5b90903..c8b367c8ec 100644 --- a/src/components/policy/policy_external/src/sql_pt_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_representation.cc @@ -761,30 +761,36 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection( *params.memory_kb = query.GetInteger(2); *params.heart_beat_timeout_ms = query.GetUInteger(3); - if (!GatherAppGroup(app_id, ¶ms.groups)) { + const auto& gather_app_id = ((*policies).apps[app_id].is_string()) + ? (*policies).apps[app_id].get_string() + : app_id; + // Data should be gathered from db by "default" key if application has + // default policies + + if (!GatherAppGroup(gather_app_id, ¶ms.groups)) { return false; } bool denied = false; - if (!GatherRemoteControlDenied(app_id, &denied)) { + if (!GatherRemoteControlDenied(gather_app_id, &denied)) { return false; } if (!denied) { - if (!GatherModuleType(app_id, &*params.moduleType)) { + if (!GatherModuleType(gather_app_id, &*params.moduleType)) { return false; } } - if (!GatherNickName(app_id, &*params.nicknames)) { + if (!GatherNickName(gather_app_id, &*params.nicknames)) { return false; } - if (!GatherAppType(app_id, &*params.AppHMIType)) { + if (!GatherAppType(gather_app_id, &*params.AppHMIType)) { return false; } - if (!GatherRequestType(app_id, &*params.RequestType)) { + if (!GatherRequestType(gather_app_id, &*params.RequestType)) { return false; } - if (!GatherRequestSubType(app_id, &*params.RequestSubType)) { + if (!GatherRequestSubType(gather_app_id, &*params.RequestSubType)) { return false; } @@ -1193,18 +1199,6 @@ bool SQLPTRepresentation::SaveRequestType( LOG4CXX_WARN(logger_, "Incorrect insert into request types."); return false; } - } else { - utils::dbms::SQLQuery query_omitted(db()); - if (!query_omitted.Prepare(sql_pt::kInsertOmittedRequestType)) { - LOG4CXX_WARN(logger_, "Incorrect insert statement for request types."); - return false; - } - LOG4CXX_WARN(logger_, "Request types omitted."); - query_omitted.Bind(0, app_id); - if (!query_omitted.Exec() || !query_omitted.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect insert into request types."); - return false; - } } return true; } @@ -1237,18 +1231,6 @@ bool SQLPTRepresentation::SaveRequestSubType( LOG4CXX_WARN(logger_, "Incorrect insert into request subtypes."); return false; } - } else { - utils::dbms::SQLQuery query_omitted(db()); - if (!query_omitted.Prepare(sql_pt::kInsertOmittedRequestSubType)) { - LOG4CXX_WARN(logger_, "Incorrect insert statement for request subtypes."); - return false; - } - LOG4CXX_WARN(logger_, "Request subtypes omitted."); - query_omitted.Bind(0, app_id); - if (!query_omitted.Exec() || !query_omitted.Reset()) { - LOG4CXX_WARN(logger_, "Incorrect insert into request subtypes."); - return false; - } } return true; } diff --git a/src/components/policy/policy_external/src/update_status_manager.cc b/src/components/policy/policy_external/src/update_status_manager.cc index e738554799..b352b5ea39 100644 --- a/src/components/policy/policy_external/src/update_status_manager.cc +++ b/src/components/policy/policy_external/src/update_status_manager.cc @@ -118,24 +118,27 @@ void UpdateStatusManager::OnResetRetrySequence() { ProcessEvent(kOnResetRetrySequence); } +void UpdateStatusManager::OnExistedApplicationAdded( + const bool is_update_required) { + LOG4CXX_AUTO_TRACE(logger_); + if (is_update_required) { + current_status_.reset(new UpToDateStatus()); + ProcessEvent(kScheduleUpdate); + } +} + void UpdateStatusManager::OnNewApplicationAdded(const DeviceConsent consent) { LOG4CXX_AUTO_TRACE(logger_); if (kDeviceAllowed != consent) { + LOG4CXX_DEBUG(logger_, "Application registered from non-consented device"); app_registered_from_non_consented_device_ = true; return; } + LOG4CXX_DEBUG(logger_, "Application registered from consented device"); app_registered_from_non_consented_device_ = false; ProcessEvent(kOnNewAppRegistered); } -void UpdateStatusManager::OnPolicyInit(bool is_update_required) { - LOG4CXX_AUTO_TRACE(logger_); - if (is_update_required) { - current_status_.reset(new UpToDateStatus()); - ProcessEvent(kScheduleUpdate); - } -} - void UpdateStatusManager::OnDeviceConsented() { LOG4CXX_AUTO_TRACE(logger_); if (app_registered_from_non_consented_device_) { diff --git a/src/components/policy/policy_external/test/include/policy/mock_update_status_manager.h b/src/components/policy/policy_external/test/include/policy/mock_update_status_manager.h index a1c808d23a..662632fc59 100644 --- a/src/components/policy/policy_external/test/include/policy/mock_update_status_manager.h +++ b/src/components/policy/policy_external/test/include/policy/mock_update_status_manager.h @@ -33,7 +33,6 @@ #define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_TEST_INCLUDE_POLICY_MOCK_UPDATE_STATUS_MANAGER_H_ #include "gmock/gmock.h" - #include "policy/update_status_manager.h" namespace test { @@ -49,8 +48,8 @@ class MockUpdateStatusManager : public ::policy::UpdateStatusManager { MOCK_METHOD0(OnWrongUpdateReceived, void()); MOCK_METHOD1(OnResetDefaultPT, void(bool is_update_required)); MOCK_METHOD0(OnResetRetrySequence, void()); + MOCK_METHOD1(OnExistedApplicationAdded, void(const bool is_update_required)); MOCK_METHOD1(OnNewApplicationAdded, void(const DeviceConsent)); - MOCK_METHOD1(OnPolicyInit, void(bool is_update_required)); MOCK_METHOD0(GetUpdateStatus, PolicyTableStatus()); }; diff --git a/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc b/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc index dd9b43d53c..93d4e19751 100644 --- a/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc +++ b/src/components/policy/policy_external/test/policy_manager_impl_ptu_test.cc @@ -113,27 +113,27 @@ TEST_F(PolicyManagerImplTest2, GetNotificationsNumberAfterPTUpdate) { EXPECT_TRUE(policy_manager_->LoadPT(kFilePtUpdateJson, msg)); EXPECT_FALSE(policy_manager_->GetCache()->IsPTPreloaded()); - std::string priority = "emergency"; + std::string priority = "EMERGENCY"; uint32_t notif_number = policy_manager_->GetNotificationsNumber(priority); EXPECT_EQ(1u, notif_number); - priority = "navigation"; + priority = "NAVIGATION"; notif_number = policy_manager_->GetNotificationsNumber(priority); EXPECT_EQ(2u, notif_number); - priority = "emergency"; + priority = "EMERGENCY"; notif_number = policy_manager_->GetNotificationsNumber(priority); EXPECT_EQ(1u, notif_number); - priority = "VOICECOMM"; + priority = "VOICECOM"; notif_number = policy_manager_->GetNotificationsNumber(priority); EXPECT_EQ(3u, notif_number); - priority = "normal"; + priority = "NORMAL"; notif_number = policy_manager_->GetNotificationsNumber(priority); EXPECT_EQ(5u, notif_number); - priority = "none"; + priority = "NONE"; notif_number = policy_manager_->GetNotificationsNumber(priority); EXPECT_EQ(6u, notif_number); } diff --git a/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc b/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc index 86b7cdc9ef..13efa39805 100644 --- a/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc +++ b/src/components/policy/policy_external/test/policy_manager_impl_test_base.cc @@ -105,12 +105,12 @@ Json::Value createPTforLoad() { "}" "}," "\"notifications_per_minute_by_priority\": {" - "\"emergency\": 1," - "\"navigation\": 2," - "\"VOICECOMM\": 3," - "\"communication\": 4," - "\"normal\": 5," - "\"none\": 6" + "\"EMERGENCY\": 1," + "\"NAVIGATION\": 2," + "\"VOICECOM\": 3," + "\"COMMUNICATION\": 4," + "\"NORMAL\": 5," + "\"NONE\": 6" "}," "\"vehicle_make\" : \"MakeT\"," "\"vehicle_model\" : \"ModelT\"," diff --git a/src/components/policy/policy_external/test/update_status_manager_test.cc b/src/components/policy/policy_external/test/update_status_manager_test.cc index 278c4fc43a..bf443bb201 100644 --- a/src/components/policy/policy_external/test/update_status_manager_test.cc +++ b/src/components/policy/policy_external/test/update_status_manager_test.cc @@ -287,42 +287,6 @@ TEST_F(UpdateStatusManagerTest, ScheduleUpdate_ExpectStatusUpdateNeeded) { } TEST_F(UpdateStatusManagerTest, - OnPolicyInit_SetUpdateRequired_ExpectStatusUpdateNeeded) { - // Arrange - manager_->OnPolicyInit(true); - status_ = manager_->GetLastUpdateStatus(); - // Checks - EXPECT_EQ(StatusUpdateRequired, status_); - EXPECT_FALSE(manager_->IsUpdatePending()); - EXPECT_TRUE(manager_->IsUpdateRequired()); -} - -TEST_F(UpdateStatusManagerTest, - OnPolicyInit_SetUpdateNotRequired_ExpectStatusUpToDate) { - // Arrange - manager_->OnPolicyInit(false); - status_ = manager_->GetLastUpdateStatus(); - // Checks - EXPECT_EQ(StatusUpToDate, status_); - EXPECT_FALSE(manager_->IsUpdatePending()); - EXPECT_FALSE(manager_->IsUpdateRequired()); -} - -TEST_F(UpdateStatusManagerTest, - StringifiedUpdateStatus_SetStatuses_ExpectCorrectStringifiedStatuses) { - // Arrange - manager_->OnPolicyInit(false); - // Check - EXPECT_EQ("UP_TO_DATE", manager_->StringifiedUpdateStatus()); - manager_->OnPolicyInit(true); - // Check - EXPECT_EQ("UPDATE_NEEDED", manager_->StringifiedUpdateStatus()); - manager_->OnUpdateSentOut(k_timeout_); - // Check - EXPECT_EQ("UPDATING", manager_->StringifiedUpdateStatus()); -} - -TEST_F(UpdateStatusManagerTest, OnAppSearchStartedCompleted_ExpectAppSearchCorrectStatus) { // Arrange manager_->OnAppsSearchStarted(); |