diff options
Diffstat (limited to 'src/components/application_manager')
18 files changed, 750 insertions, 331 deletions
diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index c34affbf13..add099f975 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -517,32 +517,6 @@ class ApplicationManagerImpl bool IsApplicationForbidden(uint32_t connection_key, const std::string& mobile_app_id); - struct ApplicationsAppIdSorter { - bool operator()(const ApplicationSharedPtr lhs, - const ApplicationSharedPtr rhs) { - return lhs->app_id() < rhs->app_id(); - } - }; - - struct ApplicationsMobileAppIdSorter { - bool operator()(const ApplicationSharedPtr lhs, - const ApplicationSharedPtr rhs) { - if (lhs->policy_app_id() == rhs->policy_app_id()) { - return lhs->device() < rhs->device(); - } - return lhs->policy_app_id() < rhs->policy_app_id(); - } - }; - - // typedef for Applications list - typedef std::set<ApplicationSharedPtr, ApplicationsAppIdSorter> ApplictionSet; - - // typedef for Applications list iterator - typedef ApplictionSet::iterator ApplictionSetIt; - - // typedef for Applications list const iterator - typedef ApplictionSet::const_iterator ApplictionSetConstIt; - /** * @brief Notification from PolicyHandler about PTU. * Compares AppHMIType between saved in app and received from PTU. If they are @@ -1065,10 +1039,12 @@ class ApplicationManagerImpl * @brief IsAppInReconnectMode check if application belongs to session * affected by transport switching at the moment by checking internal * waiting list prepared on switching start + * @param device_id device identifier * @param policy_app_id Application id * @return True if application is in the waiting list, otherwise - false */ - bool IsAppInReconnectMode(const std::string& policy_app_id) const FINAL; + bool IsAppInReconnectMode(const connection_handler::DeviceHandle& device_id, + const std::string& policy_app_id) const FINAL; bool IsStopping() const OVERRIDE { return is_stopping_; diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index 917f8be559..3422a2a2d2 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -87,11 +87,14 @@ class PolicyHandler : public PolicyHandlerInterface, bool ReceiveMessageFromSDK(const std::string& file, const BinaryMessage& pt_string) OVERRIDE; bool UnloadPolicyLibrary() OVERRIDE; - virtual void OnPermissionsUpdated(const std::string& policy_app_id, + + virtual void OnPermissionsUpdated(const std::string& device_id, + const std::string& policy_app_id, const Permissions& permissions, const HMILevel& default_hmi) OVERRIDE; - virtual void OnPermissionsUpdated(const std::string& policy_app_id, + virtual void OnPermissionsUpdated(const std::string& device_id, + const std::string& policy_app_id, const Permissions& permissions) OVERRIDE; #ifdef EXTERNAL_PROPRIETARY_MODE @@ -115,10 +118,12 @@ class PolicyHandler : public PolicyHandlerInterface, /** * @brief Sets HMI default type for specified application + * @param device_handle device identifier * @param application_id ID application * @param app_types list of HMI types */ - void SetDefaultHmiTypes(const std::string& application_id, + void SetDefaultHmiTypes(const transport_manager::DeviceHandle& device_handle, + const std::string& application_id, const smart_objects::SmartObject* app_types) OVERRIDE; /** @@ -177,7 +182,8 @@ class PolicyHandler : public PolicyHandlerInterface, bool GetModuleTypes(const std::string& policy_app_id, std::vector<std::string>* modules) const OVERRIDE; - bool GetDefaultHmi(const std::string& policy_app_id, + bool GetDefaultHmi(const std::string& device_id, + const std::string& policy_app_id, std::string* default_hmi) const OVERRIDE; bool GetInitialAppData(const std::string& application_id, StringArray* nicknames = NULL, @@ -250,7 +256,8 @@ class PolicyHandler : public PolicyHandlerInterface, */ void OnIgnitionCycleOver() OVERRIDE; - void OnPendingPermissionChange(const std::string& policy_app_id) OVERRIDE; + void OnPendingPermissionChange(const std::string& device_id, + const std::string& policy_app_id) OVERRIDE; /** * Initializes PT exchange at user request @@ -337,9 +344,11 @@ class PolicyHandler : public PolicyHandlerInterface, /** * @brief Update currently used device id in policies manager for given * application + * @param device_handle device identifier * @param policy_app_id Application id */ std::string OnCurrentDeviceIdUpdateRequired( + const transport_manager::DeviceHandle& device_handle, const std::string& policy_app_id) OVERRIDE; /** @@ -503,6 +512,7 @@ class PolicyHandler : public PolicyHandlerInterface, virtual void SendOnAppPermissionsChanged( const AppPermissions& permissions, + const std::string& device_id, const std::string& policy_app_id) const OVERRIDE; virtual void OnPTExchangeNeeded() OVERRIDE; @@ -512,11 +522,13 @@ class PolicyHandler : public PolicyHandlerInterface, /** * @brief Allows to add new or update existed application during * registration process + * @param device_id device identifier * @param application_id The policy aplication id. * @param hmi_types list of hmi types * @return function that will notify update manager about new application */ StatusNotifier AddApplication( + const std::string& device_id, const std::string& application_id, const rpc::policy_table_interface_base::AppHmiTypes& hmi_types) OVERRIDE; @@ -560,17 +572,21 @@ class PolicyHandler : public PolicyHandlerInterface, * succesfully registered on mobile device. * It will send OnAppPermissionSend notification and will try to start PTU. * + * @param device_id device identifier * @param application_id registered application. */ - void OnAppRegisteredOnMobile(const std::string& application_id) OVERRIDE; + void OnAppRegisteredOnMobile(const std::string& device_id, + const std::string& application_id) OVERRIDE; /** * @brief Checks if certain request type is allowed for application + * @param device_handle device identifier * @param policy_app_id Unique applicaion id * @param type Request type * @return true, if allowed, otherwise - false */ bool IsRequestTypeAllowed( + const transport_manager::DeviceHandle& device_handle, const std::string& policy_app_id, mobile_apis::RequestType::eType type) const OVERRIDE; @@ -602,10 +618,12 @@ class PolicyHandler : public PolicyHandlerInterface, /** * @brief Gets application request types + * @param device_id device identifier * @param policy_app_id Unique application id * @return request types */ const std::vector<std::string> GetAppRequestTypes( + const transport_manager::DeviceHandle& device_id, const std::string& policy_app_id) const OVERRIDE; /** @@ -725,7 +743,7 @@ class PolicyHandler : public PolicyHandlerInterface, void UpdateHMILevel(application_manager::ApplicationSharedPtr app, mobile_apis::HMILevel::eType level); std::vector<std::string> GetDevicesIds( - const std::string& policy_app_id) OVERRIDE; + const std::string& policy_app_id) const OVERRIDE; /** * @brief Sets days after epoch on successful policy update diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/change_registration_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/change_registration_request.h index 01f20a68e3..f9f780b84b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/change_registration_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/change_registration_request.h @@ -123,11 +123,12 @@ class ChangeRegistrationRequest /** * @brief Check parameters (name, vr) for * coincidence with already known parameters of registered applications - * + * @param device_id device identifier * @return SUCCESS if there is no coincidence of app.name/VR synonyms, * otherwise appropriate error code returns */ - mobile_apis::Result::eType CheckCoincidence(); + mobile_apis::Result::eType CheckCoincidence( + const connection_handler::DeviceHandle& device_id); /** * @brief Checks if requested name is allowed by policy diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h index 8a80db9cdf..c894b355d6 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h @@ -215,9 +215,23 @@ class RegisterAppInterfaceRequest */ bool IsApplicationSwitched(); + /** + * @brief Information about given Connection Key. + * @param key Unique key used by other components as session identifier + * @param device_id device identifier. + * @param mac_address uniq address + * @return false in case of error or true in case of success + */ + bool GetDataOnSessionKey( + const uint32_t key, + connection_handler::DeviceHandle* device_id = nullptr, + std::string* mac_address = nullptr) const; + private: std::string response_info_; mobile_apis::Result::eType result_code_; + connection_handler::DeviceHandle device_handle_; + std::string device_id_; policy::PolicyHandlerInterface& GetPolicyHandler(); DISALLOW_COPY_AND_ASSIGN(RegisterAppInterfaceRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/cancel_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/cancel_interaction_request.cc index d9a7eccddf..82e0703da1 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/cancel_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/cancel_interaction_request.cc @@ -61,12 +61,13 @@ void CancelInteractionRequest::Run() { auto function_id = static_cast<mobile_apis::FunctionID::eType>( (*message_)[strings::msg_params][strings::func_id].asInt()); - if (helpers::Compare<mobile_apis::FunctionID::eType, helpers::NEQ, helpers::ALL>( - function_id, - mobile_apis::FunctionID::PerformInteractionID, - mobile_apis::FunctionID::AlertID, - mobile_apis::FunctionID::ScrollableMessageID, - mobile_apis::FunctionID::SliderID)) { + if (helpers:: + Compare<mobile_apis::FunctionID::eType, helpers::NEQ, helpers::ALL>( + function_id, + mobile_apis::FunctionID::PerformInteractionID, + mobile_apis::FunctionID::AlertID, + mobile_apis::FunctionID::ScrollableMessageID, + mobile_apis::FunctionID::SliderID)) { LOG4CXX_ERROR(logger_, "Bad function ID" << function_id); SendResponse(false, mobile_apis::Result::INVALID_ID); return; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc index ef81babdd6..8940ea3f59 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc @@ -49,7 +49,7 @@ struct IsSameNickname { } private: - const custom_str::CustomString& app_id_; + const custom_str::CustomString app_id_; }; } // namespace @@ -160,7 +160,7 @@ void ChangeRegistrationRequest::Run() { return; } - if (mobile_apis::Result::SUCCESS != CheckCoincidence()) { + if (mobile_apis::Result::SUCCESS != CheckCoincidence(app->device())) { SendResponse(false, mobile_apis::Result::DUPLICATE_NAME); return; } @@ -578,36 +578,46 @@ bool ChangeRegistrationRequest::IsWhiteSpaceExist() { return false; } -mobile_apis::Result::eType ChangeRegistrationRequest::CheckCoincidence() { +mobile_apis::Result::eType ChangeRegistrationRequest::CheckCoincidence( + const connection_handler::DeviceHandle& device_id) { LOG4CXX_AUTO_TRACE(logger_); const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; - ApplicationSet accessor = application_manager_.applications().GetData(); + auto compare_tts_name = [](const smart_objects::SmartObject& obj_1, + const smart_objects::SmartObject& obj_2) { + return obj_1[application_manager::strings::text] + .asCustomString() + .CompareIgnoreCase( + obj_2[application_manager::strings::text].asCustomString()); + }; + + const auto& accessor = application_manager_.applications().GetData(); custom_str::CustomString app_name; - uint32_t app_id = connection_key(); + const uint32_t app_id = connection_key(); if (msg_params.keyExists(strings::app_name)) { app_name = msg_params[strings::app_name].asCustomString(); } - ApplicationSetConstIt it = accessor.begin(); - for (; accessor.end() != it; ++it) { - if (app_id == (*it)->app_id()) { + for (const auto& app : accessor) { + if (app->device() != device_id) { + continue; + } + + if (app->app_id() == app_id) { continue; } - const custom_str::CustomString& cur_name = (*it)->name(); + const auto& cur_name = app->name(); if (msg_params.keyExists(strings::app_name)) { if (app_name.CompareIgnoreCase(cur_name)) { LOG4CXX_ERROR(logger_, "Application name is known already."); return mobile_apis::Result::DUPLICATE_NAME; } - - const smart_objects::SmartObject* vr = (*it)->vr_synonyms(); - const std::vector<smart_objects::SmartObject>* curr_vr = NULL; - if (NULL != vr) { - curr_vr = vr->asArray(); + const auto vr = app->vr_synonyms(); + if (vr) { + const auto curr_vr = vr->asArray(); CoincidencePredicateVR v(app_name); if (0 != std::count_if(curr_vr->begin(), curr_vr->end(), v)) { @@ -617,18 +627,37 @@ mobile_apis::Result::eType ChangeRegistrationRequest::CheckCoincidence() { } } - // vr check + // VR check if (msg_params.keyExists(strings::vr_synonyms)) { - const std::vector<smart_objects::SmartObject>* new_vr = - msg_params[strings::vr_synonyms].asArray(); + const auto new_vr = msg_params[strings::vr_synonyms].asArray(); CoincidencePredicateVR v(cur_name); if (0 != std::count_if(new_vr->begin(), new_vr->end(), v)) { LOG4CXX_ERROR(logger_, "vr_synonyms duplicated with app_name ."); return mobile_apis::Result::DUPLICATE_NAME; } - } // end vr check - } // application for end + } // End vr check + + // TTS check + if (msg_params.keyExists(strings::tts_name) && app->tts_name()) { + const auto tts_array = msg_params[strings::tts_name].asArray(); + const auto tts_curr = app->tts_name()->asArray(); + const auto& it_tts = std::find_first_of(tts_array->begin(), + tts_array->end(), + tts_curr->begin(), + tts_curr->end(), + compare_tts_name); + if (it_tts != tts_array->end()) { + LOG4CXX_ERROR( + logger_, + "TTS name: " + << (*it_tts)[strings::text].asCustomString().AsMBString() + << " is known already"); + return mobile_apis::Result::DUPLICATE_NAME; + } + } // End tts check + + } // Application for end return mobile_apis::Result::SUCCESS; } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc index a85dec10bb..fc99bb323c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc @@ -86,8 +86,8 @@ void OnSystemRequestNotification::Run() { static_cast<rpc::policy_table_interface_base::RequestType>( request_type)); - if (!policy_handler.IsRequestTypeAllowed(app->policy_app_id(), - request_type)) { + if (!policy_handler.IsRequestTypeAllowed( + app->device(), app->policy_app_id(), request_type)) { LOG4CXX_WARN(logger_, "Request type " << stringified_request_type << " is not allowed by policies"); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc index 701002ed65..f0da4ebbab 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc @@ -164,7 +164,7 @@ struct IsSameNickname { } private: - const custom_str::CustomString& app_id_; + const custom_str::CustomString app_id_; }; } // namespace @@ -184,13 +184,14 @@ RegisterAppInterfaceRequest::RegisterAppInterfaceRequest( rpc_service, hmi_capabilities, policy_handler) - , result_code_(mobile_apis::Result::INVALID_ENUM) {} + , result_code_(mobile_apis::Result::INVALID_ENUM) + , device_handle_(0) {} RegisterAppInterfaceRequest::~RegisterAppInterfaceRequest() {} bool RegisterAppInterfaceRequest::Init() { LOG4CXX_AUTO_TRACE(logger_); - return true; + return GetDataOnSessionKey(connection_key(), &device_handle_, &device_id_); } void RegisterAppInterfaceRequest::Run() { @@ -224,20 +225,25 @@ void RegisterAppInterfaceRequest::Run() { return; } + LOG4CXX_DEBUG( + logger_, + "device_handle: " << device_handle_ << " device_id: " << device_id_); + if (IsApplicationSwitched()) { return; } + // Cache the original app ID (for legacy behavior) + const auto policy_app_id = + application_manager_.GetCorrectMobileIDFromMessage(message_); + ApplicationSharedPtr application = - application_manager_.application(connection_key()); + application_manager_.application(device_id_, policy_app_id); if (application) { SendResponse(false, mobile_apis::Result::APPLICATION_REGISTERED_ALREADY); return; } - // cache the original app ID (for legacy behavior) - const std::string policy_app_id = - application_manager_.GetCorrectMobileIDFromMessage(message_); const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; @@ -842,14 +848,15 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( } } policy::StatusNotifier notify_upd_manager = GetPolicyHandler().AddApplication( - application->policy_app_id(), hmi_types); + application->mac_address(), application->policy_app_id(), hmi_types); response_params[strings::icon_resumed] = file_system::FileExists(application->app_icon_path()); SendResponse(true, result_code, add_info.c_str(), &response_params); if (msg_params.keyExists(strings::app_hmi_type)) { - GetPolicyHandler().SetDefaultHmiTypes(application->policy_app_id(), + GetPolicyHandler().SetDefaultHmiTypes(application->device(), + application->policy_app_id(), &(msg_params[strings::app_hmi_type])); } @@ -863,7 +870,8 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( // Start PTU after successfull registration // Sends OnPermissionChange notification to mobile right after RAI response // and HMI level set-up - GetPolicyHandler().OnAppRegisteredOnMobile(application->policy_app_id()); + GetPolicyHandler().OnAppRegisteredOnMobile(application->mac_address(), + application->policy_app_id()); if (result_code != mobile_apis::Result::RESUME_FAILED) { resumer.StartResumption(application, hash_id); @@ -968,48 +976,72 @@ mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckCoincidence( const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; - ApplicationSet accessor = application_manager_.applications().GetData(); + auto compare_tts_name = [](const smart_objects::SmartObject& obj_1, + const smart_objects::SmartObject& obj_2) { + return obj_1[application_manager::strings::text] + .asCustomString() + .CompareIgnoreCase( + obj_2[application_manager::strings::text].asCustomString()); + }; - ApplicationSetConstIt it = accessor.begin(); - const custom_str::CustomString& app_name = - msg_params[strings::app_name].asCustomString(); + const auto& accessor = application_manager_.applications().GetData(); + const auto& app_name = msg_params[strings::app_name].asCustomString(); - for (; accessor.end() != it; ++it) { - // name check - const custom_str::CustomString& cur_name = (*it)->name(); + for (const auto& app : accessor) { + if (app->device() != device_handle_) { + continue; + } + // Name check + const auto& cur_name = app->name(); if (app_name.CompareIgnoreCase(cur_name)) { LOG4CXX_ERROR(logger_, "Application name is known already."); - out_duplicate_apps.push_back(*it); + out_duplicate_apps.push_back(app); continue; } - - const smart_objects::SmartObject* vr = (*it)->vr_synonyms(); - const std::vector<smart_objects::SmartObject>* curr_vr = NULL; - if (NULL != vr) { - curr_vr = vr->asArray(); + const auto vr = app->vr_synonyms(); + if (vr) { + const auto curr_vr = vr->asArray(); CoincidencePredicateVR v(app_name); if (0 != std::count_if(curr_vr->begin(), curr_vr->end(), v)) { LOG4CXX_ERROR(logger_, "Application name is known already."); - out_duplicate_apps.push_back(*it); + out_duplicate_apps.push_back(app); continue; } } - // vr check + // VR check if (msg_params.keyExists(strings::vr_synonyms)) { - const std::vector<smart_objects::SmartObject>* new_vr = - msg_params[strings::vr_synonyms].asArray(); + const auto new_vr = msg_params[strings::vr_synonyms].asArray(); CoincidencePredicateVR v(cur_name); if (0 != std::count_if(new_vr->begin(), new_vr->end(), v)) { LOG4CXX_ERROR(logger_, "vr_synonyms duplicated with app_name ."); - out_duplicate_apps.push_back(*it); + out_duplicate_apps.push_back(app); continue; } - } // end vr check + } // End vr check + + // TTS check + if (msg_params.keyExists(strings::tts_name) && app->tts_name()) { + const auto tts_array = msg_params[strings::tts_name].asArray(); + const auto tts_curr = app->tts_name()->asArray(); + const auto& it_tts = std::find_first_of(tts_array->begin(), + tts_array->end(), + tts_curr->begin(), + tts_curr->end(), + compare_tts_name); + if (it_tts != tts_array->end()) { + LOG4CXX_ERROR( + logger_, + "TTS name: " + << (*it_tts)[strings::text].asCustomString().AsMBString() + << " is known already"); + return mobile_apis::Result::DUPLICATE_NAME; + } + } // End tts check - } // application for end + } // Application for end if (!out_duplicate_apps.empty()) { return mobile_apis::Result::DUPLICATE_NAME; @@ -1138,14 +1170,19 @@ bool RegisterAppInterfaceRequest::IsApplicationWithSameAppIdRegistered() { const custom_string::CustomString mobile_app_id( application_manager_.GetCorrectMobileIDFromMessage(message_)); - const ApplicationSet& applications = - application_manager_.applications().GetData(); - - ApplicationSetConstIt it = applications.begin(); - ApplicationSetConstIt it_end = applications.end(); - - for (; it != it_end; ++it) { - if (mobile_app_id.CompareIgnoreCase((*it)->policy_app_id().c_str())) { + const auto& applications = application_manager_.applications().GetData(); + + for (const auto& app : applications) { + if (mobile_app_id.CompareIgnoreCase(app->policy_app_id().c_str())) { + if (app->device() != device_handle_) { + LOG4CXX_DEBUG(logger_, + "These policy_app_id equal, but applications have " + "different device id" + << " mobile_app_id: " << mobile_app_id.c_str() + << " device_handle: " << device_handle_ + << " device_handle: " << app->device()); + continue; + } return true; } } @@ -1330,7 +1367,7 @@ bool RegisterAppInterfaceRequest::IsApplicationSwitched() { LOG4CXX_DEBUG(logger_, "Looking for application id " << policy_app_id); - auto app = application_manager_.application_by_policy_id(policy_app_id); + auto app = application_manager_.application(device_id_, policy_app_id); if (!app) { LOG4CXX_DEBUG( @@ -1341,12 +1378,13 @@ bool RegisterAppInterfaceRequest::IsApplicationSwitched() { LOG4CXX_DEBUG(logger_, "Application with policy id " << policy_app_id << " is found."); - if (!application_manager_.IsAppInReconnectMode(policy_app_id)) { + if (!application_manager_.IsAppInReconnectMode(device_handle_, + policy_app_id)) { LOG4CXX_DEBUG( logger_, "Policy id " << policy_app_id << " is not found in reconnection list."); SendResponse(false, mobile_apis::Result::APPLICATION_REGISTERED_ALREADY); - return false; + return true; } LOG4CXX_DEBUG(logger_, "Application is found in reconnection list."); @@ -1372,6 +1410,51 @@ bool RegisterAppInterfaceRequest::IsApplicationSwitched() { return true; } +bool RegisterAppInterfaceRequest::GetDataOnSessionKey( + const uint32_t key, + connection_handler::DeviceHandle* device_id, + std::string* mac_address) const { + LOG4CXX_AUTO_TRACE(logger_); + + if ((nullptr == mac_address) && (nullptr == device_id)) { + LOG4CXX_ERROR(logger_, + "Can't get data on session key because device id and mac " + "address are empty."); + return false; + } + + connection_handler::DeviceHandle device_handle = 0; + auto& connect_handler = application_manager_.connection_handler(); + + auto result = connect_handler.GetDataOnSessionKey( + connection_key(), nullptr, nullptr, &device_handle); + + if (result) { + LOG4CXX_DEBUG( + logger_, + "Failed to get device info for connection key: " << connection_key()); + return false; + } + + if (mac_address) { + result = connect_handler.get_session_observer().GetDataOnDeviceID( + device_handle, nullptr, nullptr, mac_address, nullptr); + } + + if (result) { + LOG4CXX_DEBUG(logger_, + "Failed get unique address info for connection key: " + << connection_key()); + return false; + } + + if (device_id) { + *device_id = device_handle; + } + + return true; +} + policy::PolicyHandlerInterface& RegisterAppInterfaceRequest::GetPolicyHandler() { return policy_handler_; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/system_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/system_request.cc index e70433f29b..9be5a270f5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/system_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/system_request.cc @@ -470,8 +470,8 @@ void SystemRequest::Run() { static_cast<rpc::policy_table_interface_base::RequestType>( request_type)); - if (!policy_handler.IsRequestTypeAllowed(application->policy_app_id(), - request_type)) { + if (!policy_handler.IsRequestTypeAllowed( + application->device(), application->policy_app_id(), request_type)) { LOG4CXX_ERROR(logger_, "RequestType " << stringified_request_type << " is DISALLOWED by policies"); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_request_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_request_notification_test.cc index 69ed8fb311..ffa7203f1f 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_request_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_request_notification_test.cc @@ -62,6 +62,7 @@ using testing::SaveArg; namespace { const uint32_t kConnectionKey = 1u; const std::string kPolicyAppId = "fake-app-id"; +const connection_handler::DeviceHandle kDeviceId = 1u; } // namespace class OnSystemRequestNotificationTest @@ -73,6 +74,7 @@ class OnSystemRequestNotificationTest ON_CALL(app_mngr_, application(kConnectionKey)) .WillByDefault(Return(mock_app_)); ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kPolicyAppId)); + ON_CALL(*mock_app_, device()).WillByDefault(Return(kDeviceId)); } protected: @@ -90,12 +92,14 @@ TEST_F(OnSystemRequestNotificationTest, Run_ProprietaryType_SUCCESS) { std::shared_ptr<OnSystemRequestNotification> command = CreateCommand<OnSystemRequestNotification>(msg); + PreConditions(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillRepeatedly(Return(mock_app_)); EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId)); EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kPolicyAppId, request_type)) + IsRequestTypeAllowed(kDeviceId, kPolicyAppId, request_type)) .WillRepeatedly(Return(true)); #ifdef PROPRIETARY_MODE @@ -130,10 +134,13 @@ TEST_F(OnSystemRequestNotificationTest, Run_HTTPType_SUCCESS) { std::shared_ptr<OnSystemRequestNotification> command = CreateCommand<OnSystemRequestNotification>(msg); + PreConditions(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app_)); EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId)); - EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _)) + EXPECT_CALL(mock_policy_handler_, + IsRequestTypeAllowed(kDeviceId, kPolicyAppId, request_type)) .WillOnce(Return(true)); EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) @@ -167,7 +174,7 @@ TEST_F(OnSystemRequestNotificationTest, Run_InvalidApp_NoNotification) { EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(MockAppPtr())); EXPECT_CALL(*mock_app_, policy_app_id()).Times(0); - EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _)).Times(0); + EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _, _)).Times(0); EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); @@ -187,10 +194,13 @@ TEST_F(OnSystemRequestNotificationTest, Run_RequestNotAllowed_NoNotification) { std::shared_ptr<OnSystemRequestNotification> command = CreateCommand<OnSystemRequestNotification>(msg); + PreConditions(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app_)); EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId)); - EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _)) + EXPECT_CALL(mock_policy_handler_, + IsRequestTypeAllowed(kDeviceId, kPolicyAppId, request_type)) .WillOnce(Return(false)); EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); @@ -214,7 +224,7 @@ TEST_F( PreConditions(); EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kPolicyAppId, request_type)) + IsRequestTypeAllowed(kDeviceId, kPolicyAppId, request_type)) .WillOnce(Return(true)); EXPECT_CALL(mock_policy_handler_, IsRequestSubTypeAllowed(kPolicyAppId, request_subtype)) @@ -241,7 +251,7 @@ TEST_F(OnSystemRequestNotificationTest, PreConditions(); EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kPolicyAppId, request_type)) + IsRequestTypeAllowed(kDeviceId, kPolicyAppId, request_type)) .WillOnce(Return(true)); EXPECT_CALL(mock_policy_handler_, IsRequestSubTypeAllowed(kPolicyAppId, request_subtype)) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc index 0e8374b75a..ac45e90d8e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc @@ -67,6 +67,8 @@ using ::testing::_; using ::testing::DoAll; using ::testing::Return; using ::testing::ReturnRef; +using ::testing::SaveArg; +using ::testing::SetArgPointee; namespace am = ::application_manager; @@ -75,12 +77,15 @@ using sdl_rpc_plugin::commands::RegisterAppInterfaceRequest; namespace { const uint32_t kConnectionKey = 1u; +const uint32_t kConnectionKey2 = 2u; const hmi_apis::Common_Language::eType kHmiLanguage = hmi_apis::Common_Language::EN_US; const mobile_apis::Language::eType kMobileLanguage = mobile_apis::Language::EN_US; -const std::string kMacAddress = "test_mac_address"; -const std::string kAppId = "test_app_id"; +const std::string kMacAddress1 = "test_mac_address1"; +const std::string kMacAddress2 = "test_mac_address2"; +const std::string kAppId1 = "test_app1_id"; +const std::string kAppId2 = "test_app2_id"; const std::string kFullAppId = "test_app_id_long"; const std::string kDummyString = "test_string"; const std::vector<uint32_t> kDummyDiagModes; @@ -94,6 +99,7 @@ class RegisterAppInterfaceRequestTest : msg_(CreateMessage()) , command_(CreateCommand<RegisterAppInterfaceRequest>(msg_)) , app_name_("test_app_name_") + , app2_name_("test_app2_name_") , lock_ptr_(std::make_shared<sync_primitives::Lock>()) , mock_application_helper_( application_manager_test::MockApplicationHelper:: @@ -112,7 +118,7 @@ class RegisterAppInterfaceRequestTest void InitBasicMessage() { (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg_)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*msg_)[am::strings::msg_params][am::strings::app_id] = kAppId1; (*msg_)[am::strings::msg_params][am::strings::full_app_id] = kFullAppId; (*msg_)[am::strings::msg_params][am::strings::app_name] = app_name_; (*msg_)[am::strings::msg_params][am::strings::language_desired] = @@ -130,11 +136,11 @@ class RegisterAppInterfaceRequestTest MockAppPtr CreateBasicMockedApp() { MockAppPtr mock_app = CreateMockApp(); ON_CALL(*mock_app, name()).WillByDefault(ReturnRef(app_name_)); - ON_CALL(*mock_app, mac_address()).WillByDefault(ReturnRef(kMacAddress)); + ON_CALL(*mock_app, mac_address()).WillByDefault(ReturnRef(kMacAddress1)); ON_CALL(*mock_app, app_icon_path()).WillByDefault(ReturnRef(kDummyString)); ON_CALL(*mock_app, language()).WillByDefault(ReturnRef(kMobileLanguage)); ON_CALL(*mock_app, ui_language()).WillByDefault(ReturnRef(kMobileLanguage)); - ON_CALL(*mock_app, policy_app_id()).WillByDefault(Return(kAppId)); + ON_CALL(*mock_app, policy_app_id()).WillByDefault(Return(kAppId1)); ON_CALL(*mock_app, msg_version()) .WillByDefault(ReturnRef(mock_semantic_version)); return mock_app; @@ -154,7 +160,7 @@ class RegisterAppInterfaceRequestTest void InitGetters() { ON_CALL(app_mngr_, GetCorrectMobileIDFromMessage(msg_)) - .WillByDefault(Return(kAppId)); + .WillByDefault(Return(kAppId1)); ON_CALL(app_mngr_, IsHMICooperating()).WillByDefault(Return(true)); ON_CALL(app_mngr_, resume_controller()) .WillByDefault(ReturnRef(mock_resume_crt_)); @@ -168,7 +174,7 @@ class RegisterAppInterfaceRequestTest .WillByDefault(ReturnRef(kDummyString)); ON_CALL(app_mngr_settings_, supported_diag_modes()) .WillByDefault(ReturnRef(kDummyDiagModes)); - ON_CALL(mock_policy_handler_, GetAppRequestTypes(_)) + ON_CALL(mock_policy_handler_, GetAppRequestTypes(_, _)) .WillByDefault(Return(std::vector<std::string>())); ON_CALL(mock_policy_handler_, GetAppRequestTypeState(_)) .WillByDefault(Return(policy::RequestType::State::EMPTY)); @@ -180,7 +186,7 @@ class RegisterAppInterfaceRequestTest .WillByDefault(Return(policy::DeviceConsent::kDeviceAllowed)); ON_CALL(app_mngr_, GetDeviceTransportType(_)) .WillByDefault(Return(hmi_apis::Common_TransportType::WIFI)); - ON_CALL(app_mngr_, IsAppInReconnectMode(_)).WillByDefault(Return(false)); + ON_CALL(app_mngr_, IsAppInReconnectMode(_, _)).WillByDefault(Return(false)); ON_CALL(app_mngr_, application_by_policy_id(_)) .WillByDefault(Return(ApplicationSharedPtr())); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) @@ -201,7 +207,7 @@ class RegisterAppInterfaceRequestTest void SetCommonExpectionsOnSwitchedApplication( MockAppPtr mock_app, mobile_apis::Result::eType response_result_code) { - EXPECT_CALL(mock_policy_handler_, AddApplication(_, _)).Times(0); + EXPECT_CALL(mock_policy_handler_, AddApplication(_, _, _)).Times(0); EXPECT_CALL( mock_rpc_service_, @@ -250,6 +256,7 @@ class RegisterAppInterfaceRequestTest std::shared_ptr<RegisterAppInterfaceRequest> command_; const utils::custom_string::CustomString app_name_; + const utils::custom_string::CustomString app2_name_; std::shared_ptr<sync_primitives::Lock> lock_ptr_; am::ApplicationSet app_set_; @@ -280,7 +287,7 @@ TEST_F(RegisterAppInterfaceRequestTest, Init_SUCCESS) { TEST_F(RegisterAppInterfaceRequestTest, Run_MinimalData_SUCCESS) { InitBasicMessage(); - (*msg_)[am::strings::msg_params][am::strings::hash_id] = kAppId; + (*msg_)[am::strings::msg_params][am::strings::hash_id] = kAppId1; EXPECT_CALL(app_mngr_, IsStopping()) .WillOnce(Return(false)) .WillOnce(Return(true)) @@ -289,20 +296,30 @@ TEST_F(RegisterAppInterfaceRequestTest, Run_MinimalData_SUCCESS) { EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); EXPECT_CALL(app_mngr_, IsApplicationForbidden(_, _)).WillOnce(Return(false)); + connection_handler::DeviceHandle handle = 1; + ON_CALL(mock_connection_handler_, + GetDataOnSessionKey(kConnectionKey, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(handle), Return(0))); + ON_CALL(mock_session_observer_, GetDataOnDeviceID(handle, _, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress1), Return(0))); + MockAppPtr mock_app = CreateBasicMockedApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(ApplicationSharedPtr())) - .WillRepeatedly(Return(mock_app)); + EXPECT_CALL(app_mngr_, application(kMacAddress1, kAppId1)) + .WillRepeatedly(Return(ApplicationSharedPtr())); ON_CALL(app_mngr_, applications()) .WillByDefault( Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + ON_CALL(mock_policy_handler_, PolicyEnabled()).WillByDefault(Return(true)); - ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId, _, _)) + ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId1, _, _)) .WillByDefault(Return(true)); policy::StatusNotifier notify_upd_manager = std::make_shared<utils::CallNothing>(); - ON_CALL(mock_policy_handler_, AddApplication(_, _)) + ON_CALL(mock_policy_handler_, AddApplication(kMacAddress1, kAppId1, _)) .WillByDefault(Return(notify_upd_manager)); EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).WillOnce(Return(mock_app)); @@ -323,6 +340,7 @@ TEST_F(RegisterAppInterfaceRequestTest, Run_MinimalData_SUCCESS) { ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) .Times(2); EXPECT_CALL(app_mngr_, SendDriverDistractionState(_)); + ASSERT_TRUE(command_->Init()); command_->Run(); } @@ -360,10 +378,19 @@ TEST_F(RegisterAppInterfaceRequestTest, EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); EXPECT_CALL(app_mngr_, IsApplicationForbidden(_, _)).WillOnce(Return(false)); + connection_handler::DeviceHandle handle = 1; + ON_CALL(mock_connection_handler_, + GetDataOnSessionKey(kConnectionKey, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(handle), Return(0))); + ON_CALL(mock_session_observer_, GetDataOnDeviceID(_, _, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress1), Return(0))); + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, application(kMacAddress1, kAppId1)) + .WillRepeatedly(Return(ApplicationSharedPtr())); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(ApplicationSharedPtr())) - .WillRepeatedly(Return(mock_app)); + .WillOnce(Return(mock_app)); MessageSharedPtr expected_message = CreateMessage(smart_objects::SmartType_Map); @@ -401,11 +428,11 @@ TEST_F(RegisterAppInterfaceRequestTest, .WillByDefault( Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); ON_CALL(mock_policy_handler_, PolicyEnabled()).WillByDefault(Return(true)); - ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId, _, _)) + ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId1, _, _)) .WillByDefault(Return(true)); policy::StatusNotifier notify_upd_manager = std::make_shared<utils::CallNothing>(); - ON_CALL(mock_policy_handler_, AddApplication(_, _)) + ON_CALL(mock_policy_handler_, AddApplication(kMacAddress1, kAppId1, _)) .WillByDefault(Return(notify_upd_manager)); EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).WillOnce(Return(mock_app)); @@ -444,7 +471,7 @@ TEST_F(RegisterAppInterfaceRequestTest, ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) .Times(2); EXPECT_CALL(app_mngr_, SendDriverDistractionState(_)); - + ASSERT_TRUE(command_->Init()); command_->Run(); } @@ -456,10 +483,23 @@ TEST_F(RegisterAppInterfaceRequestTest, (*msg_)[am::strings::msg_params][am::strings::hash_id] = request_hash_id; MockAppPtr mock_app = CreateBasicMockedApp(); - EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) + app_set_.insert(mock_app); + EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId1)) .WillRepeatedly(Return(mock_app)); - EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + connection_handler::DeviceHandle device_id = 1; + ON_CALL(mock_connection_handler_, + GetDataOnSessionKey(kConnectionKey, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(device_id), Return(0))); + + ON_CALL(mock_session_observer_, GetDataOnDeviceID(device_id, _, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress1), Return(0))); + + ON_CALL(app_mngr_, application(kMacAddress1, kAppId1)) + .WillByDefault(Return(mock_app)); + + ON_CALL(app_mngr_, IsAppInReconnectMode(device_id, kAppId1)) + .WillByDefault(Return(true)); EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); @@ -482,6 +522,7 @@ TEST_F(RegisterAppInterfaceRequestTest, SetCommonExpectionsOnSwitchedApplication(mock_app, mobile_apis::Result::SUCCESS); + ASSERT_TRUE(command_->Init()); command_->Run(); } @@ -492,11 +533,22 @@ TEST_F(RegisterAppInterfaceRequestTest, const std::string request_hash_id = "abc123"; (*msg_)[am::strings::msg_params][am::strings::hash_id] = request_hash_id; + connection_handler::DeviceHandle device_id = 1; + ON_CALL(mock_connection_handler_, + GetDataOnSessionKey(kConnectionKey, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(device_id), Return(0))); + + ON_CALL(mock_session_observer_, GetDataOnDeviceID(device_id, _, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress1), Return(0))); + MockAppPtr mock_app = CreateBasicMockedApp(); - EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) + EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId1)) .WillRepeatedly(Return(mock_app)); - EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, application(kMacAddress1, kAppId1)) + .WillOnce(Return(mock_app)); + ON_CALL(app_mngr_, IsAppInReconnectMode(device_id, kAppId1)) + .WillByDefault(Return(true)); EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); @@ -520,7 +572,7 @@ TEST_F(RegisterAppInterfaceRequestTest, SetCommonExpectionsOnSwitchedApplication(mock_app, mobile_apis::Result::RESUME_FAILED); - + ASSERT_TRUE(command_->Init()); command_->Run(); } @@ -528,11 +580,23 @@ TEST_F(RegisterAppInterfaceRequestTest, SwitchApplication_NoHash_ExpectCleanupResumeFailed) { InitBasicMessage(); + connection_handler::DeviceHandle device_id = 1; + ON_CALL(mock_connection_handler_, + GetDataOnSessionKey(kConnectionKey, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(device_id), Return(0))); + + ON_CALL(mock_session_observer_, GetDataOnDeviceID(device_id, _, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress1), Return(0))); + MockAppPtr mock_app = CreateBasicMockedApp(); - EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) + EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId1)) .WillRepeatedly(Return(mock_app)); - EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, application(kMacAddress1, kAppId1)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(app_mngr_, IsAppInReconnectMode(device_id, kAppId1)) + .WillOnce(Return(true)); EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); @@ -550,6 +614,133 @@ TEST_F(RegisterAppInterfaceRequestTest, SetCommonExpectionsOnSwitchedApplication(mock_app, mobile_apis::Result::RESUME_FAILED); + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F(RegisterAppInterfaceRequestTest, + RegisterApp_SameAppId_SameDeviceFailed) { + using namespace am; + + InitBasicMessage(); + + MockAppPtr mock_app1 = CreateBasicMockedApp(); + + app_set_.insert(mock_app1); + ON_CALL(app_mngr_, applications()) + .WillByDefault( + Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); + + MockAppPtr mock_app2 = CreateBasicMockedApp(); + + connection_handler::DeviceHandle device_id = 1; + ON_CALL(mock_connection_handler_, + GetDataOnSessionKey(kConnectionKey, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(device_id), Return(0))); + + ON_CALL(mock_session_observer_, GetDataOnDeviceID(device_id, _, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress1), Return(0))); + + EXPECT_CALL(app_mngr_, application(kMacAddress1, kAppId1)) + .WillOnce(Return(mock_app1)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).Times(0); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs( + mobile_apis::Result::APPLICATION_REGISTERED_ALREADY), + am::commands::Command::SOURCE_SDL)); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F(RegisterAppInterfaceRequestTest, + RegisterApp_SameAppId_DifferentDevicesSuccess) { + MockAppPtr mock_app1 = CreateBasicMockedApp(); + const connection_handler::DeviceHandle device_id1 = 1u; + ON_CALL(*mock_app1, device()).WillByDefault(Return(device_id1)); + app_set_.insert(mock_app1); + ON_CALL(app_mngr_, applications()) + .WillByDefault( + Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); + + InitBasicMessage(); + (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey2; + EXPECT_CALL(app_mngr_, IsStopping()) + .WillOnce(Return(false)) + .WillOnce(Return(true)) + .WillOnce(Return(false)); + ON_CALL(app_mngr_, IsHMICooperating()).WillByDefault(Return(false)); + EXPECT_CALL(app_mngr_, updateRequestTimeout(kConnectionKey2, _, _)); + EXPECT_CALL(app_mngr_, IsApplicationForbidden(kConnectionKey2, kAppId1)) + .WillOnce(Return(false)); + + connection_handler::DeviceHandle device_id2 = 2u; + ON_CALL(mock_connection_handler_, + GetDataOnSessionKey(kConnectionKey2, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(device_id2), Return(0))); + + ON_CALL(mock_session_observer_, GetDataOnDeviceID(device_id2, _, _, _, _)) + .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress2), Return(0))); + + MockAppPtr mock_app2 = CreateBasicMockedApp(); + + ON_CALL(*mock_app2, device()).WillByDefault(Return(device_id2)); + ON_CALL(*mock_app2, mac_address()).WillByDefault(ReturnRef(kMacAddress2)); + EXPECT_CALL(app_mngr_, application(kMacAddress2, kAppId1)) + .WillRepeatedly(Return(ApplicationSharedPtr())); + + EXPECT_CALL(app_mngr_, application(kConnectionKey2)) + .WillOnce(Return(mock_app2)); + + ON_CALL(mock_policy_handler_, PolicyEnabled()).WillByDefault(Return(true)); + ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId1, _, _)) + .WillByDefault(Return(true)); + policy::StatusNotifier notify_upd_manager = + std::make_shared<utils::CallNothing>(); + ON_CALL(mock_policy_handler_, AddApplication(kMacAddress2, kAppId1, _)) + .WillByDefault(Return(notify_upd_manager)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).WillOnce(Return(mock_app2)); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_OnAppRegistered), + _)) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::Buttons_OnButtonSubscription), + _)) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::VR_ChangeRegistration), _)) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::TTS_ChangeRegistration), _)) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::UI_ChangeRegistration), _)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) + .Times(2); + EXPECT_CALL(app_mngr_, SendDriverDistractionState(_)); + + ASSERT_TRUE(command_->Init()); command_->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc index 7351cd67d3..211888d6be 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc @@ -74,6 +74,7 @@ const std::string kAppStorageFolder = "fake-storage"; const std::string kSystemFilesPath = "/fake/system/files"; const std::string kFileName = "Filename"; const uint32_t kHmiAppId = 3u; +const connection_handler::DeviceHandle kDeviceId = 1u; } // namespace class SystemRequestTest @@ -99,13 +100,15 @@ class SystemRequestTest ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kAppPolicyId)); ON_CALL(*mock_app_, folder_name()).WillByDefault(Return(kAppFolderName)); ON_CALL(*mock_app_, hmi_app_id()).WillByDefault(Return(kHmiAppId)); + ON_CALL(*mock_app_, device()).WillByDefault(Return(kDeviceId)); ON_CALL(app_mngr_settings_, system_files_path()) .WillByDefault(ReturnRef(kSystemFilesPath)); ON_CALL(app_mngr_settings_, app_storage_folder()) .WillByDefault(ReturnRef(kAppStorageFolder)); - ON_CALL(mock_policy_handler_, IsRequestTypeAllowed(kAppPolicyId, _)) + ON_CALL(mock_policy_handler_, + IsRequestTypeAllowed(kDeviceId, kAppPolicyId, _)) .WillByDefault(Return(true)); } @@ -146,9 +149,10 @@ TEST_F(SystemRequestTest, PreConditions(); - EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kAppPolicyId, - mobile_apis::RequestType::OEM_SPECIFIC)) + EXPECT_CALL( + mock_policy_handler_, + IsRequestTypeAllowed( + kDeviceId, kAppPolicyId, mobile_apis::RequestType::OEM_SPECIFIC)) .WillOnce(Return(true)); EXPECT_CALL(mock_policy_handler_, @@ -191,9 +195,10 @@ TEST_F( PreConditions(); - EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kAppPolicyId, - mobile_apis::RequestType::OEM_SPECIFIC)) + EXPECT_CALL( + mock_policy_handler_, + IsRequestTypeAllowed( + kDeviceId, kAppPolicyId, mobile_apis::RequestType::OEM_SPECIFIC)) .WillOnce(Return(true)); EXPECT_CALL(mock_policy_handler_, @@ -216,9 +221,10 @@ TEST_F(SystemRequestTest, Run_RequestTypeDisallowed_SendDisallowedResponse) { PreConditions(); - EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kAppPolicyId, - mobile_apis::RequestType::OEM_SPECIFIC)) + EXPECT_CALL( + mock_policy_handler_, + IsRequestTypeAllowed( + kDeviceId, kAppPolicyId, mobile_apis::RequestType::OEM_SPECIFIC)) .WillOnce(Return(false)); ExpectManageMobileCommandWithResultCode(mobile_apis::Result::DISALLOWED); @@ -241,9 +247,9 @@ TEST_F(SystemRequestTest, Run_RequestType_IconURL_Success) { const std::vector<uint8_t> binary_data = {1u, 2u}; (*msg)[am::strings::params][am::strings::binary_data] = binary_data; - EXPECT_CALL( - mock_policy_handler_, - IsRequestTypeAllowed(kAppPolicyId, mobile_apis::RequestType::ICON_URL)) + EXPECT_CALL(mock_policy_handler_, + IsRequestTypeAllowed( + kDeviceId, kAppPolicyId, mobile_apis::RequestType::ICON_URL)) .WillOnce(Return(true)); EXPECT_CALL(app_mngr_settings_, app_icons_folder()) .WillOnce(ReturnRef(kAppStorageFolder)); diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 7e72dd4c64..04fcf2c53f 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -121,17 +121,26 @@ bool device_id_comparator(const std::string& device_id, } /** - * @brief policy_app_id_comparator is predicate to compare policy application - * ids - * @param policy_app_id Policy id of application - * @param app Application pointer - * @return True if policy id of application matches to policy id passed + * @brief PolicyAppIdComparator is struct predicate to compare policy + * application ids & device + * @param device_handle of application + * @param id of application + * @return True if policy id & device_handle of application matches to policy id + * & device_handle passed */ -bool policy_app_id_comparator(const std::string& policy_app_id, - ApplicationSharedPtr app) { - DCHECK_OR_RETURN(app, false); - return app->policy_app_id() == policy_app_id; -} +struct PolicyAppIdComparator { + PolicyAppIdComparator(const connection_handler::DeviceHandle& device_handle, + const std::string& policy_app_id) + : device_handle_(device_handle), policy_app_id_(policy_app_id) {} + bool operator()(const ApplicationSharedPtr app) const { + return app && app->device() == device_handle_ && + app->policy_app_id() == policy_app_id_; + } + + private: + const connection_handler::DeviceHandle& device_handle_; + const std::string& policy_app_id_; +}; uint32_t ApplicationManagerImpl::mobile_corelation_id_ = 0; uint32_t ApplicationManagerImpl::corelation_id_ = 0; @@ -1631,7 +1640,8 @@ mobile_apis::HMILevel::eType ApplicationManagerImpl::GetDefaultHmiLevel( if (GetPolicyHandler().PolicyEnabled()) { const std::string policy_app_id = application->policy_app_id(); std::string default_hmi_string = ""; - if (GetPolicyHandler().GetDefaultHmi(policy_app_id, &default_hmi_string)) { + if (GetPolicyHandler().GetDefaultHmi( + application->mac_address(), policy_app_id, &default_hmi_string)) { if ("BACKGROUND" == default_hmi_string) { default_hmi = HMILevel::HMI_BACKGROUND; } else if ("FULL" == default_hmi_string) { @@ -1943,7 +1953,7 @@ void ApplicationManagerImpl::OnServiceEndedCallback( return; } - if (IsAppInReconnectMode(app->policy_app_id())) { + if (IsAppInReconnectMode(app->device(), app->policy_app_id())) { LOG4CXX_DEBUG(logger_, "Application is in reconnection list and won't be closed."); return; @@ -2490,8 +2500,24 @@ void ApplicationManagerImpl::CreateApplications(SmartArray& obj_array, } const std::string policy_app_id(app_data[json::appId].asString()); - ApplicationSharedPtr registered_app = - application_by_policy_id(policy_app_id); + + connection_handler::DeviceHandle device_handle; + if (-1 == connection_handler().get_session_observer().GetDataOnSessionKey( + connection_key, nullptr, nullptr, &device_handle)) { + LOG4CXX_ERROR(logger_, + "Failed to create application: no connection info."); + continue; + } + + std::string device_id; + if (-1 == connection_handler().get_session_observer().GetDataOnDeviceID( + device_handle, nullptr, nullptr, &device_id)) { + LOG4CXX_ERROR(logger_, + "Failed to create application: no connection info."); + continue; + } + + ApplicationSharedPtr registered_app = application(device_id, policy_app_id); if (registered_app) { LOG4CXX_DEBUG(logger_, "Application with the same id: " @@ -2530,22 +2556,9 @@ void ApplicationManagerImpl::CreateApplications(SmartArray& obj_array, const std::string app_icon_dir(settings_.app_icons_folder()); const std::string full_icon_path(app_icon_dir + "/" + policy_app_id); - connection_handler::DeviceHandle device_id = 0; - - if (-1 == connection_handler().get_session_observer().GetDataOnSessionKey( - connection_key, NULL, NULL, &device_id)) { - LOG4CXX_ERROR(logger_, - "Failed to create application: no connection info."); - continue; - } - - std::string device_mac; - connection_handler().get_session_observer().GetDataOnDeviceID( - device_id, NULL, NULL, &device_mac, NULL); - const uint32_t hmi_app_id = - resume_controller().IsApplicationSaved(policy_app_id, device_mac) - ? resume_controller().GetHMIApplicationID(policy_app_id, device_mac) + resume_controller().IsApplicationSaved(policy_app_id, device_id) + ? resume_controller().GetHMIApplicationID(policy_app_id, device_id) : GenerateNewHMIAppID(); // AppId = 0 because this is query_app(provided by hmi for download, but not @@ -2553,8 +2566,8 @@ void ApplicationManagerImpl::CreateApplications(SmartArray& obj_array, ApplicationSharedPtr app( new ApplicationImpl(0, policy_app_id, - device_mac, device_id, + device_handle, appName, GetPolicyHandler().GetStatisticManager(), *this)); @@ -3514,14 +3527,14 @@ bool ApplicationManagerImpl::IsApplicationForbidden( } bool ApplicationManagerImpl::IsAppInReconnectMode( + const connection_handler::DeviceHandle& device_id, const std::string& policy_app_id) const { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(reregister_wait_list_lock_); return reregister_wait_list_.end() != std::find_if(reregister_wait_list_.begin(), reregister_wait_list_.end(), - std::bind1st(std::ptr_fun(&policy_app_id_comparator), - policy_app_id)); + PolicyAppIdComparator(device_id, policy_app_id)); } policy::DeviceConsent ApplicationManagerImpl::GetUserConsentForDevice( @@ -3846,10 +3859,10 @@ void ApplicationManagerImpl::EraseAppFromReconnectionList( const auto policy_app_id = app->policy_app_id(); sync_primitives::AutoLock lock(reregister_wait_list_lock_); - auto app_it = std::find_if( - reregister_wait_list_.begin(), - reregister_wait_list_.end(), - std::bind1st(std::ptr_fun(&policy_app_id_comparator), policy_app_id)); + auto app_it = + std::find_if(reregister_wait_list_.begin(), + reregister_wait_list_.end(), + PolicyAppIdComparator(app->device(), policy_app_id)); if (reregister_wait_list_.end() != app_it) { reregister_wait_list_.erase(app_it); } diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc index 28f8fd88bb..bae4802e56 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -1648,7 +1648,8 @@ bool MessageHelper::CreateHMIApplicationStruct( const policy::RequestType::State app_request_types_state = policy_handler.GetAppRequestTypeState(policy_app_id); if (policy::RequestType::State::AVAILABLE == app_request_types_state) { - const auto request_types = policy_handler.GetAppRequestTypes(policy_app_id); + const auto request_types = + policy_handler.GetAppRequestTypes(app->device(), policy_app_id); message[strings::request_type] = SmartObject(smart_objects::SmartType_Array); smart_objects::SmartObject& request_types_array = diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index cac09bd5f3..fdbd0ce391 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -470,21 +470,25 @@ void PolicyHandler::OnDeviceConsentChanged(const std::string& device_id, continue; } - policy_manager_->ReactOnUserDevConsentForApp(policy_app_id, is_allowed); + policy_manager_->ReactOnUserDevConsentForApp( + device_handle, policy_app_id, is_allowed); - policy_manager_->SendNotificationOnPermissionsUpdated(policy_app_id); + policy_manager_->SendNotificationOnPermissionsUpdated(device_id, + policy_app_id); } } } void PolicyHandler::SendOnAppPermissionsChanged( - const AppPermissions& permissions, const std::string& policy_app_id) const { + const AppPermissions& permissions, + const std::string& device_id, + const std::string& policy_app_id) const { LOG4CXX_AUTO_TRACE(logger_); LOG4CXX_DEBUG( logger_, "PolicyHandler::SendOnAppPermissionsChanged for " << policy_app_id); ApplicationSharedPtr app = - application_manager_.application_by_policy_id(policy_app_id); + application_manager_.application(device_id, policy_app_id); if (app.use_count() == 0) { LOG4CXX_WARN(logger_, "No app found for policy app id = " << policy_app_id); return; @@ -518,10 +522,11 @@ struct SmartObjectToInt { }; StatusNotifier PolicyHandler::AddApplication( + const std::string& device_id, const std::string& application_id, const rpc::policy_table_interface_base::AppHmiTypes& hmi_types) { POLICY_LIB_CHECK(std::make_shared<utils::CallNothing>()); - return policy_manager_->AddApplication(application_id, hmi_types); + return policy_manager_->AddApplication(device_id, application_id, hmi_types); } void PolicyHandler::AddDevice(const std::string& device_id, @@ -573,13 +578,9 @@ void PolicyHandler::OnAppPermissionConsentInternal( #endif } } else if (!app_to_device_link_.empty()) { - sync_primitives::AutoLock lock(app_to_device_link_lock_); - std::map<std::string, std::string>::const_iterator it = - app_to_device_link_.begin(); - for (; app_to_device_link_.end() != it; ++it) { - ApplicationSharedPtr app = - application_manager_.application_by_policy_id(it->second); - + const ApplicationSet& accessor = + application_manager_.applications().GetData(); + for (const auto& app : accessor) { // If list of apps sent to HMI for user consents is not the same as // current, // permissions should be set only for coincident to registered apps @@ -590,19 +591,26 @@ void PolicyHandler::OnAppPermissionConsentInternal( continue; } + if (!app->IsRegistered()) { + LOG4CXX_DEBUG(logger_, + "Application " << app->policy_app_id() + << " is not marked as registered."); + continue; + } + DeviceParams device_params = GetDeviceParams( app->device(), application_manager_.connection_handler().get_session_observer()); - if (device_params.device_mac_address != it->first) { + if (device_params.device_mac_address != app->mac_address()) { LOG4CXX_WARN(logger_, "Device_id of application is changed." "Permissions setting skipped."); continue; } - out_permissions.policy_app_id = it->second; - out_permissions.device_id = it->first; + out_permissions.policy_app_id = app->policy_app_id(); + out_permissions.device_id = app->mac_address(); #ifdef EXTERNAL_PROPRIETARY_MODE policy_manager_->SetUserConsentForApp(out_permissions, mode); #else @@ -852,10 +860,15 @@ void PolicyHandler::OnUpdateStatusChanged(const std::string& status) { } std::string PolicyHandler::OnCurrentDeviceIdUpdateRequired( + const transport_manager::DeviceHandle& device_handle, const std::string& policy_app_id) { LOG4CXX_AUTO_TRACE(logger_); - ApplicationSharedPtr app = - application_manager_.application_by_policy_id(policy_app_id); + DeviceParams device_params = GetDeviceParams( + device_handle, + application_manager_.connection_handler().get_session_observer()); + + ApplicationSharedPtr app = application_manager_.application( + device_params.device_mac_address, policy_app_id); if (app.use_count() == 0) { LOG4CXX_WARN(logger_, @@ -863,11 +876,8 @@ std::string PolicyHandler::OnCurrentDeviceIdUpdateRequired( << policy_app_id << "' " "not found within registered applications."); - return ""; + return std::string(); } - DeviceParams device_params = GetDeviceParams( - app->device(), - application_manager_.connection_handler().get_session_observer()); return device_params.device_mac_address; } @@ -925,14 +935,14 @@ void PolicyHandler::OnVehicleDataUpdated( } void PolicyHandler::OnPendingPermissionChange( - const std::string& policy_app_id) { + const std::string& device_id, const std::string& policy_app_id) { LOG4CXX_AUTO_TRACE(logger_); LOG4CXX_DEBUG( logger_, "PolicyHandler::OnPendingPermissionChange for " << policy_app_id); POLICY_LIB_CHECK_VOID(); ApplicationSharedPtr app = - application_manager_.application_by_policy_id(policy_app_id); + application_manager_.application(device_id, policy_app_id); if (app.use_count() == 0) { LOG4CXX_WARN(logger_, "No app found for " << policy_app_id << " policy app id."); @@ -940,7 +950,7 @@ void PolicyHandler::OnPendingPermissionChange( } AppPermissions permissions = - policy_manager_->GetAppPermissionsChanges(policy_app_id); + policy_manager_->GetAppPermissionsChanges(device_id, policy_app_id); const uint32_t app_id = app->app_id(); @@ -1099,7 +1109,8 @@ struct SDLAlowedNotification { if (app->device() == device_id_) { std::string hmi_level; mobile_apis::HMILevel::eType default_mobile_hmi; - policy_manager_->GetDefaultHmi(app->policy_app_id(), &hmi_level); + policy_manager_->GetDefaultHmi( + app->mac_address(), app->policy_app_id(), &hmi_level); if ("BACKGROUND" == hmi_level) { default_mobile_hmi = mobile_apis::HMILevel::HMI_BACKGROUND; } else if ("FULL" == hmi_level) { @@ -1256,7 +1267,8 @@ void PolicyHandler::OnActivateApp(uint32_t connection_key, permissions.isSDLAllowed = true; } } else { - permissions = policy_manager_->GetAppPermissionsChanges(policy_app_id); + permissions = policy_manager_->GetAppPermissionsChanges(app->mac_address(), + policy_app_id); #ifdef EXTERNAL_PROPRIETARY_MODE UsageStatistics& usage = app->usage_report(); @@ -1327,18 +1339,19 @@ void PolicyHandler::PTExchangeAtUserRequest(uint32_t correlation_id) { update_status, correlation_id, application_manager_); } -void PolicyHandler::OnPermissionsUpdated(const std::string& policy_app_id, +void PolicyHandler::OnPermissionsUpdated(const std::string& device_id, + const std::string& policy_app_id, const Permissions& permissions, const HMILevel& default_hmi) { LOG4CXX_AUTO_TRACE(logger_); - OnPermissionsUpdated(policy_app_id, permissions); + OnPermissionsUpdated(device_id, policy_app_id, permissions); ApplicationSharedPtr app = - application_manager_.application_by_policy_id(policy_app_id); + application_manager_.application(device_id, policy_app_id); if (app.use_count() == 0) { LOG4CXX_WARN( logger_, - "Connection_key not found for application_id:" << policy_app_id); + "Connection_key not found for application_id: " << policy_app_id); return; } @@ -1365,13 +1378,12 @@ void PolicyHandler::OnPermissionsUpdated(const std::string& policy_app_id, << policy_app_id << " to default hmi level " << default_hmi); - if (hmi_level == mobile_apis::HMILevel::HMI_FULL) { - application_manager_.state_controller().SetRegularState( - app, hmi_level, true); - } else { - application_manager_.state_controller().SetRegularState( - app, hmi_level, false); - } + const bool is_full_hmi_level = + mobile_apis::HMILevel::HMI_FULL == hmi_level; + + application_manager_.state_controller().SetRegularState( + app, hmi_level, is_full_hmi_level); + break; } default: @@ -1383,15 +1395,16 @@ void PolicyHandler::OnPermissionsUpdated(const std::string& policy_app_id, } } -void PolicyHandler::OnPermissionsUpdated(const std::string& policy_app_id, +void PolicyHandler::OnPermissionsUpdated(const std::string& device_id, + const std::string& policy_app_id, const Permissions& permissions) { LOG4CXX_AUTO_TRACE(logger_); ApplicationSharedPtr app = - application_manager_.application_by_policy_id(policy_app_id); + application_manager_.application(device_id, policy_app_id); if (app.use_count() == 0) { LOG4CXX_WARN( logger_, - "Connection_key not found for application_id:" << policy_app_id); + "Connection_key not found for application_id: " << policy_app_id); return; } @@ -1399,7 +1412,7 @@ void PolicyHandler::OnPermissionsUpdated(const std::string& policy_app_id, app->app_id(), permissions, application_manager_); LOG4CXX_DEBUG(logger_, - "Notification sent for application_id:" + "Notification sent for application_id: " << policy_app_id << " and connection_key " << app->app_id()); } @@ -1501,13 +1514,9 @@ void PolicyHandler::CheckPermissions( "Checking permissions for " << app->policy_app_id() << " in " << hmi_level << " on device " << device_id << " rpc " << rpc); -#ifdef EXTERNAL_PROPRIETARY_MODE - policy_manager_->CheckPermissions( - app->policy_app_id(), hmi_level, rpc, rpc_params, result); -#else // EXTERNAL_PROPRIETARY_MODE + policy_manager_->CheckPermissions( device_id, app->policy_app_id(), hmi_level, rpc, rpc_params, result); -#endif // EXTERNAL_PROPRIETARY_MODE } uint32_t PolicyHandler::GetNotificationsNumber( @@ -1522,10 +1531,11 @@ DeviceConsent PolicyHandler::GetUserConsentForDevice( return policy_manager_->GetUserConsentForDevice(device_id); } -bool PolicyHandler::GetDefaultHmi(const std::string& policy_app_id, +bool PolicyHandler::GetDefaultHmi(const std::string& device_id, + const std::string& policy_app_id, std::string* default_hmi) const { POLICY_LIB_CHECK(false); - return policy_manager_->GetDefaultHmi(policy_app_id, default_hmi); + return policy_manager_->GetDefaultHmi(device_id, policy_app_id, default_hmi); } bool PolicyHandler::GetInitialAppData(const std::string& application_id, @@ -1662,7 +1672,7 @@ custom_str::CustomString PolicyHandler::GetAppName( if (app.use_count() == 0) { LOG4CXX_WARN( logger_, - "Connection_key not found for application_id:" << policy_app_id); + "Connection_key not found for application_id: " << policy_app_id); return custom_str::CustomString(""); } return app->name(); @@ -2078,9 +2088,10 @@ void PolicyHandler::OnAppsSearchCompleted(const bool trigger_ptu) { policy_manager_->OnAppsSearchCompleted(trigger_ptu); } -void PolicyHandler::OnAppRegisteredOnMobile(const std::string& application_id) { +void PolicyHandler::OnAppRegisteredOnMobile(const std::string& device_id, + const std::string& application_id) { POLICY_LIB_CHECK_VOID(); - policy_manager_->OnAppRegisteredOnMobile(application_id); + policy_manager_->OnAppRegisteredOnMobile(device_id, application_id); } RequestType::State PolicyHandler::GetAppRequestTypeState( @@ -2096,12 +2107,13 @@ RequestSubType::State PolicyHandler::GetAppRequestSubTypeState( } bool PolicyHandler::IsRequestTypeAllowed( + const transport_manager::DeviceHandle& device_id, const std::string& policy_app_id, mobile_apis::RequestType::eType type) const { POLICY_LIB_CHECK(false); using namespace mobile_apis; - std::string stringified_type = RequestTypeToString(type); + const std::string stringified_type = RequestTypeToString(type); if (stringified_type.empty()) { LOG4CXX_ERROR(logger_, "Unknown request type."); return false; @@ -2124,7 +2136,11 @@ bool PolicyHandler::IsRequestTypeAllowed( case RequestType::State::AVAILABLE: { // If any of request types is available for current application - get them const auto request_types = +#ifdef EXTERNAL_PROPRIETARY_MODE + policy_manager_->GetAppRequestTypes(device_id, policy_app_id); +#else policy_manager_->GetAppRequestTypes(policy_app_id); +#endif return helpers::in_range(request_types, stringified_type); } default: @@ -2170,9 +2186,14 @@ bool PolicyHandler::IsRequestSubTypeAllowed( } const std::vector<std::string> PolicyHandler::GetAppRequestTypes( + const transport_manager::DeviceHandle& device_handle, const std::string& policy_app_id) const { POLICY_LIB_CHECK(std::vector<std::string>()); +#ifdef EXTERNAL_PROPRIETARY_MODE + return policy_manager_->GetAppRequestTypes(device_handle, policy_app_id); +#else return policy_manager_->GetAppRequestTypes(policy_app_id); +#endif } const std::vector<std::string> PolicyHandler::GetAppRequestSubTypes( @@ -2222,18 +2243,32 @@ bool PolicyHandler::IsUrlAppIdValid(const uint32_t app_idx, const EndpointUrls& urls) const { const EndpointData& app_data = urls[app_idx]; const std::vector<std::string> app_urls = app_data.url; - const ApplicationSharedPtr app = - application_manager_.application_by_policy_id(app_data.app_id); - const bool is_registered = (app && (app->IsRegistered())); - const bool is_default = (app_data.app_id == policy::kDefaultId); - const bool is_empty_urls = app_urls.empty(); + if (policy::kDefaultId == app_data.app_id) { + return true; + } - return ((is_registered && !is_empty_urls) || is_default); + if (app_urls.empty()) { + return false; + } + + const auto devices_ids = GetDevicesIds(app_data.app_id); + LOG4CXX_TRACE(logger_, + "Count devices: " << devices_ids.size() + << " for app_id: " << app_data.app_id); + for (const auto& device_id : devices_ids) { + ApplicationSharedPtr app = + application_manager_.application(device_id, app_data.app_id); + if (app && (app->IsRegistered())) { + return true; + } + } + + return false; } std::vector<std::string> PolicyHandler::GetDevicesIds( - const std::string& policy_app_id) { + const std::string& policy_app_id) const { return application_manager_.devices(policy_app_id); } @@ -2307,6 +2342,7 @@ bool PolicyHandler::GetModuleTypes(const std::string& policy_app_id, } void PolicyHandler::SetDefaultHmiTypes( + const transport_manager::DeviceHandle& device_handle, const std::string& application_id, const smart_objects::SmartObject* app_types) { LOG4CXX_AUTO_TRACE(logger_); @@ -2319,7 +2355,7 @@ void PolicyHandler::SetDefaultHmiTypes( std::back_inserter(hmi_types), SmartObjectToInt()); } - policy_manager_->SetDefaultHmiTypes(application_id, hmi_types); + policy_manager_->SetDefaultHmiTypes(device_handle, application_id, hmi_types); } bool PolicyHandler::CheckHMIType(const std::string& application_id, diff --git a/src/components/application_manager/src/rpc_service_impl.cc b/src/components/application_manager/src/rpc_service_impl.cc index b5cae1c126..fef5ef0163 100644 --- a/src/components/application_manager/src/rpc_service_impl.cc +++ b/src/components/application_manager/src/rpc_service_impl.cc @@ -82,7 +82,8 @@ bool RPCServiceImpl::ManageMobileCommand( (*message)[strings::params][strings::connection_key].asUInt()); auto app_ptr = app_manager_.application(connection_key); - if (app_ptr && app_manager_.IsAppInReconnectMode(app_ptr->policy_app_id())) { + if (app_ptr && app_manager_.IsAppInReconnectMode(app_ptr->device(), + app_ptr->policy_app_id())) { commands_holder_.Suspend( app_ptr, CommandHolder::CommandType::kMobileCommand, message); return true; @@ -296,7 +297,8 @@ bool RPCServiceImpl::ManageHMICommand(const commands::MessageSharedPtr message, (*message)[strings::msg_params][strings::app_id].asUInt(); auto app = app_manager_.application(static_cast<uint32_t>(connection_key)); - if (app && app_manager_.IsAppInReconnectMode(app->policy_app_id())) { + if (app && app_manager_.IsAppInReconnectMode(app->device(), + app->policy_app_id())) { commands_holder_.Suspend( app, CommandHolder::CommandType::kHmiCommand, message); return true; diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc index 804959e1db..1f4b94a991 100644 --- a/src/components/application_manager/test/application_manager_impl_test.cc +++ b/src/components/application_manager/test/application_manager_impl_test.cc @@ -145,8 +145,10 @@ class ApplicationManagerImplTest : public ::testing::Test { protected: void SetUp() OVERRIDE { CreateAppManager(); - ON_CALL(mock_session_observer_, GetDataOnSessionKey(_, _, _, _)) - .WillByDefault(DoAll(SetArgPointee<3u>(kDeviceId), Return(0))); + ON_CALL(*mock_app_ptr_, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*mock_app_ptr_, device()).WillByDefault(Return(kDeviceId)); + ON_CALL(mock_connection_handler_, GetDataOnSessionKey(_, _, _, &kDeviceId)) + .WillByDefault(DoAll(SetArgPointee<3u>(app_id_), Return(0))); ON_CALL(mock_connection_handler_, get_session_observer()) .WillByDefault(ReturnRef(mock_session_observer_)); app_manager_impl_->SetMockRPCService(mock_rpc_service_); @@ -820,6 +822,9 @@ TEST_F(ApplicationManagerImplTest, std::shared_ptr<MockApplication> switching_app_ptr = std::make_shared<MockApplication>(); + ON_CALL(*switching_app_ptr, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*switching_app_ptr, device()).WillByDefault(Return(kDeviceId)); + const std::string switching_device_id = "switching"; const std::string switching_device_id_hash = encryption::MakeHash(switching_device_id); @@ -837,7 +842,6 @@ TEST_F(ApplicationManagerImplTest, std::shared_ptr<MockApplication> nonswitching_app_ptr = std::make_shared<MockApplication>(); - const std::string nonswitching_device_id = "nonswitching"; const std::string nonswitching_device_id_hash = encryption::MakeHash(nonswitching_device_id); @@ -868,15 +872,18 @@ TEST_F(ApplicationManagerImplTest, .WillOnce(Return(smart_objects::SmartObjectSPtr())); app_manager_impl_->OnDeviceSwitchingStart(switching_device, non_switching_device); - EXPECT_TRUE(app_manager_impl_->IsAppInReconnectMode(policy_app_id_switch)); - EXPECT_FALSE( - app_manager_impl_->IsAppInReconnectMode(policy_app_id_nonswitch)); + EXPECT_TRUE( + app_manager_impl_->IsAppInReconnectMode(kDeviceId, policy_app_id_switch)); + EXPECT_FALSE(app_manager_impl_->IsAppInReconnectMode( + kDeviceId, policy_app_id_nonswitch)); } TEST_F(ApplicationManagerImplTest, OnDeviceSwitchingFinish_ExpectUnregisterAppsInWaitList) { std::shared_ptr<MockApplication> switching_app_ptr = std::make_shared<MockApplication>(); + ON_CALL(*switching_app_ptr, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*switching_app_ptr, device()).WillByDefault(Return(kDeviceId)); plugin_manager::MockRPCPluginManager* mock_rpc_plugin_manager = new plugin_manager::MockRPCPluginManager; @@ -913,6 +920,10 @@ TEST_F(ApplicationManagerImplTest, EXPECT_CALL(*nonswitching_app_ptr, policy_app_id()) .WillRepeatedly(Return(policy_app_id_nonswitch)); + ON_CALL(*nonswitching_app_ptr, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_4)); + const auto hmi_level_nonswitching_app = mobile_apis::HMILevel::HMI_LIMITED; EXPECT_CALL(*nonswitching_app_ptr, hmi_level()) .WillRepeatedly(Return(hmi_level_nonswitching_app)); @@ -933,7 +944,8 @@ TEST_F(ApplicationManagerImplTest, app_manager_impl_->OnDeviceSwitchingStart(switching_device, non_switching_device); - EXPECT_TRUE(app_manager_impl_->IsAppInReconnectMode(policy_app_id_switch)); + EXPECT_TRUE( + app_manager_impl_->IsAppInReconnectMode(kDeviceId, policy_app_id_switch)); app_manager_impl_->OnDeviceSwitchingFinish(switching_device_id); EXPECT_FALSE( diff --git a/src/components/application_manager/test/policy_handler_test.cc b/src/components/application_manager/test/policy_handler_test.cc index 458b065cdd..6bd2c7fda6 100644 --- a/src/components/application_manager/test/policy_handler_test.cc +++ b/src/components/application_manager/test/policy_handler_test.cc @@ -233,7 +233,7 @@ class PolicyHandlerTest : public ::testing::Test { void TestOnPermissionsUpdated(const std::string& default_hmi_level, const mobile_apis::HMILevel::eType hmi_level) { - EXPECT_CALL(app_manager_, application_by_policy_id(kPolicyAppId_)) + EXPECT_CALL(app_manager_, application(kDeviceId, kPolicyAppId_)) .WillRepeatedly(Return(mock_app_)); EXPECT_CALL(*mock_app_, app_id()).WillRepeatedly(Return(kAppId1_)); EXPECT_CALL(*mock_app_, hmi_level()) @@ -247,7 +247,7 @@ class PolicyHandlerTest : public ::testing::Test { Permissions permissions; policy_handler_.OnPermissionsUpdated( - kPolicyAppId_, permissions, default_hmi_level); + kDeviceId, kPolicyAppId_, permissions, default_hmi_level); } void CreateFunctionalGroupPermission( @@ -494,31 +494,31 @@ TEST_F(PolicyHandlerTest, UnloadPolicyLibrary_method_ExpectLibraryUnloaded) { TEST_F(PolicyHandlerTest, OnPermissionsUpdated_method_With2Parameters) { // Check expectations - EXPECT_CALL(app_manager_, application_by_policy_id(kPolicyAppId_)) + EXPECT_CALL(app_manager_, application(kDeviceId, kPolicyAppId_)) .WillOnce(Return(mock_app_)); EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId1_)); EXPECT_CALL(mock_message_helper_, SendOnPermissionsChangeNotification(kAppId1_, _, _)); // Act Permissions perms; - policy_handler_.OnPermissionsUpdated(kPolicyAppId_, perms); + policy_handler_.OnPermissionsUpdated(kDeviceId, kPolicyAppId_, perms); } TEST_F(PolicyHandlerTest, OnPermissionsUpdated_TwoParams_InvalidApp_UNSUCCESS) { std::shared_ptr<application_manager_test::MockApplication> invalid_app; - EXPECT_CALL(app_manager_, application_by_policy_id(kPolicyAppId_)) + EXPECT_CALL(app_manager_, application(kDeviceId, kPolicyAppId_)) .WillOnce(Return(invalid_app)); EXPECT_CALL(mock_message_helper_, SendOnPermissionsChangeNotification(_, _, _)) .Times(0); Permissions permissions; - policy_handler_.OnPermissionsUpdated(kPolicyAppId_, permissions); + policy_handler_.OnPermissionsUpdated(kDeviceId, kPolicyAppId_, permissions); } TEST_F(PolicyHandlerTest, OnPermissionsUpdated_InvalidApp_UNSUCCESS) { std::shared_ptr<application_manager_test::MockApplication> invalid_app; - EXPECT_CALL(app_manager_, application_by_policy_id(kPolicyAppId_)) + EXPECT_CALL(app_manager_, application(kDeviceId, kPolicyAppId_)) .WillOnce(Return(mock_app_)) .WillOnce(Return(invalid_app)); EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId1_)); @@ -526,7 +526,8 @@ TEST_F(PolicyHandlerTest, OnPermissionsUpdated_InvalidApp_UNSUCCESS) { SendOnPermissionsChangeNotification(kAppId1_, _, _)); Permissions permissions; - policy_handler_.OnPermissionsUpdated(kPolicyAppId_, permissions, "HMI_FULL"); + policy_handler_.OnPermissionsUpdated( + kDeviceId, kPolicyAppId_, permissions, "HMI_FULL"); } TEST_F(PolicyHandlerTest, OnPermissionsUpdated_HmiLevelInvalidEnum_UNSUCCESS) { @@ -544,7 +545,7 @@ TEST_F(PolicyHandlerTest, const std::string new_kHmiLevel_string = "HMI_FULL"; mobile_apis::HMILevel::eType new_hmi_level = mobile_apis::HMILevel::HMI_FULL; // Check expectations - EXPECT_CALL(app_manager_, application_by_policy_id(kPolicyAppId_)) + EXPECT_CALL(app_manager_, application(kDeviceId, kPolicyAppId_)) .Times(2) .WillRepeatedly(Return(mock_app_)); EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId1_)); @@ -562,7 +563,7 @@ TEST_F(PolicyHandlerTest, // Act Permissions perms; policy_handler_.OnPermissionsUpdated( - kPolicyAppId_, perms, new_kHmiLevel_string); + kDeviceId, kPolicyAppId_, perms, new_kHmiLevel_string); } TEST_F(PolicyHandlerTest, @@ -572,7 +573,7 @@ TEST_F(PolicyHandlerTest, mobile_apis::HMILevel::eType new_hmi_level = mobile_apis::HMILevel::HMI_LIMITED; // Check expectations - EXPECT_CALL(app_manager_, application_by_policy_id(kPolicyAppId_)) + EXPECT_CALL(app_manager_, application(kDeviceId, kPolicyAppId_)) .Times(2) .WillRepeatedly(Return(mock_app_)); EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId1_)); @@ -590,7 +591,7 @@ TEST_F(PolicyHandlerTest, // Act Permissions perms; policy_handler_.OnPermissionsUpdated( - kPolicyAppId_, perms, new_kHmiLevel_string); + kDeviceId, kPolicyAppId_, perms, new_kHmiLevel_string); } TEST_F(PolicyHandlerTest, @@ -599,7 +600,7 @@ TEST_F(PolicyHandlerTest, std::string new_kHmiLevel_string = "HMI_FULL"; mobile_apis::HMILevel::eType new_hmi_level = mobile_apis::HMILevel::HMI_FULL; // Check expectations - EXPECT_CALL(app_manager_, application_by_policy_id(kPolicyAppId_)) + EXPECT_CALL(app_manager_, application(kDeviceId, kPolicyAppId_)) .Times(2) .WillRepeatedly(Return(mock_app_)); EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId1_)); @@ -615,7 +616,7 @@ TEST_F(PolicyHandlerTest, // Act Permissions perms; policy_handler_.OnPermissionsUpdated( - kPolicyAppId_, perms, new_kHmiLevel_string); + kDeviceId, kPolicyAppId_, perms, new_kHmiLevel_string); } TEST_F(PolicyHandlerTest, GetPriority) { @@ -639,16 +640,9 @@ TEST_F(PolicyHandlerTest, CheckPermissions) { EXPECT_CALL(*mock_app_, hmi_level()).WillOnce(Return(hmi_level)); EXPECT_CALL(*mock_app_, device()).WillOnce(Return(device)); EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId_)); -#ifdef EXTERNAL_PROPRIETARY_MODE - EXPECT_CALL( - *mock_policy_manager_, - CheckPermissions(kPolicyAppId_, kHmiLevel_, kRpc_, kRpc_params, _)); - -#else // EXTERNAL_PROPRIETARY_MODE EXPECT_CALL(*mock_policy_manager_, CheckPermissions( kDeviceId, kPolicyAppId_, kHmiLevel_, kRpc_, kRpc_params, _)); -#endif // EXTERNAL_PROPRIETARY_MODE EXPECT_CALL(mock_message_helper_, StringifiedHMILevel(hmi_level)) .WillOnce(Return(kHmiLevel_)); EXPECT_CALL(mock_message_helper_, GetDeviceMacAddressForHandle(device, _)) @@ -681,9 +675,9 @@ TEST_F(PolicyHandlerTest, GetDefaultHmi) { EnablePolicyAndPolicyManagerMock(); // Check expectations EXPECT_CALL(*mock_policy_manager_, - GetDefaultHmi(kPolicyAppId_, &default_hmi_)); + GetDefaultHmi(kDeviceId_, kPolicyAppId_, &default_hmi_)); // Act - policy_handler_.GetDefaultHmi(kPolicyAppId_, &default_hmi_); + policy_handler_.GetDefaultHmi(kDeviceId_, kPolicyAppId_, &default_hmi_); } TEST_F(PolicyHandlerTest, GetInitialAppData) { @@ -882,12 +876,14 @@ void PolicyHandlerTest::TestActivateApp(const uint32_t connection_key, #endif // EXTERNAL_PROPRIETARY_MODE EXPECT_CALL(*application1, policy_app_id()).WillOnce(Return(kPolicyAppId_)); - EXPECT_CALL(*mock_policy_manager_, GetAppPermissionsChanges(_)) + EXPECT_CALL(*mock_policy_manager_, + GetAppPermissionsChanges(kMacAddr_, kPolicyAppId_)) .WillOnce(Return(permissions)); ON_CALL(*mock_policy_manager_, Increment(_, _)).WillByDefault(Return()); EXPECT_CALL(*mock_policy_manager_, RemovePendingPermissionChanges(_)); EXPECT_CALL(mock_message_helper_, SendSDLActivateAppResponse(_, _, _)); ON_CALL(*application1, app_id()).WillByDefault(Return(kAppId1_)); + ON_CALL(*application1, mac_address()).WillByDefault(ReturnRef(kMacAddr_)); // Act policy_handler_.OnActivateApp(connection_key, correlation_id); } @@ -936,12 +932,14 @@ TEST_F(PolicyHandlerTest, OnActivateApp_AppIsRevoked_AppNotActivated) { // Check expectations EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId_)); - EXPECT_CALL(*mock_policy_manager_, GetAppPermissionsChanges(_)) + EXPECT_CALL(*mock_policy_manager_, + GetAppPermissionsChanges(kDefaultId, kPolicyAppId_)) .WillOnce(Return(permissions)); ON_CALL(*mock_policy_manager_, Increment(_, _)).WillByDefault(Return()); EXPECT_CALL(*mock_policy_manager_, RemovePendingPermissionChanges(_)); EXPECT_CALL(mock_message_helper_, SendSDLActivateAppResponse(_, _, _)); ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId1_)); + ON_CALL(*mock_app_, mac_address()).WillByDefault(ReturnRef(kDefaultId)); // Act policy_handler_.OnActivateApp(kConnectionKey_, kCorrelationKey_); } @@ -963,8 +961,7 @@ void PolicyHandlerTest::OnPendingPermissionChangePrecondition( std::shared_ptr<application_manager_test::MockApplication> application = std::make_shared<application_manager_test::MockApplication>(); - EXPECT_CALL(app_manager_, application_by_policy_id(kPolicyAppId_)) - .WillOnce(Return(application)); + EXPECT_CALL(app_manager_, application(_, _)).WillOnce(Return(application)); EXPECT_CALL(*application, app_id()).WillRepeatedly(Return(kAppId1_)); EXPECT_CALL(*application, hmi_level()).WillRepeatedly(Return(hmi_level)); } @@ -980,13 +977,13 @@ TEST_F(PolicyHandlerTest, EXPECT_CALL(mock_message_helper_, SendOnAppPermissionsChangedNotification(kAppId1_, _, _)) .Times(0); - - EXPECT_CALL(*mock_policy_manager_, GetAppPermissionsChanges(_)) + EXPECT_CALL(*mock_policy_manager_, + GetAppPermissionsChanges(kDeviceId_, kPolicyAppId_)) .WillOnce(Return(permissions)); EXPECT_CALL(*mock_policy_manager_, RemovePendingPermissionChanges(kPolicyAppId_)); // Act - policy_handler_.OnPendingPermissionChange(kPolicyAppId_); + policy_handler_.OnPendingPermissionChange(kDeviceId_, kPolicyAppId_); } TEST_F(PolicyHandlerTest, OnPendingPermissionChange_AppInLimitedConsentNeeded) { @@ -998,12 +995,13 @@ TEST_F(PolicyHandlerTest, OnPendingPermissionChange_AppInLimitedConsentNeeded) { // Check expectations EXPECT_CALL(mock_message_helper_, SendOnAppPermissionsChangedNotification(kAppId1_, _, _)); - EXPECT_CALL(*mock_policy_manager_, GetAppPermissionsChanges(_)) + EXPECT_CALL(*mock_policy_manager_, + GetAppPermissionsChanges(kDeviceId_, kPolicyAppId_)) .WillOnce(Return(permissions)); EXPECT_CALL(*mock_policy_manager_, RemovePendingPermissionChanges(kPolicyAppId_)); // Act - policy_handler_.OnPendingPermissionChange(kPolicyAppId_); + policy_handler_.OnPendingPermissionChange(kDeviceId_, kPolicyAppId_); } TEST_F(PolicyHandlerTest, OnPendingPermissionChange_AppLimitedAndRevoked) { @@ -1025,12 +1023,13 @@ TEST_F(PolicyHandlerTest, OnPendingPermissionChange_AppLimitedAndRevoked) { mobile_apis::VideoStreamingState::NOT_STREAMABLE, true)); - EXPECT_CALL(*mock_policy_manager_, GetAppPermissionsChanges(_)) + EXPECT_CALL(*mock_policy_manager_, + GetAppPermissionsChanges(kDeviceId_, kPolicyAppId_)) .WillOnce(Return(permissions)); EXPECT_CALL(*mock_policy_manager_, RemovePendingPermissionChanges(kPolicyAppId_)); // Act - policy_handler_.OnPendingPermissionChange(kPolicyAppId_); + policy_handler_.OnPendingPermissionChange(kDeviceId_, kPolicyAppId_); } TEST_F(PolicyHandlerTest, OnPendingPermissionChange_AppInBackgroundAndRevoked) { @@ -1044,12 +1043,13 @@ TEST_F(PolicyHandlerTest, OnPendingPermissionChange_AppInBackgroundAndRevoked) { EXPECT_CALL(mock_message_helper_, SendOnAppPermissionsChangedNotification(kAppId1_, _, _)); - EXPECT_CALL(*mock_policy_manager_, GetAppPermissionsChanges(_)) + EXPECT_CALL(*mock_policy_manager_, + GetAppPermissionsChanges(kDeviceId_, kPolicyAppId_)) .WillOnce(Return(permissions)); EXPECT_CALL(*mock_policy_manager_, RemovePendingPermissionChanges(kPolicyAppId_)); // Act - policy_handler_.OnPendingPermissionChange(kPolicyAppId_); + policy_handler_.OnPendingPermissionChange(kDeviceId_, kPolicyAppId_); } TEST_F(PolicyHandlerTest, @@ -1066,7 +1066,8 @@ TEST_F(PolicyHandlerTest, EXPECT_CALL(mock_message_helper_, SendOnAppPermissionsChangedNotification(kAppId1_, _, _)); - EXPECT_CALL(*mock_policy_manager_, GetAppPermissionsChanges(_)) + EXPECT_CALL(*mock_policy_manager_, + GetAppPermissionsChanges(kDeviceId_, kPolicyAppId_)) .WillOnce(Return(permissions)); EXPECT_CALL(mock_message_helper_, @@ -1083,7 +1084,7 @@ TEST_F(PolicyHandlerTest, RemovePendingPermissionChanges(kPolicyAppId_)); // Act - policy_handler_.OnPendingPermissionChange(kPolicyAppId_); + policy_handler_.OnPendingPermissionChange(kDeviceId_, kPolicyAppId_); } TEST_F(PolicyHandlerTest, @@ -1096,13 +1097,14 @@ TEST_F(PolicyHandlerTest, EXPECT_CALL(mock_message_helper_, SendOnAppPermissionsChangedNotification(kAppId1_, _, _)); - EXPECT_CALL(*mock_policy_manager_, GetAppPermissionsChanges(_)) + EXPECT_CALL(*mock_policy_manager_, + GetAppPermissionsChanges(kDeviceId_, kPolicyAppId_)) .WillOnce(Return(permissions)); EXPECT_CALL(*mock_policy_manager_, RemovePendingPermissionChanges(kPolicyAppId_)); - policy_handler_.OnPendingPermissionChange(kPolicyAppId_); + policy_handler_.OnPendingPermissionChange(kDeviceId_, kPolicyAppId_); } TEST_F(PolicyHandlerTest, @@ -1121,7 +1123,8 @@ TEST_F(PolicyHandlerTest, SendOnAppPermissionsChangedNotification(kAppId1_, _, _)) .Times(0); - EXPECT_CALL(*mock_policy_manager_, GetAppPermissionsChanges(_)) + EXPECT_CALL(*mock_policy_manager_, + GetAppPermissionsChanges(kDeviceId_, kPolicyAppId_)) .WillOnce(Return(permissions)); EXPECT_CALL(mock_message_helper_, @@ -1138,7 +1141,7 @@ TEST_F(PolicyHandlerTest, RemovePendingPermissionChanges(kPolicyAppId_)); // Act - policy_handler_.OnPendingPermissionChange(kPolicyAppId_); + policy_handler_.OnPendingPermissionChange(kDeviceId_, kPolicyAppId_); } TEST_F(PolicyHandlerTest, PTExchangeAtUserRequest) { @@ -1234,7 +1237,7 @@ TEST_F(PolicyHandlerTest, OnCurrentDeviceIdUpdateRequired) { // Check expectations std::shared_ptr<application_manager_test::MockApplication> application = std::make_shared<application_manager_test::MockApplication>(); - EXPECT_CALL(app_manager_, application_by_policy_id(kPolicyAppId_)) + EXPECT_CALL(app_manager_, application(kDeviceId_, kPolicyAppId_)) .WillOnce(Return(application)); EXPECT_CALL(app_manager_, connection_handler()) .WillOnce(ReturnRef(conn_handler)); @@ -1251,10 +1254,11 @@ TEST_F(PolicyHandlerTest, OnCurrentDeviceIdUpdateRequired) { _, _, _, - _)); + _)) + .WillOnce(DoAll(SetArgPointee<3>(kDeviceId_), Return(0))); // Act - policy_handler_.OnCurrentDeviceIdUpdateRequired(kPolicyAppId_); + policy_handler_.OnCurrentDeviceIdUpdateRequired(handle, kPolicyAppId_); } TEST_F(PolicyHandlerTest, OnSystemInfoChanged) { @@ -1303,11 +1307,17 @@ TEST_F(PolicyHandlerTest, GetAppRequestTypes) { // Arrange EnablePolicy(); ChangePolicyManagerToMock(); - // Check expectations + const transport_manager::DeviceHandle handle = 0u; +// Check expectations +#ifdef EXTERNAL_PROPRIETARY_MODE + EXPECT_CALL(*mock_policy_manager_, GetAppRequestTypes(handle, kPolicyAppId_)) + .WillOnce(Return(std::vector<std::string>())); +#else EXPECT_CALL(*mock_policy_manager_, GetAppRequestTypes(kPolicyAppId_)) .WillOnce(Return(std::vector<std::string>())); +#endif // Act - policy_handler_.GetAppRequestTypes(kPolicyAppId_); + policy_handler_.GetAppRequestTypes(handle, kPolicyAppId_); } TEST_F(PolicyHandlerTest, OnVIIsReady) { @@ -1376,13 +1386,14 @@ TEST_F(PolicyHandlerTest, SendOnAppPermissionsChanged) { std::shared_ptr<application_manager_test::MockApplication> application = std::make_shared<application_manager_test::MockApplication>(); // Check expectations - EXPECT_CALL(app_manager_, application_by_policy_id(kPolicyAppId_)) + EXPECT_CALL(app_manager_, application(kDeviceId_, kPolicyAppId_)) .WillOnce(Return(application)); EXPECT_CALL(mock_message_helper_, SendOnAppPermissionsChangedNotification(_, _, _)); AppPermissions permissions(kPolicyAppId_); // Act - policy_handler_.SendOnAppPermissionsChanged(permissions, kPolicyAppId_); + policy_handler_.SendOnAppPermissionsChanged( + permissions, kDeviceId_, kPolicyAppId_); } TEST_F(PolicyHandlerTest, OnPTExchangeNeeded) { @@ -1400,11 +1411,12 @@ TEST_F(PolicyHandlerTest, AddApplication) { // Check expectations EXPECT_CALL( *mock_policy_manager_, - AddApplication(kPolicyAppId_, HmiTypes(policy_table::AHT_DEFAULT))) + AddApplication( + kMacAddr_, kPolicyAppId_, HmiTypes(policy_table::AHT_DEFAULT))) .WillOnce(Return(std::make_shared<utils::CallNothing>())); // Act - policy_handler_.AddApplication(kPolicyAppId_, - HmiTypes(policy_table::AHT_DEFAULT)); + policy_handler_.AddApplication( + kMacAddr_, kPolicyAppId_, HmiTypes(policy_table::AHT_DEFAULT)); } TEST_F(PolicyHandlerTest, HeartBeatTimeout) { @@ -1439,9 +1451,10 @@ TEST_F(PolicyHandlerTest, OnAppRegisteredOnMobile) { EnablePolicyAndPolicyManagerMock(); // Check expectations - EXPECT_CALL(*mock_policy_manager_, OnAppRegisteredOnMobile(kPolicyAppId_)); + EXPECT_CALL(*mock_policy_manager_, + OnAppRegisteredOnMobile(kDeviceId, kPolicyAppId_)); // Act - policy_handler_.OnAppRegisteredOnMobile(kPolicyAppId_); + policy_handler_.OnAppRegisteredOnMobile(kDeviceId, kPolicyAppId_); } TEST_F(PolicyHandlerTest, IsRequestTypeAllowed) { @@ -1452,13 +1465,20 @@ TEST_F(PolicyHandlerTest, IsRequestTypeAllowed) { mobile_apis::RequestType::eType type = mobile_apis::RequestType::eType::EMERGENCY; + const transport_manager::DeviceHandle handle = 0u; + EXPECT_CALL(*mock_policy_manager_, GetAppRequestTypesState(kPolicyAppId_)) .WillOnce(Return(policy::RequestType::State::AVAILABLE)); - +#ifdef EXTERNAL_PROPRIETARY_MODE + EXPECT_CALL(*mock_policy_manager_, GetAppRequestTypes(handle, kPolicyAppId_)) + .WillOnce(Return(std::vector<std::string>({"HTTP"}))); +#else EXPECT_CALL(*mock_policy_manager_, GetAppRequestTypes(kPolicyAppId_)) .WillOnce(Return(std::vector<std::string>({"HTTP"}))); +#endif // Act - EXPECT_FALSE(policy_handler_.IsRequestTypeAllowed(kPolicyAppId_, type)); + EXPECT_FALSE( + policy_handler_.IsRequestTypeAllowed(handle, kPolicyAppId_, type)); } TEST_F(PolicyHandlerTest, IsRequestSubTypeAllowed) { @@ -1848,8 +1868,9 @@ TEST_F(PolicyHandlerTest, OnDeviceConsentChanged_ConsentAllowed) { connection_handler::DeviceHandle test_device_id = 100u; EXPECT_CALL(app_manager_, connection_handler()) .WillOnce(ReturnRef(conn_handler)); + EXPECT_CALL(app_manager_, applications()).WillRepeatedly(Return(app_set)); - EXPECT_CALL(conn_handler, GetDeviceID(kPolicyAppId_, _)) + EXPECT_CALL(conn_handler, GetDeviceID(kDeviceId, _)) .WillOnce(DoAll(SetArgPointee<1>(test_device_id), Return(true))); test_app.insert(mock_app_); @@ -1859,12 +1880,13 @@ TEST_F(PolicyHandlerTest, OnDeviceConsentChanged_ConsentAllowed) { EXPECT_CALL(*mock_policy_manager_, IsPredataPolicy(kPolicyAppId_)) .WillOnce(Return(true)); + EXPECT_CALL( + *mock_policy_manager_, + ReactOnUserDevConsentForApp(test_device_id, kPolicyAppId_, is_allowed)); EXPECT_CALL(*mock_policy_manager_, - ReactOnUserDevConsentForApp(kPolicyAppId_, is_allowed)); - EXPECT_CALL(*mock_policy_manager_, - SendNotificationOnPermissionsUpdated(kPolicyAppId_)); + SendNotificationOnPermissionsUpdated(kDeviceId, kPolicyAppId_)); - policy_handler_.OnDeviceConsentChanged(kPolicyAppId_, is_allowed); + policy_handler_.OnDeviceConsentChanged(kDeviceId, is_allowed); } TEST_F(PolicyHandlerTest, OnDeviceConsentChanged_ConsentNotAllowed) { @@ -1872,27 +1894,29 @@ TEST_F(PolicyHandlerTest, OnDeviceConsentChanged_ConsentNotAllowed) { // Arrange EnablePolicyAndPolicyManagerMock(); - connection_handler::DeviceHandle test_device_id = 100u; + connection_handler::DeviceHandle handle = 100u; EXPECT_CALL(app_manager_, connection_handler()) .WillOnce(ReturnRef(conn_handler)); // Check expectations - EXPECT_CALL(conn_handler, GetDeviceID(kPolicyAppId_, _)) - .WillOnce(DoAll(SetArgPointee<1>(test_device_id), Return(true))); + EXPECT_CALL(conn_handler, GetDeviceID(kMacAddr_, _)) + .WillOnce(DoAll(SetArgPointee<1>(handle), Return(true))); test_app.insert(mock_app_); - EXPECT_CALL(*mock_app_, device()).WillOnce(Return(test_device_id)); + EXPECT_CALL(*mock_app_, device()).WillOnce(Return(handle)); EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId_)); EXPECT_CALL(*mock_policy_manager_, IsPredataPolicy(kPolicyAppId_)) .WillOnce(Return(true)); - EXPECT_CALL(*mock_policy_manager_, ReactOnUserDevConsentForApp(_, _)) + EXPECT_CALL(*mock_policy_manager_, + ReactOnUserDevConsentForApp(handle, kPolicyAppId_, is_allowed)) .Times(0); - EXPECT_CALL(*mock_policy_manager_, SendNotificationOnPermissionsUpdated(_)) + EXPECT_CALL(*mock_policy_manager_, + SendNotificationOnPermissionsUpdated(kMacAddr_, kPolicyAppId_)) .Times(0); - policy_handler_.OnDeviceConsentChanged(kPolicyAppId_, is_allowed); + policy_handler_.OnDeviceConsentChanged(kMacAddr_, is_allowed); } TEST_F(PolicyHandlerTest, OnDeviceConsentChanged_PredatePolicyNotAllowed) { @@ -1903,8 +1927,9 @@ TEST_F(PolicyHandlerTest, OnDeviceConsentChanged_PredatePolicyNotAllowed) { connection_handler::DeviceHandle test_device_id = 100u; EXPECT_CALL(app_manager_, connection_handler()) .WillOnce(ReturnRef(conn_handler)); + EXPECT_CALL(app_manager_, applications()).WillRepeatedly(Return(app_set)); - EXPECT_CALL(conn_handler, GetDeviceID(kPolicyAppId_, _)) + EXPECT_CALL(conn_handler, GetDeviceID(kMacAddr_, _)) .WillOnce(DoAll(SetArgPointee<1>(test_device_id), Return(true))); test_app.insert(mock_app_); @@ -1916,12 +1941,13 @@ TEST_F(PolicyHandlerTest, OnDeviceConsentChanged_PredatePolicyNotAllowed) { EXPECT_CALL(*mock_policy_manager_, IsPredataPolicy(kPolicyAppId_)) .WillOnce(Return(false)); + EXPECT_CALL( + *mock_policy_manager_, + ReactOnUserDevConsentForApp(test_device_id, kPolicyAppId_, is_allowed)); EXPECT_CALL(*mock_policy_manager_, - ReactOnUserDevConsentForApp(kPolicyAppId_, is_allowed)); - EXPECT_CALL(*mock_policy_manager_, - SendNotificationOnPermissionsUpdated(kPolicyAppId_)); + SendNotificationOnPermissionsUpdated(kMacAddr_, kPolicyAppId_)); - policy_handler_.OnDeviceConsentChanged(kPolicyAppId_, is_allowed); + policy_handler_.OnDeviceConsentChanged(kMacAddr_, is_allowed); } #ifdef ENABLE_SECURITY #ifdef EXTERNAL_PROPRIETARY_MODE |