diff options
8 files changed, 1332 insertions, 1413 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d7dde3076..a4358b5b7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ option(ENABLE_GCOV "gcov code coverage feature" OFF) option(ENABLE_SANITIZE "Sanitize tool" OFF) option(ENABLE_SECURITY "Security Ford protocol protection" ON) option(ENABLE_HMI_PTU_DECRYPTION "Policy table update parsed by hmi" ON) -option(ENABLE_EXTENDED_POLICY "Turns extended flow which requires embedded system interaction" OFF) +option(ENABLE_EXTENDED_POLICY "Turns extended flow which requires embedded system interaction" ON) set(OS_TYPE_OPTION "$ENV{OS_TYPE}") set(DEBUG_OPTION "$ENV{DEBUG}") 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 22be96b16e..2ec5309717 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 @@ -113,7 +113,7 @@ class PolicyHandler : public PolicyHandlerInterface, void GetServiceUrls(const std::string& service_type, EndpointUrls& end_points) OVERRIDE; void ResetRetrySequence() OVERRIDE; - int NextRetryTimeout() OVERRIDE; + uint32_t NextRetryTimeout() OVERRIDE; int TimeoutExchange() OVERRIDE; void OnExceededTimeout() OVERRIDE; void OnSystemReady() OVERRIDE; @@ -356,15 +356,6 @@ class PolicyHandler : public PolicyHandlerInterface, void OnAppsSearchCompleted() OVERRIDE; /** - * @brief OnAppRegisteredOnMobile alows to handle event when application were - * succesfully registered on mobile device. - * It will send OnAppPermissionSend notification and will try to start PTU. - * - * @param application_id registered application. - */ - void OnAppRegisteredOnMobile(const std::string& application_id); - - /** * @brief Checks if certain request type is allowed for application * @param policy_app_id Unique applicaion id * @param type Request type diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 9969311bdc..4a3b7099bf 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -341,13 +341,6 @@ void ApplicationManagerImpl::OnApplicationRegistered(ApplicationSharedPtr app) { event.raise(event_dispatcher()); } -void ApplicationManagerImpl::OnApplicationRegistered(ApplicationSharedPtr app) { - DCHECK_OR_RETURN_VOID(app); - sync_primitives::AutoLock lock(applications_list_lock_); - const mobile_apis::HMILevel::eType default_level = GetDefaultHmiLevel(app); - state_ctrl_.OnApplicationRegistered(app, default_level); -} - bool ApplicationManagerImpl::IsAppTypeExistsInFullOrLimited( ApplicationConstSharedPtr app) const { bool voice_state = app->is_voice_communication_supported(); @@ -1086,7 +1079,7 @@ bool ApplicationManagerImpl::StartNaviService( if (navi_service_status_.end() == it) { std::pair<NaviServiceStatusMap::iterator, bool> res = navi_service_status_.insert( - std::pair<uint32_t, std::pair<bool, bool>>( + std::pair<uint32_t, std::pair<bool, bool> >( app_id, std::make_pair(false, false))); if (!res.second) { LOG4CXX_WARN(logger_, "Navi service refused"); @@ -1226,22 +1219,15 @@ void ApplicationManagerImpl::OnServiceEndedCallback( break; } } - default: { - reason = Result::INVALID_ENUM; - is_resuming = true; - is_unexpected_disconnect = true; - break; - } + UnregisterApplication( + session_key, reason, is_resuming, is_unexpected_disconnect); + return; } - UnregisterApplication( - session_key, reason, is_resuming, is_unexpected_disconnect); - return; -} -if (Compare<ServiceType, EQ, ONE>( - type, ServiceType::kMobileNav, ServiceType::kAudio)) { - StopNaviService(session_key, type); -} + if (Compare<ServiceType, EQ, ONE>( + type, ServiceType::kMobileNav, ServiceType::kAudio)) { + StopNaviService(session_key, type); + } } #ifdef ENABLE_SECURITY @@ -1813,144 +1799,138 @@ bool ApplicationManagerImpl::ConvertMessageToSO( *(message.binary_data()); } break; - } break; - } - case ProtocolVersion::kHMI: { + } + case ProtocolVersion::kHMI: { #ifdef ENABLE_LOG - int32_t result = + int32_t result = #endif - formatters::FormatterJsonRpc::FromString<hmi_apis::FunctionID::eType, - hmi_apis::messageType::eType>( - message.json_message(), output); - LOG4CXX_DEBUG(logger_, - "Convertion result: " - << result << " function id " - << output[jhs::S_PARAMS][jhs::S_FUNCTION_ID].asInt()); - if (!hmi_so_factory().attachSchema(output, false)) { - LOG4CXX_WARN(logger_, "Failed to attach schema to object."); - return false; - } - - if (application_manager::MessageType::kRequest == - output[strings::params][strings::message_type].asInt()) { - LOG4CXX_ERROR(logger_, "Ignore wrong HMI request"); - return false; - } - - output.erase(strings::msg_params); - output[strings::params][hmi_response::code] = - hmi_apis::Common_Result::INVALID_DATA; - output[strings::msg_params][strings::info] = - std::string("Received invalid data on HMI response"); - } break; -} -break; -} -case ProtocolVersion::kV1: { - static NsSmartDeviceLinkRPC::V1::v4_protocol_v1_2_no_extra v1_shema; - - if (message.function_id() == 0 || message.type() == kUnknownType) { - LOG4CXX_ERROR(logger_, "Message received: UNSUPPORTED_VERSION"); - - int32_t conversation_result = - formatters::CFormatterJsonSDLRPCv1::fromString< - NsSmartDeviceLinkRPC::V1::FunctionID::eType, - NsSmartDeviceLinkRPC::V1::messageType::eType>( - message.json_message(), output); - - if (formatters::CFormatterJsonSDLRPCv1::kSuccess == conversation_result) { - smart_objects::SmartObject params = - smart_objects::SmartObject(smart_objects::SmartType::SmartType_Map); + formatters::FormatterJsonRpc::FromString< + hmi_apis::FunctionID::eType, + hmi_apis::messageType::eType>(message.json_message(), output); + LOG4CXX_DEBUG(logger_, + "Convertion result: " + << result << " function id " + << output[jhs::S_PARAMS][jhs::S_FUNCTION_ID].asInt()); + if (!hmi_so_factory().attachSchema(output, false)) { + LOG4CXX_WARN(logger_, "Failed to attach schema to object."); + return false; + } + if (output.validate() != smart_objects::Errors::OK) { + LOG4CXX_ERROR(logger_, "Incorrect parameter from HMI"); - output[strings::params][strings::message_type] = - NsSmartDeviceLinkRPC::V1::messageType::response; - output[strings::params][strings::connection_key] = - message.connection_key(); + if (application_manager::MessageType::kNotification == + output[strings::params][strings::message_type].asInt()) { + LOG4CXX_ERROR(logger_, "Ignore wrong HMI notification"); + return false; + } - output[strings::msg_params] = - smart_objects::SmartObject(smart_objects::SmartType::SmartType_Map); - output[strings::msg_params][strings::success] = false; - output[strings::msg_params][strings::result_code] = - NsSmartDeviceLinkRPC::V1::Result::UNSUPPORTED_VERSION; + if (application_manager::MessageType::kRequest == + output[strings::params][strings::message_type].asInt()) { + LOG4CXX_ERROR(logger_, "Ignore wrong HMI request"); + return false; + } - smart_objects::SmartObjectSPtr msg_to_send = - new smart_objects::SmartObject(output); - v1_shema.attachSchema(*msg_to_send, false); - SendMessageToMobile(msg_to_send); - return false; + output.erase(strings::msg_params); + output[strings::params][hmi_response::code] = + hmi_apis::Common_Result::INVALID_DATA; + output[strings::msg_params][strings::info] = + std::string("Received invalid data on HMI response"); + } + break; } - } - break; -} -default: - // TODO(PV): - // removed NOTREACHED() because some app can still have vesion 1. - LOG4CXX_WARN(logger_, - "Application used unsupported protocol :" - << message.protocol_version() << "."); - return false; + case ProtocolVersion::kV1: { + static NsSmartDeviceLinkRPC::V1::v4_protocol_v1_2_no_extra v1_shema; + + if (message.function_id() == 0 || message.type() == kUnknownType) { + LOG4CXX_ERROR(logger_, "Message received: UNSUPPORTED_VERSION"); + + int32_t conversation_result = + formatters::CFormatterJsonSDLRPCv1::fromString< + NsSmartDeviceLinkRPC::V1::FunctionID::eType, + NsSmartDeviceLinkRPC::V1::messageType::eType>( + message.json_message(), output); + + if (formatters::CFormatterJsonSDLRPCv1::kSuccess == + conversation_result) { + smart_objects::SmartObject params = smart_objects::SmartObject( + smart_objects::SmartType::SmartType_Map); + + output[strings::params][strings::message_type] = + NsSmartDeviceLinkRPC::V1::messageType::response; + output[strings::params][strings::connection_key] = + message.connection_key(); + + output[strings::msg_params] = smart_objects::SmartObject( + smart_objects::SmartType::SmartType_Map); + output[strings::msg_params][strings::success] = false; + output[strings::msg_params][strings::result_code] = + NsSmartDeviceLinkRPC::V1::Result::UNSUPPORTED_VERSION; + + smart_objects::SmartObjectSPtr msg_to_send = + new smart_objects::SmartObject(output); + v1_shema.attachSchema(*msg_to_send, false); + SendMessageToMobile(msg_to_send); + return false; + } + } + break; + } + default: + // TODO(PV): + // removed NOTREACHED() because some app can still have vesion 1. + LOG4CXX_WARN(logger_, + "Application used unsupported protocol :" + << message.protocol_version() << "."); + return false; } LOG4CXX_DEBUG(logger_, "Successfully parsed message into smart object"); return true; - } +} - bool ApplicationManagerImpl::ConvertSOtoMessage( - const smart_objects::SmartObject& message, Message& output) { - LOG4CXX_AUTO_TRACE(logger_); +bool ApplicationManagerImpl::ConvertSOtoMessage( + const smart_objects::SmartObject& message, Message& output) { + LOG4CXX_AUTO_TRACE(logger_); - if (smart_objects::SmartType_Null == message.getType() || - smart_objects::SmartType_Invalid == message.getType()) { - LOG4CXX_WARN(logger_, "Invalid smart object received."); - return false; - } + if (smart_objects::SmartType_Null == message.getType() || + smart_objects::SmartType_Invalid == message.getType()) { + LOG4CXX_WARN(logger_, "Invalid smart object received."); + return false; + } - LOG4CXX_DEBUG( - logger_, - "Message with protocol: " << message.getElement(jhs::S_PARAMS) - .getElement(jhs::S_PROTOCOL_TYPE) - .asInt()); - - std::string output_string; - const int64_t protocol_type = message.getElement(jhs::S_PARAMS) - .getElement(jhs::S_PROTOCOL_TYPE) - .asInt(); - const int64_t protocol_version = message.getElement(jhs::S_PARAMS) - .getElement(jhs::S_PROTOCOL_VERSION) - .asInt(); - switch (protocol_type) { - case 0: { - if (protocol_version == 1) { - if (!formatters::CFormatterJsonSDLRPCv1::toString(message, - output_string)) { - LOG4CXX_WARN(logger_, "Failed to serialize smart object"); - return false; - } - output.set_protocol_version(application_manager::kV1); - } else { - if (!formatters::CFormatterJsonSDLRPCv2::toString(message, - output_string)) { - LOG4CXX_WARN(logger_, "Failed to serialize smart object"); - return false; - } - output.set_protocol_version( - static_cast<ProtocolVersion>(protocol_version)); + LOG4CXX_DEBUG( + logger_, + "Message with protocol: " << message.getElement(jhs::S_PARAMS) + .getElement(jhs::S_PROTOCOL_TYPE) + .asInt()); + + std::string output_string; + const int64_t protocol_type = message.getElement(jhs::S_PARAMS) + .getElement(jhs::S_PROTOCOL_TYPE) + .asInt(); + const int64_t protocol_version = message.getElement(jhs::S_PARAMS) + .getElement(jhs::S_PROTOCOL_VERSION) + .asInt(); + switch (protocol_type) { + case 0: { + if (protocol_version == 1) { + if (!formatters::CFormatterJsonSDLRPCv1::toString(message, + output_string)) { + LOG4CXX_WARN(logger_, "Failed to serialize smart object"); + return false; } output.set_protocol_version(application_manager::kV1); - } - else { - if (!formatters::CFormatterJsonSDLRPCv2::toString(message, - output_string)) { - LOG4CXX_WARN(logger_, "Failed to serialize smart object"); - return false; - } - output.set_protocol_version(static_cast<ProtocolVersion>( - message.getElement(jhs::S_PARAMS) - .getElement(jhs::S_PROTOCOL_VERSION) - .asUInt())); + } else { + if (!formatters::CFormatterJsonSDLRPCv2::toString(message, + output_string)) { + LOG4CXX_WARN(logger_, "Failed to serialize smart object"); + return false; } + output.set_protocol_version( + static_cast<ProtocolVersion>(protocol_version)); + } - break; + break; } case 1: { if (!formatters::FormatterJsonRpc::ToString(message, output_string)) { @@ -1971,9 +1951,8 @@ default: .getElement(strings::connection_key) .asInt()); - output.set_function_id(message.getElement(jhs::S_PARAMS) - .getElement(jhs::S_FUNCTION_ID) - .asInt()); + output.set_function_id( + message.getElement(jhs::S_PARAMS).getElement(jhs::S_FUNCTION_ID).asInt()); output.set_correlation_id(message.getElement(jhs::S_PARAMS) .getElement(jhs::S_CORRELATION_ID) @@ -2008,580 +1987,569 @@ default: LOG4CXX_DEBUG(logger_, "Successfully parsed smart object into message"); return true; - } - - utils::SharedPtr<Message> ApplicationManagerImpl::ConvertRawMsgToMessage( - const ::protocol_handler::RawMessagePtr message) { - LOG4CXX_AUTO_TRACE(logger_); - DCHECK(message); - utils::SharedPtr<Message> outgoing_message; +} - LOG4CXX_DEBUG(logger_, "Service type." << message->service_type()); - if (message->service_type() != protocol_handler::kRpc && - message->service_type() != protocol_handler::kBulk) { - // skip this message, not under handling of ApplicationManager - LOG4CXX_TRACE(logger_, "Skipping message; not the under AM handling."); - return outgoing_message; - } +utils::SharedPtr<Message> ApplicationManagerImpl::ConvertRawMsgToMessage( + const ::protocol_handler::RawMessagePtr message) { + LOG4CXX_AUTO_TRACE(logger_); + DCHECK(message); + utils::SharedPtr<Message> outgoing_message; + + LOG4CXX_DEBUG(logger_, "Service type." << message->service_type()); + if (message->service_type() != protocol_handler::kRpc && + message->service_type() != protocol_handler::kBulk) { + // skip this message, not under handling of ApplicationManager + LOG4CXX_TRACE(logger_, "Skipping message; not the under AM handling."); + return outgoing_message; + } - Message* convertion_result = - MobileMessageHandler::HandleIncomingMessageProtocol(message); + Message* convertion_result = + MobileMessageHandler::HandleIncomingMessageProtocol(message); - if (convertion_result) { - outgoing_message = convertion_result; - } else { - LOG4CXX_ERROR(logger_, "Received invalid message"); - } - return outgoing_message; + if (convertion_result) { + outgoing_message = convertion_result; + } else { + LOG4CXX_ERROR(logger_, "Received invalid message"); } + return outgoing_message; +} - void ApplicationManagerImpl::ProcessMessageFromMobile( - const utils::SharedPtr<Message> message) { - LOG4CXX_AUTO_TRACE(logger_); +void ApplicationManagerImpl::ProcessMessageFromMobile( + const utils::SharedPtr<Message> message) { + LOG4CXX_AUTO_TRACE(logger_); #ifdef TELEMETRY_MONITOR - AMTelemetryObserver::MessageMetricSharedPtr metric( - new AMTelemetryObserver::MessageMetric()); - metric->begin = date_time::DateTime::getCurrentTime(); + AMTelemetryObserver::MessageMetricSharedPtr metric( + new AMTelemetryObserver::MessageMetric()); + metric->begin = date_time::DateTime::getCurrentTime(); #endif // TELEMETRY_MONITOR - smart_objects::SmartObjectSPtr so_from_mobile = - utils::MakeShared<smart_objects::SmartObject>(); + smart_objects::SmartObjectSPtr so_from_mobile = + utils::MakeShared<smart_objects::SmartObject>(); - DCHECK_OR_RETURN_VOID(so_from_mobile); - if (!so_from_mobile) { - LOG4CXX_ERROR(logger_, "Null pointer"); - return; - } + DCHECK_OR_RETURN_VOID(so_from_mobile); + if (!so_from_mobile) { + LOG4CXX_ERROR(logger_, "Null pointer"); + return; + } - if (!ConvertMessageToSO(*message, *so_from_mobile)) { - LOG4CXX_ERROR(logger_, "Cannot create smart object from message"); - return; - } + if (!ConvertMessageToSO(*message, *so_from_mobile)) { + LOG4CXX_ERROR(logger_, "Cannot create smart object from message"); + return; + } #ifdef TELEMETRY_MONITOR - metric->message = so_from_mobile; + metric->message = so_from_mobile; #endif // TELEMETRY_MONITOR - if (!ManageMobileCommand(so_from_mobile, - commands::Command::ORIGIN_MOBILE)) { - LOG4CXX_ERROR(logger_, "Received command didn't run successfully"); - } + if (!ManageMobileCommand(so_from_mobile, commands::Command::ORIGIN_MOBILE)) { + LOG4CXX_ERROR(logger_, "Received command didn't run successfully"); + } #ifdef TELEMETRY_MONITOR - metric->end = date_time::DateTime::getCurrentTime(); - if (metric_observer_) { - metric_observer_->OnMessage(metric); - } -#endif // TELEMETRY_MONITOR + metric->end = date_time::DateTime::getCurrentTime(); + if (metric_observer_) { + metric_observer_->OnMessage(metric); } +#endif // TELEMETRY_MONITOR +} - void ApplicationManagerImpl::ProcessMessageFromHMI( - const utils::SharedPtr<Message> message) { - LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObjectSPtr smart_object(new smart_objects::SmartObject); +void ApplicationManagerImpl::ProcessMessageFromHMI( + const utils::SharedPtr<Message> message) { + LOG4CXX_AUTO_TRACE(logger_); + smart_objects::SmartObjectSPtr smart_object(new smart_objects::SmartObject); - if (!smart_object) { - LOG4CXX_ERROR(logger_, "Null pointer"); - return; - } + if (!smart_object) { + LOG4CXX_ERROR(logger_, "Null pointer"); + return; + } #ifdef HMI_DBUS_API - *smart_object = message->smart_object(); + *smart_object = message->smart_object(); #else - if (!ConvertMessageToSO(*message, *smart_object)) { - LOG4CXX_ERROR(logger_, "Cannot create smart object from message"); - return; - } + if (!ConvertMessageToSO(*message, *smart_object)) { + LOG4CXX_ERROR(logger_, "Cannot create smart object from message"); + return; + } #endif // HMI_DBUS_API - LOG4CXX_DEBUG(logger_, "Converted message, trying to create hmi command"); - if (!ManageHMICommand(smart_object)) { - LOG4CXX_ERROR(logger_, "Received command didn't run successfully"); - } + LOG4CXX_DEBUG(logger_, "Converted message, trying to create hmi command"); + if (!ManageHMICommand(smart_object)) { + LOG4CXX_ERROR(logger_, "Received command didn't run successfully"); } +} - hmi_apis::HMI_API& ApplicationManagerImpl::hmi_so_factory() { +hmi_apis::HMI_API& ApplicationManagerImpl::hmi_so_factory() { + if (!hmi_so_factory_) { + hmi_so_factory_ = new hmi_apis::HMI_API; if (!hmi_so_factory_) { - hmi_so_factory_ = new hmi_apis::HMI_API; - if (!hmi_so_factory_) { - LOG4CXX_ERROR(logger_, "Out of memory"); - NOTREACHED(); - } + LOG4CXX_ERROR(logger_, "Out of memory"); + NOTREACHED(); } - return *hmi_so_factory_; } + return *hmi_so_factory_; +} - mobile_apis::MOBILE_API& ApplicationManagerImpl::mobile_so_factory() { +mobile_apis::MOBILE_API& ApplicationManagerImpl::mobile_so_factory() { + if (!mobile_so_factory_) { + mobile_so_factory_ = new mobile_apis::MOBILE_API; if (!mobile_so_factory_) { - mobile_so_factory_ = new mobile_apis::MOBILE_API; - if (!mobile_so_factory_) { - LOG4CXX_ERROR(logger_, "Out of memory."); - NOTREACHED(); - } + LOG4CXX_ERROR(logger_, "Out of memory."); + NOTREACHED(); } - return *mobile_so_factory_; } + return *mobile_so_factory_; +} - HMICapabilities& ApplicationManagerImpl::hmi_capabilities() { - return hmi_capabilities_; - } +HMICapabilities& ApplicationManagerImpl::hmi_capabilities() { + return hmi_capabilities_; +} + +const HMICapabilities& ApplicationManagerImpl::hmi_capabilities() const { + return hmi_capabilities_; +} - const HMICapabilities& ApplicationManagerImpl::hmi_capabilities() const { - return hmi_capabilities_; +void ApplicationManagerImpl::PullLanguagesInfo(const SmartObject& app_data, + SmartObject& ttsName, + SmartObject& vrSynonym) { + LOG4CXX_AUTO_TRACE(logger_); + if (!app_data.keyExists(json::languages)) { + LOG4CXX_WARN(logger_, "\"languages\" not exists"); + return; } - void ApplicationManagerImpl::PullLanguagesInfo(const SmartObject& app_data, - SmartObject& ttsName, - SmartObject& vrSynonym) { - LOG4CXX_AUTO_TRACE(logger_); - if (!app_data.keyExists(json::languages)) { - LOG4CXX_WARN(logger_, "\"languages\" not exists"); - return; + const HMICapabilities& hmi_cap = hmi_capabilities(); + std::string cur_vr_lang( + MessageHelper::CommonLanguageToString(hmi_cap.active_vr_language())); + const SmartObject& languages = app_data[json::languages]; + + std::transform( + cur_vr_lang.begin(), cur_vr_lang.end(), cur_vr_lang.begin(), ::toupper); + + ssize_t default_idx = -1; + ssize_t specific_idx = -1; + + const size_t size = languages.length(); + for (size_t idx = 0; idx < size; ++idx) { + if (languages[idx].keyExists(cur_vr_lang)) { + LOG4CXX_DEBUG(logger_, "Found active HMI language " << cur_vr_lang); + specific_idx = idx; + } else if (languages[idx].keyExists(json::default_)) { + LOG4CXX_DEBUG(logger_, "Found default language"); + default_idx = idx; } + } - const HMICapabilities& hmi_cap = hmi_capabilities(); - std::string cur_vr_lang( - MessageHelper::CommonLanguageToString(hmi_cap.active_vr_language())); - const SmartObject& languages = app_data[json::languages]; + if ((-1 == specific_idx) && (-1 == default_idx)) { + LOG4CXX_DEBUG(logger_, "No suitable language found"); + return; + } - std::transform( - cur_vr_lang.begin(), cur_vr_lang.end(), cur_vr_lang.begin(), ::toupper); + if (app_data[json::languages][specific_idx][cur_vr_lang].keyExists( + json::ttsName)) { + LOG4CXX_DEBUG(logger_, "Get ttsName from " << cur_vr_lang << " language"); + ttsName = + app_data[json::languages][specific_idx][cur_vr_lang][json::ttsName]; + } else { + LOG4CXX_DEBUG(logger_, + "No data for ttsName for " << cur_vr_lang << " language"); + } - ssize_t default_idx = -1; - ssize_t specific_idx = -1; + if (app_data[json::languages][specific_idx][cur_vr_lang].keyExists( + json::vrSynonyms)) { + LOG4CXX_DEBUG(logger_, + "Get vrSynonyms from " << cur_vr_lang << " language"); + vrSynonym = + app_data[json::languages][specific_idx][cur_vr_lang][json::vrSynonyms]; + } else { + LOG4CXX_DEBUG(logger_, + "No data for vrSynonyms for " << cur_vr_lang << " language"); + } +} - const size_t size = languages.length(); - for (size_t idx = 0; idx < size; ++idx) { - if (languages[idx].keyExists(cur_vr_lang)) { - LOG4CXX_DEBUG(logger_, "Found active HMI language " << cur_vr_lang); - specific_idx = idx; - } else if (languages[idx].keyExists(json::default_)) { - LOG4CXX_DEBUG(logger_, "Found default language"); - default_idx = idx; - } - } +void ApplicationManagerImpl::CreateApplications(SmartArray& obj_array, + const uint32_t connection_key) { + LOG4CXX_AUTO_TRACE(logger_); + using namespace policy; - if ((-1 == specific_idx) && (-1 == default_idx)) { - LOG4CXX_DEBUG(logger_, "No suitable language found"); - return; - } + const std::size_t arr_size(obj_array.size()); + for (std::size_t idx = 0; idx < arr_size; ++idx) { + const SmartObject& app_data = obj_array[idx]; - if (app_data[json::languages][specific_idx][cur_vr_lang].keyExists( - json::ttsName)) { - LOG4CXX_DEBUG(logger_, "Get ttsName from " << cur_vr_lang << " language"); - ttsName = - app_data[json::languages][specific_idx][cur_vr_lang][json::ttsName]; - } else { - LOG4CXX_DEBUG(logger_, - "No data for ttsName for " << cur_vr_lang << " language"); + if (!(app_data.keyExists(json::name) && app_data.keyExists(json::appId))) { + LOG4CXX_DEBUG(logger_, "The entry in query apps json is not valid"); + continue; } - if (app_data[json::languages][specific_idx][cur_vr_lang].keyExists( - json::vrSynonyms)) { + const std::string policy_app_id(app_data[json::appId].asString()); + ApplicationSharedPtr registered_app = + application_by_policy_id(policy_app_id); + if (registered_app) { LOG4CXX_DEBUG(logger_, - "Get vrSynonyms from " << cur_vr_lang << " language"); - vrSynonym = app_data[json::languages][specific_idx][cur_vr_lang] - [json::vrSynonyms]; - } else { - LOG4CXX_DEBUG( - logger_, "No data for vrSynonyms for " << cur_vr_lang << " language"); + "Application with the same id: " + << policy_app_id << " is registered already."); + continue; } - } - void ApplicationManagerImpl::CreateApplications( - SmartArray& obj_array, const uint32_t connection_key) { - LOG4CXX_AUTO_TRACE(logger_); - using namespace policy; + std::string url_scheme; + std::string package_name; + std::string os_type; + SmartObject vrSynonym; + SmartObject ttsName; - const std::size_t arr_size(obj_array.size()); - for (std::size_t idx = 0; idx < arr_size; ++idx) { - const SmartObject& app_data = obj_array[idx]; + const custom_str::CustomString appName( + app_data[json::name].asCustomString()); - if (!(app_data.keyExists(json::name) && - app_data.keyExists(json::appId))) { - LOG4CXX_DEBUG(logger_, "The entry in query apps json is not valid"); - continue; - } + if (app_data.keyExists(json::ios)) { + os_type = json::ios; + url_scheme = app_data[os_type][json::urlScheme].asString(); + } else if (app_data.keyExists(json::android)) { + os_type = json::android; + package_name = app_data[os_type][json::packageName].asString(); + } - const std::string policy_app_id(app_data[json::appId].asString()); - ApplicationSharedPtr registered_app = - application_by_policy_id(policy_app_id); - if (registered_app) { - LOG4CXX_DEBUG(logger_, - "Application with the same id: " - << policy_app_id << " is registered already."); - continue; - } + PullLanguagesInfo(app_data[os_type], ttsName, vrSynonym); - std::string url_scheme; - std::string package_name; - std::string os_type; - SmartObject vrSynonym; - SmartObject ttsName; - - const custom_str::CustomString appName( - app_data[json::name].asCustomString()); - - if (app_data.keyExists(json::ios)) { - os_type = json::ios; - url_scheme = app_data[os_type][json::urlScheme].asString(); - } else if (app_data.keyExists(json::android)) { - os_type = json::android; - package_name = app_data[os_type][json::packageName].asString(); - } + if (ttsName.empty()) { + ttsName = SmartObject(SmartType_Array); + ttsName[0] = appName; + } + if (vrSynonym.empty()) { + vrSynonym = SmartObject(SmartType_Array); + vrSynonym[0] = appName; + } - PullLanguagesInfo(app_data[os_type], ttsName, vrSynonym); + const std::string app_icon_dir(settings_.app_icons_folder()); + const std::string full_icon_path(app_icon_dir + "/" + policy_app_id); - if (ttsName.empty()) { - ttsName = SmartObject(SmartType_Array); - ttsName[0] = appName; - } - if (vrSynonym.empty()) { - vrSynonym = SmartObject(SmartType_Array); - vrSynonym[0] = appName; - } + uint32_t device_id = 0; - const std::string app_icon_dir(settings_.app_icons_folder()); - const std::string full_icon_path(app_icon_dir + "/" + policy_app_id); + if (-1 == + connection_handler().GetDataOnSessionKey( + connection_key, NULL, NULL, &device_id)) { + LOG4CXX_ERROR(logger_, + "Failed to create application: no connection info."); + continue; + } - uint32_t device_id = 0; + std::string device_mac; + connection_handler().get_session_observer().GetDataOnDeviceID( + device_id, NULL, NULL, &device_mac, NULL); + + const uint32_t hmi_app_id = + resume_ctrl_.IsApplicationSaved(policy_app_id, device_mac) + ? resume_ctrl_.GetHMIApplicationID(policy_app_id, device_mac) + : GenerateNewHMIAppID(); + + // AppId = 0 because this is query_app(provided by hmi for download, but not + // yet registered) + ApplicationSharedPtr app( + new ApplicationImpl(0, + policy_app_id, + device_mac, + appName, + GetPolicyHandler().GetStatisticManager(), + *this)); + DCHECK_OR_RETURN_VOID(app); + app->SetShemaUrl(url_scheme); + app->SetPackageName(package_name); + app->set_app_icon_path(full_icon_path); + app->set_hmi_application_id(hmi_app_id); + app->set_device(device_id); - if (-1 == - connection_handler().GetDataOnSessionKey( - connection_key, NULL, NULL, &device_id)) { - LOG4CXX_ERROR(logger_, - "Failed to create application: no connection info."); - continue; - } + app->set_vr_synonyms(vrSynonym); + app->set_tts_name(ttsName); - std::string device_mac; - connection_handler().get_session_observer().GetDataOnDeviceID( - device_id, NULL, NULL, &device_mac, NULL); - - const uint32_t hmi_app_id = - resume_ctrl_.IsApplicationSaved(policy_app_id, device_mac) - ? resume_ctrl_.GetHMIApplicationID(policy_app_id, device_mac) - : GenerateNewHMIAppID(); - - // AppId = 0 because this is query_app(provided by hmi for download, but - // not - // yet registered) - ApplicationSharedPtr app( - new ApplicationImpl(0, - policy_app_id, - device_mac, - appName, - GetPolicyHandler().GetStatisticManager(), - *this)); - DCHECK_OR_RETURN_VOID(app); - app->SetShemaUrl(url_scheme); - app->SetPackageName(package_name); - app->set_app_icon_path(full_icon_path); - app->set_hmi_application_id(hmi_app_id); - app->set_device(device_id); - - app->set_vr_synonyms(vrSynonym); - app->set_tts_name(ttsName); - - sync_primitives::AutoLock lock(apps_to_register_list_lock_); - LOG4CXX_DEBUG( - logger_, - "apps_to_register_ size before: " << apps_to_register_.size()); - apps_to_register_.insert(app); - LOG4CXX_DEBUG( - logger_, - "apps_to_register_ size after: " << apps_to_register_.size()); - } + sync_primitives::AutoLock lock(apps_to_register_list_lock_); + LOG4CXX_DEBUG( + logger_, "apps_to_register_ size before: " << apps_to_register_.size()); + apps_to_register_.insert(app); + LOG4CXX_DEBUG(logger_, + "apps_to_register_ size after: " << apps_to_register_.size()); } +} - void ApplicationManagerImpl::ProcessQueryApp( - const smart_objects::SmartObject& sm_object, - const uint32_t connection_key) { - LOG4CXX_AUTO_TRACE(logger_); - using namespace policy; +void ApplicationManagerImpl::ProcessQueryApp( + const smart_objects::SmartObject& sm_object, + const uint32_t connection_key) { + LOG4CXX_AUTO_TRACE(logger_); + using namespace policy; - if (!sm_object.keyExists(json::response)) { - LOG4CXX_DEBUG(logger_, "The response key is not exists."); - return; - } + if (!sm_object.keyExists(json::response)) { + LOG4CXX_DEBUG(logger_, "The response key is not exists."); + return; + } - SmartArray* obj_array = sm_object[json::response].asArray(); - if (NULL != obj_array) { - CreateApplications(*obj_array, connection_key); - SendUpdateAppList(); + SmartArray* obj_array = sm_object[json::response].asArray(); + if (NULL != obj_array) { + CreateApplications(*obj_array, connection_key); + SendUpdateAppList(); - AppsWaitRegistrationSet::const_iterator it = apps_to_register_.begin(); - for (; it != apps_to_register_.end(); ++it) { - const std::string full_icon_path((*it)->app_icon_path()); - if (file_system::FileExists(full_icon_path)) { - MessageHelper::SendSetAppIcon( - (*it)->hmi_app_id(), full_icon_path, *this); - } + AppsWaitRegistrationSet::const_iterator it = apps_to_register_.begin(); + for (; it != apps_to_register_.end(); ++it) { + const std::string full_icon_path((*it)->app_icon_path()); + if (file_system::FileExists(full_icon_path)) { + MessageHelper::SendSetAppIcon( + (*it)->hmi_app_id(), full_icon_path, *this); } } } +} - bool ApplicationManagerImpl::is_attenuated_supported() const { - return hmi_capabilities().attenuated_supported() && - get_settings().is_mixing_audio_supported(); - } +bool ApplicationManagerImpl::is_attenuated_supported() const { + return hmi_capabilities().attenuated_supported() && + get_settings().is_mixing_audio_supported(); +} #ifdef TELEMETRY_MONITOR - void ApplicationManagerImpl::SetTelemetryObserver( - AMTelemetryObserver* observer) { - metric_observer_ = observer; - } +void ApplicationManagerImpl::SetTelemetryObserver( + AMTelemetryObserver* observer) { + metric_observer_ = observer; +} #endif // TELEMETRY_MONITOR - void ApplicationManagerImpl::addNotification(const CommandSharedPtr ptr) { - request_ctrl_.addNotification(ptr); - } - - void ApplicationManagerImpl::removeNotification( - const commands::Command* notification) { - request_ctrl_.removeNotification(notification); - } - - void ApplicationManagerImpl::updateRequestTimeout( - uint32_t connection_key, - uint32_t mobile_correlation_id, - uint32_t new_timeout_value) { - LOG4CXX_AUTO_TRACE(logger_); - request_ctrl_.updateRequestTimeout( - connection_key, mobile_correlation_id, new_timeout_value); - } +void ApplicationManagerImpl::addNotification(const CommandSharedPtr ptr) { + request_ctrl_.addNotification(ptr); +} - uint32_t ApplicationManagerImpl::application_id( - const int32_t correlation_id) { - // ykazakov: there is no erase for const iterator for QNX - std::map<const int32_t, const uint32_t>::iterator it = - appID_list_.find(correlation_id); - if (appID_list_.end() != it) { - const uint32_t app_id = it->second; - appID_list_.erase(it); - return app_id; - } else { - return 0; - } - } +void ApplicationManagerImpl::removeNotification( + const commands::Command* notification) { + request_ctrl_.removeNotification(notification); +} - void ApplicationManagerImpl::set_application_id(const int32_t correlation_id, - const uint32_t app_id) { - appID_list_.insert( - std::pair<const int32_t, const uint32_t>(correlation_id, app_id)); +void ApplicationManagerImpl::updateRequestTimeout( + uint32_t connection_key, + uint32_t mobile_correlation_id, + uint32_t new_timeout_value) { + LOG4CXX_AUTO_TRACE(logger_); + request_ctrl_.updateRequestTimeout( + connection_key, mobile_correlation_id, new_timeout_value); +} + +uint32_t ApplicationManagerImpl::application_id(const int32_t correlation_id) { + // ykazakov: there is no erase for const iterator for QNX + std::map<const int32_t, const uint32_t>::iterator it = + appID_list_.find(correlation_id); + if (appID_list_.end() != it) { + const uint32_t app_id = it->second; + appID_list_.erase(it); + return app_id; + } else { + return 0; } +} - void ApplicationManagerImpl::AddPolicyObserver( - policy::PolicyHandlerObserver* listener) { - GetPolicyHandler().add_listener(listener); - } +void ApplicationManagerImpl::set_application_id(const int32_t correlation_id, + const uint32_t app_id) { + appID_list_.insert( + std::pair<const int32_t, const uint32_t>(correlation_id, app_id)); +} - void ApplicationManagerImpl::RemovePolicyObserver( - policy::PolicyHandlerObserver* listener) { - GetPolicyHandler().remove_listener(listener); - } +void ApplicationManagerImpl::AddPolicyObserver( + policy::PolicyHandlerObserver* listener) { + GetPolicyHandler().add_listener(listener); +} - void ApplicationManagerImpl::SetUnregisterAllApplicationsReason( - mobile_api::AppInterfaceUnregisteredReason::eType reason) { - LOG4CXX_TRACE(logger_, "reason = " << reason); - unregister_reason_ = reason; - } +void ApplicationManagerImpl::RemovePolicyObserver( + policy::PolicyHandlerObserver* listener) { + GetPolicyHandler().remove_listener(listener); +} - void ApplicationManagerImpl::HeadUnitReset( - mobile_api::AppInterfaceUnregisteredReason::eType reason) { - stopping_application_mng_lock_.Acquire(); - is_stopping_ = true; - stopping_application_mng_lock_.Release(); - switch (reason) { - case mobile_api::AppInterfaceUnregisteredReason::MASTER_RESET: { - UnregisterAllApplications(); - GetPolicyHandler().ResetPolicyTable(); - GetPolicyHandler().UnloadPolicyLibrary(); +void ApplicationManagerImpl::SetUnregisterAllApplicationsReason( + mobile_api::AppInterfaceUnregisteredReason::eType reason) { + LOG4CXX_TRACE(logger_, "reason = " << reason); + unregister_reason_ = reason; +} - resume_controller().StopSavePersistentDataTimer(); - file_system::remove_directory_content( - get_settings().app_storage_folder()); - break; - } - case mobile_api::AppInterfaceUnregisteredReason::FACTORY_DEFAULTS: { - GetPolicyHandler().ClearUserConsent(); +void ApplicationManagerImpl::HeadUnitReset( + mobile_api::AppInterfaceUnregisteredReason::eType reason) { + stopping_application_mng_lock_.Acquire(); + is_stopping_ = true; + stopping_application_mng_lock_.Release(); + switch (reason) { + case mobile_api::AppInterfaceUnregisteredReason::MASTER_RESET: { + UnregisterAllApplications(); + GetPolicyHandler().ResetPolicyTable(); + GetPolicyHandler().UnloadPolicyLibrary(); + + resume_controller().StopSavePersistentDataTimer(); + file_system::remove_directory_content( + get_settings().app_storage_folder()); + break; + } + case mobile_api::AppInterfaceUnregisteredReason::FACTORY_DEFAULTS: { + GetPolicyHandler().ClearUserConsent(); - resume_controller().StopSavePersistentDataTimer(); - file_system::remove_directory_content( - get_settings().app_storage_folder()); - break; - } - default: { - LOG4CXX_ERROR(logger_, "Bad AppInterfaceUnregisteredReason"); - return; - } + resume_controller().StopSavePersistentDataTimer(); + file_system::remove_directory_content( + get_settings().app_storage_folder()); + break; + } + default: { + LOG4CXX_ERROR(logger_, "Bad AppInterfaceUnregisteredReason"); + return; } } +} - void ApplicationManagerImpl::SendOnSDLClose() { - LOG4CXX_AUTO_TRACE(logger_); +void ApplicationManagerImpl::SendOnSDLClose() { + LOG4CXX_AUTO_TRACE(logger_); - // must be sent to PASA HMI on shutdown synchronously - smart_objects::SmartObjectSPtr msg = - new smart_objects::SmartObject(smart_objects::SmartType_Map); + // must be sent to PASA HMI on shutdown synchronously + smart_objects::SmartObjectSPtr msg = + new smart_objects::SmartObject(smart_objects::SmartType_Map); - (*msg)[strings::params][strings::function_id] = - hmi_apis::FunctionID::BasicCommunication_OnSDLClose; - (*msg)[strings::params][strings::message_type] = MessageType::kNotification; - (*msg)[strings::params][strings::protocol_type] = - commands::CommandImpl::hmi_protocol_type_; - (*msg)[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; + (*msg)[strings::params][strings::function_id] = + hmi_apis::FunctionID::BasicCommunication_OnSDLClose; + (*msg)[strings::params][strings::message_type] = MessageType::kNotification; + (*msg)[strings::params][strings::protocol_type] = + commands::CommandImpl::hmi_protocol_type_; + (*msg)[strings::params][strings::protocol_version] = + commands::CommandImpl::protocol_version_; - if (!msg) { - LOG4CXX_WARN(logger_, "Null-pointer message received."); - NOTREACHED(); - return; - } + if (!msg) { + LOG4CXX_WARN(logger_, "Null-pointer message received."); + NOTREACHED(); + return; + } - // SmartObject |message| has no way to declare priority for now - utils::SharedPtr<Message> message_to_send( - new Message(protocol_handler::MessagePriority::kDefault)); + // SmartObject |message| has no way to declare priority for now + utils::SharedPtr<Message> message_to_send( + new Message(protocol_handler::MessagePriority::kDefault)); - hmi_so_factory().attachSchema(*msg, false); - LOG4CXX_DEBUG( - logger_, - "Attached schema to message, result if valid: " << msg->isValid()); + hmi_so_factory().attachSchema(*msg, false); + LOG4CXX_DEBUG( + logger_, + "Attached schema to message, result if valid: " << msg->isValid()); #ifdef HMI_DBUS_API - message_to_send->set_smart_object(*msg); + message_to_send->set_smart_object(*msg); #else - if (!ConvertSOtoMessage(*msg, *message_to_send)) { - LOG4CXX_WARN(logger_, - "Cannot send message to HMI: failed to create string"); - return; - } + if (!ConvertSOtoMessage(*msg, *message_to_send)) { + LOG4CXX_WARN(logger_, + "Cannot send message to HMI: failed to create string"); + return; + } #endif // HMI_DBUS_API - if (!hmi_handler_) { - LOG4CXX_WARN(logger_, "No HMI Handler set"); - return; - } - - hmi_handler_->SendMessageToHMI(message_to_send); + if (!hmi_handler_) { + LOG4CXX_WARN(logger_, "No HMI Handler set"); + return; } - void ApplicationManagerImpl::UnregisterAllApplications() { - LOG4CXX_DEBUG(logger_, "Unregister reason " << unregister_reason_); + hmi_handler_->SendMessageToHMI(message_to_send); +} - hmi_cooperating_ = false; - bool is_ignition_off = false; - using namespace mobile_api::AppInterfaceUnregisteredReason; - using namespace helpers; +void ApplicationManagerImpl::UnregisterAllApplications() { + LOG4CXX_DEBUG(logger_, "Unregister reason " << unregister_reason_); - is_ignition_off = - Compare<eType, EQ, ONE>(unregister_reason_, IGNITION_OFF, INVALID_ENUM); + hmi_cooperating_ = false; + bool is_ignition_off = false; + using namespace mobile_api::AppInterfaceUnregisteredReason; + using namespace helpers; - bool is_unexpected_disconnect = Compare<eType, NEQ, ALL>( - unregister_reason_, IGNITION_OFF, MASTER_RESET, FACTORY_DEFAULTS); + is_ignition_off = + Compare<eType, EQ, ONE>(unregister_reason_, IGNITION_OFF, INVALID_ENUM); - ClearTTSGlobalPropertiesList(); + bool is_unexpected_disconnect = Compare<eType, NEQ, ALL>( + unregister_reason_, IGNITION_OFF, MASTER_RESET, FACTORY_DEFAULTS); - { // A local scope to limit accessor's lifetime and release app list lock. - DataAccessor<ApplicationSet> accessor = applications(); - ApplicationSetConstIt it = accessor.GetData().begin(); - while (it != accessor.GetData().end()) { - ApplicationSharedPtr app_to_remove = *it; - ManageMobileCommand( - MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( - app_to_remove->app_id(), unregister_reason_), - commands::Command::ORIGIN_SDL); - UnregisterApplication(app_to_remove->app_id(), - mobile_apis::Result::INVALID_ENUM, - is_ignition_off, - is_unexpected_disconnect); - connection_handler().CloseSession(app_to_remove->app_id(), - connection_handler::kCommon); - it = accessor.GetData().begin(); - } - } - if (is_ignition_off) { - resume_controller().OnSuspend(); + ClearTTSGlobalPropertiesList(); + + { // A local scope to limit accessor's lifetime and release app list lock. + DataAccessor<ApplicationSet> accessor = applications(); + ApplicationSetConstIt it = accessor.GetData().begin(); + while (it != accessor.GetData().end()) { + ApplicationSharedPtr app_to_remove = *it; + ManageMobileCommand( + MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( + app_to_remove->app_id(), unregister_reason_), + commands::Command::ORIGIN_SDL); + UnregisterApplication(app_to_remove->app_id(), + mobile_apis::Result::INVALID_ENUM, + is_ignition_off, + is_unexpected_disconnect); + connection_handler().CloseSession(app_to_remove->app_id(), + connection_handler::kCommon); + it = accessor.GetData().begin(); } - request_ctrl_.terminateAllHMIRequests(); } + if (is_ignition_off) { + resume_controller().OnSuspend(); + } + request_ctrl_.terminateAllHMIRequests(); +} - void ApplicationManagerImpl::RemoveAppsWaitingForRegistration( - const connection_handler::DeviceHandle handle) { - DevicePredicate device_finder(handle); - apps_to_register_list_lock_.Acquire(); - AppsWaitRegistrationSet::iterator it_app = std::find_if( - apps_to_register_.begin(), apps_to_register_.end(), device_finder); - - while (apps_to_register_.end() != it_app) { - LOG4CXX_DEBUG(logger_, - "Waiting app: " << (*it_app)->name().c_str() - << " is removed."); - apps_to_register_.erase(it_app); - it_app = std::find_if( - apps_to_register_.begin(), apps_to_register_.end(), device_finder); - } +void ApplicationManagerImpl::RemoveAppsWaitingForRegistration( + const connection_handler::DeviceHandle handle) { + DevicePredicate device_finder(handle); + apps_to_register_list_lock_.Acquire(); + AppsWaitRegistrationSet::iterator it_app = std::find_if( + apps_to_register_.begin(), apps_to_register_.end(), device_finder); - apps_to_register_list_lock_.Release(); + while (apps_to_register_.end() != it_app) { + LOG4CXX_DEBUG(logger_, + "Waiting app: " << (*it_app)->name().c_str() + << " is removed."); + apps_to_register_.erase(it_app); + it_app = std::find_if( + apps_to_register_.begin(), apps_to_register_.end(), device_finder); } - void ApplicationManagerImpl::UnregisterApplication( - const uint32_t& app_id, - mobile_apis::Result::eType reason, - bool is_resuming, - bool is_unexpected_disconnect) { - LOG4CXX_DEBUG(logger_, - "app_id = " << app_id << "; reason = " << reason - << "; is_resuming = " << is_resuming - << "; is_unexpected_disconnect = " - << is_unexpected_disconnect); - size_t subscribed_for_way_points_app_count = 0; + apps_to_register_list_lock_.Release(); +} - // SDL sends UnsubscribeWayPoints only for last application - { - sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); - subscribed_for_way_points_app_count = - subscribed_way_points_apps_list_.size(); - } - if (1 == subscribed_for_way_points_app_count) { - LOG4CXX_ERROR(logger_, "Send UnsubscribeWayPoints"); - MessageHelper::SendUnsubscribedWayPoints(*this); - } +void ApplicationManagerImpl::UnregisterApplication( + const uint32_t& app_id, + mobile_apis::Result::eType reason, + bool is_resuming, + bool is_unexpected_disconnect) { + LOG4CXX_DEBUG(logger_, + "app_id = " << app_id << "; reason = " << reason + << "; is_resuming = " << is_resuming + << "; is_unexpected_disconnect = " + << is_unexpected_disconnect); + size_t subscribed_for_way_points_app_count = 0; - NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); - if (navi_service_status_.end() != it) { - navi_service_status_.erase(it); - } + // SDL sends UnsubscribeWayPoints only for last application + { + sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); + subscribed_for_way_points_app_count = + subscribed_way_points_apps_list_.size(); + } + if (1 == subscribed_for_way_points_app_count) { + LOG4CXX_ERROR(logger_, "Send UnsubscribeWayPoints"); + MessageHelper::SendUnsubscribedWayPoints(*this); + } - // remove appID from tts_global_properties_app_list_ - RemoveAppFromTTSGlobalPropertiesList(app_id); + NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); + if (navi_service_status_.end() != it) { + navi_service_status_.erase(it); + } - switch (reason) { - case mobile_apis::Result::SUCCESS: - break; - case mobile_apis::Result::DISALLOWED: - break; - case mobile_apis::Result::USER_DISALLOWED: - break; - case mobile_apis::Result::INVALID_CERT: - break; - case mobile_apis::Result::EXPIRED_CERT: - break; - case mobile_apis::Result::TOO_MANY_PENDING_REQUESTS: { - ApplicationSharedPtr app_ptr = application(app_id); - if (app_ptr) { - app_ptr->usage_report().RecordRemovalsForBadBehavior(); - if (reason == mobile_apis::Result::TOO_MANY_PENDING_REQUESTS) { - LOG4CXX_DEBUG( - logger_, - "INSERT: " << GetHashedAppID(app_id, app_ptr->policy_app_id())); - forbidden_applications.insert( - GetHashedAppID(app_id, app_ptr->policy_app_id())); - } + // remove appID from tts_global_properties_app_list_ + RemoveAppFromTTSGlobalPropertiesList(app_id); + + switch (reason) { + case mobile_apis::Result::SUCCESS: + break; + case mobile_apis::Result::DISALLOWED: + break; + case mobile_apis::Result::USER_DISALLOWED: + break; + case mobile_apis::Result::INVALID_CERT: + break; + case mobile_apis::Result::EXPIRED_CERT: + break; + case mobile_apis::Result::TOO_MANY_PENDING_REQUESTS: { + ApplicationSharedPtr app_ptr = application(app_id); + if (app_ptr) { + app_ptr->usage_report().RecordRemovalsForBadBehavior(); + if (reason == mobile_apis::Result::TOO_MANY_PENDING_REQUESTS) { + LOG4CXX_DEBUG( + logger_, + "INSERT: " << GetHashedAppID(app_id, app_ptr->policy_app_id())); + forbidden_applications.insert( + GetHashedAppID(app_id, app_ptr->policy_app_id())); } - break; } - default: { - LOG4CXX_ERROR(logger_, "Unknown unregister reason " << reason); - break; - } break; + break; } default: { LOG4CXX_ERROR(logger_, "Unknown unregister reason " << reason); @@ -2633,937 +2601,924 @@ default: MessageHelper::SendStopAudioPathThru(*this); } - MessageHelper::SendOnAppUnregNotificationToHMI(app_to_remove, - is_unexpected_disconnect, - *this); + MessageHelper::SendOnAppUnregNotificationToHMI( + app_to_remove, is_unexpected_disconnect, *this); request_ctrl_.terminateAppRequests(app_id); return; - } +} - void ApplicationManagerImpl::OnAppUnauthorized(const uint32_t& app_id) { - connection_handler().CloseSession(app_id, - connection_handler::kUnauthorizedApp); - } +void ApplicationManagerImpl::OnAppUnauthorized(const uint32_t& app_id) { + connection_handler().CloseSession(app_id, + connection_handler::kUnauthorizedApp); +} - void ApplicationManagerImpl::Handle(const impl::MessageFromMobile message) { - LOG4CXX_AUTO_TRACE(logger_); +void ApplicationManagerImpl::Handle(const impl::MessageFromMobile message) { + LOG4CXX_AUTO_TRACE(logger_); - if (!message) { - LOG4CXX_ERROR(logger_, "Null-pointer message received."); - return; - } - sync_primitives::AutoLock lock(stopping_application_mng_lock_); - if (is_stopping_) { - LOG4CXX_INFO(logger_, "Application manager is stopping"); - return; - } - ProcessMessageFromMobile(message); + if (!message) { + LOG4CXX_ERROR(logger_, "Null-pointer message received."); + return; + } + sync_primitives::AutoLock lock(stopping_application_mng_lock_); + if (is_stopping_) { + LOG4CXX_INFO(logger_, "Application manager is stopping"); + return; } + ProcessMessageFromMobile(message); +} - void ApplicationManagerImpl::Handle(const impl::MessageToMobile message) { - if (!protocol_handler_) { - LOG4CXX_WARN( - logger_, - "Protocol Handler is not set; cannot send message to mobile."); - return; - } +void ApplicationManagerImpl::Handle(const impl::MessageToMobile message) { + if (!protocol_handler_) { + LOG4CXX_WARN(logger_, + "Protocol Handler is not set; cannot send message to mobile."); + return; + } - utils::SharedPtr<protocol_handler::RawMessage> rawMessage = - MobileMessageHandler::HandleOutgoingMessageProtocol(message); + utils::SharedPtr<protocol_handler::RawMessage> rawMessage = + MobileMessageHandler::HandleOutgoingMessageProtocol(message); - if (!rawMessage) { - LOG4CXX_ERROR(logger_, "Failed to create raw message."); - return; - } + if (!rawMessage) { + LOG4CXX_ERROR(logger_, "Failed to create raw message."); + return; + } - bool is_final = message.is_final; - bool close_session = false; - if (is_final) { - if (1 < connection_handler().GetConnectionSessionsCount( - message->connection_key())) { - is_final = false; - close_session = true; - } + bool is_final = message.is_final; + bool close_session = false; + if (is_final) { + if (1 < connection_handler().GetConnectionSessionsCount( + message->connection_key())) { + is_final = false; + close_session = true; } + } - protocol_handler_->SendMessageToMobileApp(rawMessage, is_final); - LOG4CXX_INFO(logger_, "Message for mobile given away"); + protocol_handler_->SendMessageToMobileApp(rawMessage, is_final); + LOG4CXX_INFO(logger_, "Message for mobile given away"); - if (close_session) { - connection_handler().CloseSession(message->connection_key(), - connection_handler::kCommon); - } + if (close_session) { + connection_handler().CloseSession(message->connection_key(), + connection_handler::kCommon); } +} - void ApplicationManagerImpl::Handle(const impl::MessageFromHmi message) { - LOG4CXX_AUTO_TRACE(logger_); +void ApplicationManagerImpl::Handle(const impl::MessageFromHmi message) { + LOG4CXX_AUTO_TRACE(logger_); - if (!message) { - LOG4CXX_ERROR(logger_, "Null-pointer message received."); - return; - } + if (!message) { + LOG4CXX_ERROR(logger_, "Null-pointer message received."); + return; + } + + ProcessMessageFromHMI(message); +} - ProcessMessageFromHMI(message); +void ApplicationManagerImpl::Handle(const impl::MessageToHmi message) { + LOG4CXX_AUTO_TRACE(logger_); + if (!hmi_handler_) { + LOG4CXX_ERROR(logger_, "Observer is not set for HMIMessageHandler"); + return; } - void ApplicationManagerImpl::Handle(const impl::MessageToHmi message) { - LOG4CXX_AUTO_TRACE(logger_); - if (!hmi_handler_) { - LOG4CXX_ERROR(logger_, "Observer is not set for HMIMessageHandler"); - return; - } + hmi_handler_->SendMessageToHMI(message); + LOG4CXX_INFO(logger_, "Message for HMI given away"); +} + +void ApplicationManagerImpl::Handle(const impl::AudioData message) { + LOG4CXX_AUTO_TRACE(logger_); + smart_objects::SmartObjectSPtr on_audio_pass = + new smart_objects::SmartObject(); - hmi_handler_->SendMessageToHMI(message); - LOG4CXX_INFO(logger_, "Message for HMI given away"); + if (!on_audio_pass) { + LOG4CXX_ERROR(logger_, "OnAudioPassThru NULL pointer"); + return; } - void ApplicationManagerImpl::Handle(const impl::AudioData message) { - LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObjectSPtr on_audio_pass = - new smart_objects::SmartObject(); + LOG4CXX_DEBUG(logger_, "Fill smart object"); - if (!on_audio_pass) { - LOG4CXX_ERROR(logger_, "OnAudioPassThru NULL pointer"); - return; - } + (*on_audio_pass)[strings::params][strings::message_type] = + application_manager::MessageType::kNotification; - LOG4CXX_DEBUG(logger_, "Fill smart object"); + (*on_audio_pass)[strings::params][strings::connection_key] = + static_cast<int32_t>(message.session_key); + (*on_audio_pass)[strings::params][strings::function_id] = + mobile_apis::FunctionID::OnAudioPassThruID; - (*on_audio_pass)[strings::params][strings::message_type] = - application_manager::MessageType::kNotification; + LOG4CXX_DEBUG(logger_, "Fill binary data"); + // binary data + (*on_audio_pass)[strings::params][strings::binary_data] = + smart_objects::SmartObject(message.binary_data); - (*on_audio_pass)[strings::params][strings::connection_key] = - static_cast<int32_t>(message.session_key); - (*on_audio_pass)[strings::params][strings::function_id] = - mobile_apis::FunctionID::OnAudioPassThruID; + LOG4CXX_DEBUG(logger_, "After fill binary data"); + LOG4CXX_DEBUG(logger_, "Send data"); + CommandSharedPtr command(MobileCommandFactory::CreateCommand( + on_audio_pass, commands::Command::ORIGIN_SDL, *this)); + if (!command) { + LOG4CXX_WARN(logger_, "Failed to create mobile command from smart object"); + return; + } - LOG4CXX_DEBUG(logger_, "Fill binary data"); - // binary data - (*on_audio_pass)[strings::params][strings::binary_data] = - smart_objects::SmartObject(message.binary_data); + command->Init(); + command->Run(); + command->CleanUp(); +} - LOG4CXX_DEBUG(logger_, "After fill binary data"); - LOG4CXX_DEBUG(logger_, "Send data"); - CommandSharedPtr command(MobileCommandFactory::CreateCommand( - on_audio_pass, commands::Command::ORIGIN_SDL, *this)); - if (!command) { - LOG4CXX_WARN(logger_, - "Failed to create mobile command from smart object"); - return; - } +mobile_apis::Result::eType ApplicationManagerImpl::CheckPolicyPermissions( + const std::string& policy_app_id, + mobile_apis::HMILevel::eType hmi_level, + mobile_apis::FunctionID::eType function_id, + const RPCParams& rpc_params, + CommandParametersPermissions* params_permissions) { + LOG4CXX_AUTO_TRACE(logger_); + // TODO(AOleynik): Remove check of policy_enable, when this flag will be + // unused in config file + if (!GetPolicyHandler().PolicyEnabled()) { + return mobile_apis::Result::SUCCESS; + } - command->Init(); - command->Run(); - command->CleanUp(); - } - - mobile_apis::Result::eType ApplicationManagerImpl::CheckPolicyPermissions( - const std::string& policy_app_id, - mobile_apis::HMILevel::eType hmi_level, - mobile_apis::FunctionID::eType function_id, - const RPCParams& rpc_params, - CommandParametersPermissions* params_permissions) { - LOG4CXX_AUTO_TRACE(logger_); - // TODO(AOleynik): Remove check of policy_enable, when this flag will be - // unused in config file - if (!GetPolicyHandler().PolicyEnabled()) { - return mobile_apis::Result::SUCCESS; - } - - const std::string stringified_functionID = - MessageHelper::StringifiedFunctionID(function_id); - const std::string stringified_hmi_level = - MessageHelper::StringifiedHMILevel(hmi_level); - LOG4CXX_DEBUG(logger_, - "Checking permissions for " - << policy_app_id << " in " << stringified_hmi_level - << " rpc " << stringified_functionID); - policy::CheckPermissionResult result; - GetPolicyHandler().CheckPermissions(policy_app_id, - stringified_hmi_level, - stringified_functionID, - rpc_params, - result); - - if (NULL != params_permissions) { - params_permissions->allowed_params = result.list_of_allowed_params; - params_permissions->disallowed_params = result.list_of_disallowed_params; - params_permissions->undefined_params = result.list_of_undefined_params; - } - - if (hmi_level == mobile_apis::HMILevel::HMI_NONE && - function_id != mobile_apis::FunctionID::UnregisterAppInterfaceID) { - ApplicationSharedPtr app = application_by_policy_id(policy_app_id); - if (!app) { - LOG4CXX_ERROR(logger_, - "No application for policy id " << policy_app_id); - return mobile_apis::Result::GENERIC_ERROR; - } - if (result.hmi_level_permitted != policy::kRpcAllowed) { - app->usage_report().RecordRpcSentInHMINone(); - } + const std::string stringified_functionID = + MessageHelper::StringifiedFunctionID(function_id); + const std::string stringified_hmi_level = + MessageHelper::StringifiedHMILevel(hmi_level); + LOG4CXX_DEBUG(logger_, + "Checking permissions for " << policy_app_id << " in " + << stringified_hmi_level << " rpc " + << stringified_functionID); + policy::CheckPermissionResult result; + GetPolicyHandler().CheckPermissions(policy_app_id, + stringified_hmi_level, + stringified_functionID, + rpc_params, + result); + + if (NULL != params_permissions) { + params_permissions->allowed_params = result.list_of_allowed_params; + params_permissions->disallowed_params = result.list_of_disallowed_params; + params_permissions->undefined_params = result.list_of_undefined_params; + } + + if (hmi_level == mobile_apis::HMILevel::HMI_NONE && + function_id != mobile_apis::FunctionID::UnregisterAppInterfaceID) { + ApplicationSharedPtr app = application_by_policy_id(policy_app_id); + if (!app) { + LOG4CXX_ERROR(logger_, "No application for policy id " << policy_app_id); + return mobile_apis::Result::GENERIC_ERROR; } + if (result.hmi_level_permitted != policy::kRpcAllowed) { + app->usage_report().RecordRpcSentInHMINone(); + } + } - const std::string log_msg = "Application: " + policy_app_id + ", RPC: " + - stringified_functionID + ", HMI status: " + - stringified_hmi_level; + const std::string log_msg = "Application: " + policy_app_id + ", RPC: " + + stringified_functionID + ", HMI status: " + + stringified_hmi_level; - if (result.hmi_level_permitted != policy::kRpcAllowed) { - LOG4CXX_WARN(logger_, "Request is blocked by policies. " << log_msg); + if (result.hmi_level_permitted != policy::kRpcAllowed) { + LOG4CXX_WARN(logger_, "Request is blocked by policies. " << log_msg); - ApplicationSharedPtr app = application_by_policy_id(policy_app_id); - if (!app) { - LOG4CXX_ERROR(logger_, - "No application for policy id " << policy_app_id); - return mobile_apis::Result::GENERIC_ERROR; - } - app->usage_report().RecordPolicyRejectedRpcCall(); - - switch (result.hmi_level_permitted) { - case policy::kRpcDisallowed: - return mobile_apis::Result::DISALLOWED; - case policy::kRpcUserDisallowed: - return mobile_apis::Result::USER_DISALLOWED; - default: - return mobile_apis::Result::INVALID_ENUM; - } + ApplicationSharedPtr app = application_by_policy_id(policy_app_id); + if (!app) { + LOG4CXX_ERROR(logger_, "No application for policy id " << policy_app_id); + return mobile_apis::Result::GENERIC_ERROR; } - LOG4CXX_DEBUG(logger_, "Request is allowed by policies. " << log_msg); - return mobile_api::Result::SUCCESS; - } + app->usage_report().RecordPolicyRejectedRpcCall(); - void ApplicationManagerImpl::OnLowVoltage() { - LOG4CXX_AUTO_TRACE(logger_); - is_low_voltage_ = true; - request_ctrl_.OnLowVoltage(); + switch (result.hmi_level_permitted) { + case policy::kRpcDisallowed: + return mobile_apis::Result::DISALLOWED; + case policy::kRpcUserDisallowed: + return mobile_apis::Result::USER_DISALLOWED; + default: + return mobile_apis::Result::INVALID_ENUM; + } } + LOG4CXX_DEBUG(logger_, "Request is allowed by policies. " << log_msg); + return mobile_api::Result::SUCCESS; +} - bool ApplicationManagerImpl::IsLowVoltage() { - LOG4CXX_TRACE(logger_, "result: " << is_low_voltage_); - return is_low_voltage_; - } +void ApplicationManagerImpl::OnLowVoltage() { + LOG4CXX_AUTO_TRACE(logger_); + is_low_voltage_ = true; + request_ctrl_.OnLowVoltage(); +} - std::string ApplicationManagerImpl::GetHashedAppID( - uint32_t connection_key, const std::string& mobile_app_id) const { - uint32_t device_id = 0; - connection_handler().GetDataOnSessionKey( - connection_key, 0, NULL, &device_id); - std::string device_name; - connection_handler().get_session_observer().GetDataOnDeviceID( - device_id, &device_name, NULL, NULL, NULL); +bool ApplicationManagerImpl::IsLowVoltage() { + LOG4CXX_TRACE(logger_, "result: " << is_low_voltage_); + return is_low_voltage_; +} + +std::string ApplicationManagerImpl::GetHashedAppID( + uint32_t connection_key, const std::string& mobile_app_id) const { + uint32_t device_id = 0; + connection_handler().GetDataOnSessionKey(connection_key, 0, NULL, &device_id); + std::string device_name; + connection_handler().get_session_observer().GetDataOnDeviceID( + device_id, &device_name, NULL, NULL, NULL); - return mobile_app_id + device_name; + return mobile_app_id + device_name; +} + +bool ApplicationManagerImpl::HMILevelAllowsStreaming( + uint32_t app_id, protocol_handler::ServiceType service_type) const { + LOG4CXX_AUTO_TRACE(logger_); + using namespace mobile_apis::HMILevel; + using namespace helpers; + + ApplicationSharedPtr app = application(app_id); + if (!app) { + LOG4CXX_WARN(logger_, "An application is not registered."); + return false; } + return Compare<eType, EQ, ONE>(app->hmi_level(), HMI_FULL, HMI_LIMITED); +} - bool ApplicationManagerImpl::HMILevelAllowsStreaming( - uint32_t app_id, protocol_handler::ServiceType service_type) const { - LOG4CXX_AUTO_TRACE(logger_); - using namespace mobile_apis::HMILevel; - using namespace helpers; +bool ApplicationManagerImpl::CanAppStream( + uint32_t app_id, protocol_handler::ServiceType service_type) const { + using namespace protocol_handler; + LOG4CXX_AUTO_TRACE(logger_); - ApplicationSharedPtr app = application(app_id); - if (!app) { - LOG4CXX_WARN(logger_, "An application is not registered."); - return false; - } - return Compare<eType, EQ, ONE>(app->hmi_level(), HMI_FULL, HMI_LIMITED); + ApplicationSharedPtr app = application(app_id); + if (!app) { + LOG4CXX_WARN(logger_, "An application is not registered."); + return false; } - bool ApplicationManagerImpl::CanAppStream( - uint32_t app_id, protocol_handler::ServiceType service_type) const { - using namespace protocol_handler; - LOG4CXX_AUTO_TRACE(logger_); + bool is_allowed = false; + if (ServiceType::kMobileNav == service_type) { + is_allowed = app->video_streaming_allowed(); + } else if (ServiceType::kAudio == service_type) { + is_allowed = app->audio_streaming_allowed(); + } else { + LOG4CXX_WARN(logger_, "Unsupported service_type " << service_type); + } - ApplicationSharedPtr app = application(app_id); - if (!app) { - LOG4CXX_WARN(logger_, "An application is not registered."); - return false; - } + return HMILevelAllowsStreaming(app_id, service_type) && is_allowed; +} - bool is_allowed = false; - if (ServiceType::kMobileNav == service_type) { - is_allowed = app->video_streaming_allowed(); - } else if (ServiceType::kAudio == service_type) { - is_allowed = app->audio_streaming_allowed(); - } else { - LOG4CXX_WARN(logger_, "Unsupported service_type " << service_type); - } +void ApplicationManagerImpl::ForbidStreaming(uint32_t app_id) { + using namespace mobile_apis::AppInterfaceUnregisteredReason; + using namespace mobile_apis::Result; - return HMILevelAllowsStreaming(app_id, service_type) && is_allowed; - } + LOG4CXX_AUTO_TRACE(logger_); - void ApplicationManagerImpl::ForbidStreaming(uint32_t app_id) { - using namespace mobile_apis::AppInterfaceUnregisteredReason; - using namespace mobile_apis::Result; + ApplicationSharedPtr app = application(app_id); + if (!app || !app->is_navi()) { + LOG4CXX_DEBUG(logger_, "There is no navi application with id: " << app_id); + return; + } - LOG4CXX_AUTO_TRACE(logger_); + if (navi_app_to_stop_.end() != std::find(navi_app_to_stop_.begin(), + navi_app_to_stop_.end(), + app_id) || + navi_app_to_end_stream_.end() != + std::find(navi_app_to_end_stream_.begin(), + navi_app_to_end_stream_.end(), + app_id)) { + return; + } - ApplicationSharedPtr app = application(app_id); - if (!app || !app->is_navi()) { - LOG4CXX_DEBUG(logger_, - "There is no navi application with id: " << app_id); - return; - } + NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); + if (navi_service_status_.end() == it || + (!it->second.first && !it->second.second)) { + ManageMobileCommand( + MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( + app_id, PROTOCOL_VIOLATION), + commands::Command::ORIGIN_SDL); + UnregisterApplication(app_id, ABORTED); + return; + } + EndNaviServices(app_id); +} - if (navi_app_to_stop_.end() != std::find(navi_app_to_stop_.begin(), - navi_app_to_stop_.end(), - app_id) || - navi_app_to_end_stream_.end() != - std::find(navi_app_to_end_stream_.begin(), - navi_app_to_end_stream_.end(), - app_id)) { - return; - } +void ApplicationManagerImpl::OnAppStreaming( + uint32_t app_id, protocol_handler::ServiceType service_type, bool state) { + using namespace protocol_handler; + LOG4CXX_AUTO_TRACE(logger_); - NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); - if (navi_service_status_.end() == it || - (!it->second.first && !it->second.second)) { - ManageMobileCommand( - MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( - app_id, PROTOCOL_VIOLATION), - commands::Command::ORIGIN_SDL); - UnregisterApplication(app_id, ABORTED); - return; - } - EndNaviServices(app_id); + ApplicationSharedPtr app = application(app_id); + if (!app || !app->is_navi()) { + LOG4CXX_DEBUG(logger_, " There is no navi application with id: " << app_id); + return; } + DCHECK_OR_RETURN_VOID(media_manager_); - void ApplicationManagerImpl::OnAppStreaming( - uint32_t app_id, protocol_handler::ServiceType service_type, bool state) { - using namespace protocol_handler; - LOG4CXX_AUTO_TRACE(logger_); + if (state) { + state_ctrl_.OnNaviStreamingStarted(); + media_manager_->StartStreaming(app_id, service_type); + } else { + media_manager_->StopStreaming(app_id, service_type); + state_ctrl_.OnNaviStreamingStopped(); + } +} - ApplicationSharedPtr app = application(app_id); - if (!app || !app->is_navi()) { - LOG4CXX_DEBUG(logger_, - " There is no navi application with id: " << app_id); - return; - } - DCHECK_OR_RETURN_VOID(media_manager_); +void ApplicationManagerImpl::EndNaviServices(uint32_t app_id) { + using namespace protocol_handler; + LOG4CXX_AUTO_TRACE(logger_); - if (state) { - state_ctrl_.OnNaviStreamingStarted(); - media_manager_->StartStreaming(app_id, service_type); - } else { - media_manager_->StopStreaming(app_id, service_type); - state_ctrl_.OnNaviStreamingStopped(); - } + ApplicationSharedPtr app = application(app_id); + if (!app || !app->is_navi()) { + LOG4CXX_DEBUG(logger_, "There is no navi application with id: " << app_id); + return; } - void ApplicationManagerImpl::EndNaviServices(uint32_t app_id) { - using namespace protocol_handler; - LOG4CXX_AUTO_TRACE(logger_); + NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); + if (navi_service_status_.end() == it) { + LOG4CXX_ERROR(logger_, "No info about navi servicies for app"); + return; + } - ApplicationSharedPtr app = application(app_id); - if (!app || !app->is_navi()) { - LOG4CXX_DEBUG(logger_, - "There is no navi application with id: " << app_id); - return; + if (connection_handler_) { + if (it->second.first) { + LOG4CXX_DEBUG(logger_, "Going to end video service"); + connection_handler().SendEndService(app_id, ServiceType::kMobileNav); + app->StopStreamingForce(ServiceType::kMobileNav); } - - NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); - if (navi_service_status_.end() == it) { - LOG4CXX_ERROR(logger_, "No info about navi servicies for app"); - return; + if (it->second.second) { + LOG4CXX_DEBUG(logger_, "Going to end audio service"); + connection_handler().SendEndService(app_id, ServiceType::kAudio); + app->StopStreamingForce(ServiceType::kAudio); } + DisallowStreaming(app_id); - if (connection_handler_) { - if (it->second.first) { - LOG4CXX_DEBUG(logger_, "Going to end video service"); - connection_handler().SendEndService(app_id, ServiceType::kMobileNav); - app->StopStreamingForce(ServiceType::kMobileNav); - } - if (it->second.second) { - LOG4CXX_DEBUG(logger_, "Going to end audio service"); - connection_handler().SendEndService(app_id, ServiceType::kAudio); - app->StopStreamingForce(ServiceType::kAudio); - } - DisallowStreaming(app_id); + navi_app_to_stop_.push_back(app_id); - navi_app_to_stop_.push_back(app_id); + TimerSPtr close_timer(utils::MakeShared<timer::Timer>( + "CloseNaviAppTimer", + new TimerTaskImpl<ApplicationManagerImpl>( + this, &ApplicationManagerImpl::CloseNaviApp))); + close_timer->Start(navi_close_app_timeout_, true); - TimerSPtr close_timer(utils::MakeShared<timer::Timer>( - "CloseNaviAppTimer", - new TimerTaskImpl<ApplicationManagerImpl>( - this, &ApplicationManagerImpl::CloseNaviApp))); - close_timer->Start(navi_close_app_timeout_, true); + sync_primitives::AutoLock lock(timer_pool_lock_); + timer_pool_.push_back(close_timer); + } +} - sync_primitives::AutoLock lock(timer_pool_lock_); - timer_pool_.push_back(close_timer); - } +void ApplicationManagerImpl::OnHMILevelChanged( + uint32_t app_id, + mobile_apis::HMILevel::eType from, + mobile_apis::HMILevel::eType to) { + LOG4CXX_AUTO_TRACE(logger_); + using namespace mobile_apis::HMILevel; + using namespace helpers; + + if (from == to) { + LOG4CXX_TRACE(logger_, "HMILevel from = to"); + return; } - void ApplicationManagerImpl::OnHMILevelChanged( - uint32_t app_id, - mobile_apis::HMILevel::eType from, - mobile_apis::HMILevel::eType to) { - LOG4CXX_AUTO_TRACE(logger_); - using namespace mobile_apis::HMILevel; - using namespace helpers; + ApplicationSharedPtr app = application(app_id); + if (!app || !app->is_navi()) { + LOG4CXX_ERROR(logger_, "Navi application not found"); + return; + } - if (from == to) { - LOG4CXX_TRACE(logger_, "HMILevel from = to"); - return; + if (to == HMI_FULL || to == HMI_LIMITED) { + LOG4CXX_TRACE(logger_, "HMILevel to FULL or LIMITED"); + if (from == HMI_BACKGROUND) { + LOG4CXX_TRACE(logger_, "HMILevel from BACKGROUND"); + AllowStreaming(app_id); } + } else if (to == HMI_BACKGROUND) { + LOG4CXX_TRACE(logger_, "HMILevel to BACKGROUND"); + if (from == HMI_FULL || from == HMI_LIMITED) { + LOG4CXX_TRACE(logger_, "HMILevel from FULL or LIMITED"); + navi_app_to_end_stream_.push_back(app_id); + TimerSPtr end_stream_timer(utils::MakeShared<timer::Timer>( + "AppShouldFinishStreaming", + new TimerTaskImpl<ApplicationManagerImpl>( + this, &ApplicationManagerImpl::EndNaviStreaming))); + end_stream_timer->Start(navi_end_stream_timeout_, true); - ApplicationSharedPtr app = application(app_id); - if (!app || !app->is_navi()) { - LOG4CXX_ERROR(logger_, "Navi application not found"); - return; + sync_primitives::AutoLock lock(timer_pool_lock_); + timer_pool_.push_back(end_stream_timer); } - - if (to == HMI_FULL || to == HMI_LIMITED) { - LOG4CXX_TRACE(logger_, "HMILevel to FULL or LIMITED"); - if (from == HMI_BACKGROUND) { - LOG4CXX_TRACE(logger_, "HMILevel from BACKGROUND"); - AllowStreaming(app_id); - } - } else if (to == HMI_BACKGROUND) { - LOG4CXX_TRACE(logger_, "HMILevel to BACKGROUND"); - if (from == HMI_FULL || from == HMI_LIMITED) { - LOG4CXX_TRACE(logger_, "HMILevel from FULL or LIMITED"); - navi_app_to_end_stream_.push_back(app_id); - TimerSPtr end_stream_timer(utils::MakeShared<timer::Timer>( - "AppShouldFinishStreaming", - new TimerTaskImpl<ApplicationManagerImpl>( - this, &ApplicationManagerImpl::EndNaviStreaming))); - end_stream_timer->Start(navi_end_stream_timeout_, true); - - sync_primitives::AutoLock lock(timer_pool_lock_); - timer_pool_.push_back(end_stream_timer); - } - } else if (to == HMI_NONE) { - LOG4CXX_TRACE(logger_, "HMILevel to NONE"); - if (from == HMI_FULL || from == HMI_LIMITED || from == HMI_BACKGROUND) { - EndNaviServices(app_id); - } + } else if (to == HMI_NONE) { + LOG4CXX_TRACE(logger_, "HMILevel to NONE"); + if (from == HMI_FULL || from == HMI_LIMITED || from == HMI_BACKGROUND) { + EndNaviServices(app_id); } } +} - void ApplicationManagerImpl::SendHMIStatusNotification( - const utils::SharedPtr<Application> app) { - LOG4CXX_AUTO_TRACE(logger_); - DCHECK_OR_RETURN_VOID(app); - smart_objects::SmartObjectSPtr notification = - utils::MakeShared<smart_objects::SmartObject>(); - smart_objects::SmartObject& message = *notification; +void ApplicationManagerImpl::SendHMIStatusNotification( + const utils::SharedPtr<Application> app) { + LOG4CXX_AUTO_TRACE(logger_); + DCHECK_OR_RETURN_VOID(app); + smart_objects::SmartObjectSPtr notification = + utils::MakeShared<smart_objects::SmartObject>(); + smart_objects::SmartObject& message = *notification; - message[strings::params][strings::function_id] = - static_cast<int32_t>(mobile_api::FunctionID::OnHMIStatusID); + message[strings::params][strings::function_id] = + static_cast<int32_t>(mobile_api::FunctionID::OnHMIStatusID); - message[strings::params][strings::message_type] = - static_cast<int32_t>(application_manager::MessageType::kNotification); + message[strings::params][strings::message_type] = + static_cast<int32_t>(application_manager::MessageType::kNotification); - message[strings::params][strings::connection_key] = - static_cast<int32_t>(app->app_id()); + message[strings::params][strings::connection_key] = + static_cast<int32_t>(app->app_id()); - message[strings::msg_params][strings::hmi_level] = - static_cast<int32_t>(app->hmi_level()); + message[strings::msg_params][strings::hmi_level] = + static_cast<int32_t>(app->hmi_level()); - message[strings::msg_params][strings::audio_streaming_state] = - static_cast<int32_t>(app->audio_streaming_state()); + message[strings::msg_params][strings::audio_streaming_state] = + static_cast<int32_t>(app->audio_streaming_state()); - message[strings::msg_params][strings::system_context] = - static_cast<int32_t>(app->system_context()); + message[strings::msg_params][strings::system_context] = + static_cast<int32_t>(app->system_context()); - ManageMobileCommand(notification, commands::Command::ORIGIN_SDL); - } + ManageMobileCommand(notification, commands::Command::ORIGIN_SDL); +} - void ApplicationManagerImpl::ClearTimerPool() { - LOG4CXX_AUTO_TRACE(logger_); +void ApplicationManagerImpl::ClearTimerPool() { + LOG4CXX_AUTO_TRACE(logger_); - std::vector<TimerSPtr> new_timer_pool; + std::vector<TimerSPtr> new_timer_pool; - sync_primitives::AutoLock lock(timer_pool_lock_); - new_timer_pool.push_back(timer_pool_[0]); + sync_primitives::AutoLock lock(timer_pool_lock_); + new_timer_pool.push_back(timer_pool_[0]); - for (size_t i = 1; i < timer_pool_.size(); ++i) { - if (timer_pool_[i]->is_running()) { - new_timer_pool.push_back(timer_pool_[i]); - } + for (size_t i = 1; i < timer_pool_.size(); ++i) { + if (timer_pool_[i]->is_running()) { + new_timer_pool.push_back(timer_pool_[i]); } - - timer_pool_.swap(new_timer_pool); - new_timer_pool.clear(); } - void ApplicationManagerImpl::CloseNaviApp() { - LOG4CXX_AUTO_TRACE(logger_); - using namespace mobile_apis::AppInterfaceUnregisteredReason; - using namespace mobile_apis::Result; + timer_pool_.swap(new_timer_pool); + new_timer_pool.clear(); +} - uint32_t app_id = navi_app_to_stop_.front(); - navi_app_to_stop_.pop_front(); +void ApplicationManagerImpl::CloseNaviApp() { + LOG4CXX_AUTO_TRACE(logger_); + using namespace mobile_apis::AppInterfaceUnregisteredReason; + using namespace mobile_apis::Result; - NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); - if (navi_service_status_.end() != it) { - if (it->second.first || it->second.second) { - LOG4CXX_INFO(logger_, - "App haven't answered for EndService. Unregister it."); - ManageMobileCommand( - MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( - app_id, PROTOCOL_VIOLATION), - commands::Command::ORIGIN_SDL); - UnregisterApplication(app_id, ABORTED); - } + uint32_t app_id = navi_app_to_stop_.front(); + navi_app_to_stop_.pop_front(); + + NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); + if (navi_service_status_.end() != it) { + if (it->second.first || it->second.second) { + LOG4CXX_INFO(logger_, + "App haven't answered for EndService. Unregister it."); + ManageMobileCommand( + MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( + app_id, PROTOCOL_VIOLATION), + commands::Command::ORIGIN_SDL); + UnregisterApplication(app_id, ABORTED); } } +} - void ApplicationManagerImpl::EndNaviStreaming() { - LOG4CXX_AUTO_TRACE(logger_); - using namespace mobile_apis::AppInterfaceUnregisteredReason; - using namespace mobile_apis::Result; +void ApplicationManagerImpl::EndNaviStreaming() { + LOG4CXX_AUTO_TRACE(logger_); + using namespace mobile_apis::AppInterfaceUnregisteredReason; + using namespace mobile_apis::Result; - uint32_t app_id = navi_app_to_end_stream_.front(); - navi_app_to_end_stream_.pop_front(); + uint32_t app_id = navi_app_to_end_stream_.front(); + navi_app_to_end_stream_.pop_front(); - if (navi_app_to_stop_.end() == - std::find(navi_app_to_stop_.begin(), navi_app_to_stop_.end(), app_id)) { - DisallowStreaming(app_id); - } + if (navi_app_to_stop_.end() == + std::find(navi_app_to_stop_.begin(), navi_app_to_stop_.end(), app_id)) { + DisallowStreaming(app_id); } +} - void ApplicationManagerImpl::DisallowStreaming(uint32_t app_id) { - using namespace protocol_handler; - LOG4CXX_AUTO_TRACE(logger_); +void ApplicationManagerImpl::DisallowStreaming(uint32_t app_id) { + using namespace protocol_handler; + LOG4CXX_AUTO_TRACE(logger_); - ApplicationSharedPtr app = application(app_id); - if (!app || !app->is_navi()) { - LOG4CXX_ERROR(logger_, "Navi application not found"); - return; - } + ApplicationSharedPtr app = application(app_id); + if (!app || !app->is_navi()) { + LOG4CXX_ERROR(logger_, "Navi application not found"); + return; + } - NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); - if (navi_service_status_.end() != it) { - if (it->second.first) { - app->set_video_streaming_allowed(false); - } - if (it->second.second) { - app->set_audio_streaming_allowed(false); - } + NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); + if (navi_service_status_.end() != it) { + if (it->second.first) { + app->set_video_streaming_allowed(false); + } + if (it->second.second) { + app->set_audio_streaming_allowed(false); } } +} - void ApplicationManagerImpl::AllowStreaming(uint32_t app_id) { - using namespace protocol_handler; - LOG4CXX_AUTO_TRACE(logger_); +void ApplicationManagerImpl::AllowStreaming(uint32_t app_id) { + using namespace protocol_handler; + LOG4CXX_AUTO_TRACE(logger_); - ApplicationSharedPtr app = application(app_id); - if (!app || !app->is_navi()) { - LOG4CXX_ERROR(logger_, "Navi application not found"); - return; - } + ApplicationSharedPtr app = application(app_id); + if (!app || !app->is_navi()) { + LOG4CXX_ERROR(logger_, "Navi application not found"); + return; + } - NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); - if (navi_service_status_.end() != it) { - if (it->second.first) { - app->set_video_streaming_allowed(true); - } - if (it->second.second) { - app->set_audio_streaming_allowed(true); - } + NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); + if (navi_service_status_.end() != it) { + if (it->second.first) { + app->set_video_streaming_allowed(true); + } + if (it->second.second) { + app->set_audio_streaming_allowed(true); } } +} - bool ApplicationManagerImpl::IsApplicationForbidden( - uint32_t connection_key, const std::string& mobile_app_id) const { - const std::string name = GetHashedAppID(connection_key, mobile_app_id); - return forbidden_applications.find(name) != forbidden_applications.end(); - } +bool ApplicationManagerImpl::IsApplicationForbidden( + uint32_t connection_key, const std::string& mobile_app_id) const { + const std::string name = GetHashedAppID(connection_key, mobile_app_id); + return forbidden_applications.find(name) != forbidden_applications.end(); +} - policy::DeviceConsent ApplicationManagerImpl::GetUserConsentForDevice( - const std::string& device_id) const { - return policy_handler_.GetUserConsentForDevice(device_id); - } +policy::DeviceConsent ApplicationManagerImpl::GetUserConsentForDevice( + const std::string& device_id) const { + return policy_handler_.GetUserConsentForDevice(device_id); +} - void ApplicationManagerImpl::OnWakeUp() { - LOG4CXX_AUTO_TRACE(logger_); - is_low_voltage_ = false; - request_ctrl_.OnWakeUp(); - } +void ApplicationManagerImpl::OnWakeUp() { + LOG4CXX_AUTO_TRACE(logger_); + is_low_voltage_ = false; + request_ctrl_.OnWakeUp(); +} - mobile_apis::Result::eType ApplicationManagerImpl::SaveBinary( - const std::vector<uint8_t>& binary_data, - const std::string& file_path, - const std::string& file_name, - const int64_t offset) { - LOG4CXX_DEBUG(logger_, - "SaveBinaryWithOffset binary_size = " - << binary_data.size() << " offset = " << offset); - - if (binary_data.size() > file_system::GetAvailableDiskSpace(file_path)) { - LOG4CXX_ERROR(logger_, "Out of free disc space."); - return mobile_apis::Result::OUT_OF_MEMORY; - } - - const std::string full_file_path = file_path + "/" + file_name; - const int64_t file_size = file_system::FileSize(full_file_path); - std::ofstream* file_stream; - if (offset != 0) { - if (file_size != offset) { - LOG4CXX_DEBUG(logger_, - "ApplicationManagerImpl::SaveBinaryWithOffset offset" - << " does'n match existing file size"); - return mobile_apis::Result::INVALID_DATA; - } - file_stream = file_system::Open(full_file_path, std::ios_base::app); - } else { - LOG4CXX_DEBUG( - logger_, - "ApplicationManagerImpl::SaveBinaryWithOffset offset is 0, rewrite"); - // if offset == 0: rewrite file - file_stream = file_system::Open(full_file_path, std::ios_base::out); - } +mobile_apis::Result::eType ApplicationManagerImpl::SaveBinary( + const std::vector<uint8_t>& binary_data, + const std::string& file_path, + const std::string& file_name, + const int64_t offset) { + LOG4CXX_DEBUG(logger_, + "SaveBinaryWithOffset binary_size = " + << binary_data.size() << " offset = " << offset); - if (!file_system::Write( - file_stream, binary_data.data(), binary_data.size())) { - file_system::Close(file_stream); - delete file_stream; - file_stream = NULL; - return mobile_apis::Result::GENERIC_ERROR; + if (binary_data.size() > file_system::GetAvailableDiskSpace(file_path)) { + LOG4CXX_ERROR(logger_, "Out of free disc space."); + return mobile_apis::Result::OUT_OF_MEMORY; + } + + const std::string full_file_path = file_path + "/" + file_name; + const int64_t file_size = file_system::FileSize(full_file_path); + std::ofstream* file_stream; + if (offset != 0) { + if (file_size != offset) { + LOG4CXX_DEBUG(logger_, + "ApplicationManagerImpl::SaveBinaryWithOffset offset" + << " does'n match existing file size"); + return mobile_apis::Result::INVALID_DATA; } + file_stream = file_system::Open(full_file_path, std::ios_base::app); + } else { + LOG4CXX_DEBUG( + logger_, + "ApplicationManagerImpl::SaveBinaryWithOffset offset is 0, rewrite"); + // if offset == 0: rewrite file + file_stream = file_system::Open(full_file_path, std::ios_base::out); + } + if (!file_system::Write( + file_stream, binary_data.data(), binary_data.size())) { file_system::Close(file_stream); delete file_stream; file_stream = NULL; - LOG4CXX_INFO(logger_, "Successfully write data to file"); - return mobile_apis::Result::SUCCESS; + return mobile_apis::Result::GENERIC_ERROR; } - uint32_t ApplicationManagerImpl::GetAvailableSpaceForApp( - const std::string& folder_name) { - const uint32_t app_quota = settings_.app_dir_quota(); - std::string app_storage_path = settings_.app_storage_folder(); + file_system::Close(file_stream); + delete file_stream; + file_stream = NULL; + LOG4CXX_INFO(logger_, "Successfully write data to file"); + return mobile_apis::Result::SUCCESS; +} - app_storage_path += "/"; - app_storage_path += folder_name; +uint32_t ApplicationManagerImpl::GetAvailableSpaceForApp( + const std::string& folder_name) { + const uint32_t app_quota = settings_.app_dir_quota(); + std::string app_storage_path = settings_.app_storage_folder(); - if (file_system::DirectoryExists(app_storage_path)) { - size_t size_of_directory = file_system::DirectorySize(app_storage_path); - if (app_quota < size_of_directory) { - return 0; - } + app_storage_path += "/"; + app_storage_path += folder_name; - uint32_t current_app_quota = app_quota - size_of_directory; - uint32_t available_disk_space = - file_system::GetAvailableDiskSpace(app_storage_path); + if (file_system::DirectoryExists(app_storage_path)) { + size_t size_of_directory = file_system::DirectorySize(app_storage_path); + if (app_quota < size_of_directory) { + return 0; + } - if (current_app_quota > available_disk_space) { - return available_disk_space; - } else { - return current_app_quota; - } + uint32_t current_app_quota = app_quota - size_of_directory; + uint32_t available_disk_space = + file_system::GetAvailableDiskSpace(app_storage_path); + + if (current_app_quota > available_disk_space) { + return available_disk_space; } else { - return app_quota; + return current_app_quota; } + } else { + return app_quota; } +} - bool ApplicationManagerImpl::IsHMICooperating() const { - return hmi_cooperating_; - } +bool ApplicationManagerImpl::IsHMICooperating() const { + return hmi_cooperating_; +} - void ApplicationManagerImpl::OnApplicationListUpdateTimer() { - LOG4CXX_DEBUG(logger_, "Application list update timer finished"); - SendUpdateAppList(); - GetPolicyHandler().OnAppsSearchCompleted(); - } - - void ApplicationManagerImpl::OnTimerSendTTSGlobalProperties() { - std::vector<uint32_t> app_list; - { - sync_primitives::AutoLock lock(tts_global_properties_app_list_lock_); - std::map<uint32_t, TimevalStruct>::iterator it = - tts_global_properties_app_list_.begin(); - std::map<uint32_t, TimevalStruct>::iterator it_end = - tts_global_properties_app_list_.end(); - date_time::TimeCompare time_comp; - for (; it != it_end; ++it) { - time_comp = date_time::DateTime::compareTime( - date_time::DateTime::getCurrentTime(), it->second); - if (date_time::GREATER == time_comp || date_time::EQUAL == time_comp) { - app_list.push_back(it->first); - } - } - } - if (!app_list.empty()) { - for (uint32_t i = 0; i < app_list.size(); ++i) { - LOG4CXX_INFO( - logger_, - "Send TTS GlobalProperties to HMI with default helpPrompt"); - MessageHelper::SendTTSGlobalProperties( - application(app_list[i]), true, *this); - RemoveAppFromTTSGlobalPropertiesList(app_list[i]); +void ApplicationManagerImpl::OnApplicationListUpdateTimer() { + LOG4CXX_DEBUG(logger_, "Application list update timer finished"); + SendUpdateAppList(); + GetPolicyHandler().OnAppsSearchCompleted(); +} + +void ApplicationManagerImpl::OnTimerSendTTSGlobalProperties() { + std::vector<uint32_t> app_list; + { + sync_primitives::AutoLock lock(tts_global_properties_app_list_lock_); + std::map<uint32_t, TimevalStruct>::iterator it = + tts_global_properties_app_list_.begin(); + std::map<uint32_t, TimevalStruct>::iterator it_end = + tts_global_properties_app_list_.end(); + date_time::TimeCompare time_comp; + for (; it != it_end; ++it) { + time_comp = date_time::DateTime::compareTime( + date_time::DateTime::getCurrentTime(), it->second); + if (date_time::GREATER == time_comp || date_time::EQUAL == time_comp) { + app_list.push_back(it->first); } } } - - void ApplicationManagerImpl::AddAppToTTSGlobalPropertiesList( - const uint32_t app_id) { - LOG4CXX_AUTO_TRACE(logger_); - uint16_t timeout = get_settings().tts_global_properties_timeout(); - TimevalStruct current_time = date_time::DateTime::getCurrentTime(); - current_time.tv_sec += timeout; - // please avoid AutoLock usage to avoid deadlock - tts_global_properties_app_list_lock_.Acquire(); - if (tts_global_properties_app_list_.end() == - tts_global_properties_app_list_.find(app_id)) { - tts_global_properties_app_list_[app_id] = current_time; + if (!app_list.empty()) { + for (uint32_t i = 0; i < app_list.size(); ++i) { + LOG4CXX_INFO(logger_, + "Send TTS GlobalProperties to HMI with default helpPrompt"); + MessageHelper::SendTTSGlobalProperties( + application(app_list[i]), true, *this); + RemoveAppFromTTSGlobalPropertiesList(app_list[i]); } - // if add first item need to start timer on one second - if (1 == tts_global_properties_app_list_.size()) { - LOG4CXX_INFO(logger_, "Start tts_global_properties_timer_"); - tts_global_properties_app_list_lock_.Release(); - const uint32_t timeout_ms = 1000; - tts_global_properties_timer_.Start(timeout_ms, false); - return; - } - tts_global_properties_app_list_lock_.Release(); } +} - void ApplicationManagerImpl::RemoveAppFromTTSGlobalPropertiesList( - const uint32_t app_id) { - LOG4CXX_AUTO_TRACE(logger_); - // please avoid AutoLock usage to avoid deadlock - tts_global_properties_app_list_lock_.Acquire(); - std::map<uint32_t, TimevalStruct>::iterator it = - tts_global_properties_app_list_.find(app_id); - if (tts_global_properties_app_list_.end() != it) { - tts_global_properties_app_list_.erase(it); - if (tts_global_properties_app_list_.empty()) { - LOG4CXX_DEBUG(logger_, "Stop tts_global_properties_timer_"); - // if container is empty need to stop timer - tts_global_properties_app_list_lock_.Release(); - tts_global_properties_timer_.Stop(); - return; - } - } +void ApplicationManagerImpl::AddAppToTTSGlobalPropertiesList( + const uint32_t app_id) { + LOG4CXX_AUTO_TRACE(logger_); + uint16_t timeout = get_settings().tts_global_properties_timeout(); + TimevalStruct current_time = date_time::DateTime::getCurrentTime(); + current_time.tv_sec += timeout; + // please avoid AutoLock usage to avoid deadlock + tts_global_properties_app_list_lock_.Acquire(); + if (tts_global_properties_app_list_.end() == + tts_global_properties_app_list_.find(app_id)) { + tts_global_properties_app_list_[app_id] = current_time; + } + // if add first item need to start timer on one second + if (1 == tts_global_properties_app_list_.size()) { + LOG4CXX_INFO(logger_, "Start tts_global_properties_timer_"); tts_global_properties_app_list_lock_.Release(); + const uint32_t timeout_ms = 1000; + tts_global_properties_timer_.Start(timeout_ms, false); + return; } + tts_global_properties_app_list_lock_.Release(); +} - mobile_apis::AppHMIType::eType ApplicationManagerImpl::StringToAppHMIType( - std::string str) { - LOG4CXX_AUTO_TRACE(logger_); - if ("DEFAULT" == str) { - return mobile_apis::AppHMIType::DEFAULT; - } else if ("COMMUNICATION" == str) { - return mobile_apis::AppHMIType::COMMUNICATION; - } else if ("MEDIA" == str) { - return mobile_apis::AppHMIType::MEDIA; - } else if ("MESSAGING" == str) { - return mobile_apis::AppHMIType::MESSAGING; - } else if ("NAVIGATION" == str) { - return mobile_apis::AppHMIType::NAVIGATION; - } else if ("INFORMATION" == str) { - return mobile_apis::AppHMIType::INFORMATION; - } else if ("SOCIAL" == str) { - return mobile_apis::AppHMIType::SOCIAL; - } else if ("BACKGROUND_PROCESS" == str) { - return mobile_apis::AppHMIType::BACKGROUND_PROCESS; - } else if ("TESTING" == str) { - return mobile_apis::AppHMIType::TESTING; - } else if ("SYSTEM" == str) { - return mobile_apis::AppHMIType::SYSTEM; - } else { - return mobile_apis::AppHMIType::INVALID_ENUM; +void ApplicationManagerImpl::RemoveAppFromTTSGlobalPropertiesList( + const uint32_t app_id) { + LOG4CXX_AUTO_TRACE(logger_); + // please avoid AutoLock usage to avoid deadlock + tts_global_properties_app_list_lock_.Acquire(); + std::map<uint32_t, TimevalStruct>::iterator it = + tts_global_properties_app_list_.find(app_id); + if (tts_global_properties_app_list_.end() != it) { + tts_global_properties_app_list_.erase(it); + if (tts_global_properties_app_list_.empty()) { + LOG4CXX_DEBUG(logger_, "Stop tts_global_properties_timer_"); + // if container is empty need to stop timer + tts_global_properties_app_list_lock_.Release(); + tts_global_properties_timer_.Stop(); + return; } } + tts_global_properties_app_list_lock_.Release(); +} - bool ApplicationManagerImpl::CompareAppHMIType( - const smart_objects::SmartObject& from_policy, - const smart_objects::SmartObject& from_application) { - LOG4CXX_AUTO_TRACE(logger_); - bool equal = false; - uint32_t lenght_policy_app_types = from_policy.length(); - uint32_t lenght_application_app_types = from_application.length(); +mobile_apis::AppHMIType::eType ApplicationManagerImpl::StringToAppHMIType( + std::string str) { + LOG4CXX_AUTO_TRACE(logger_); + if ("DEFAULT" == str) { + return mobile_apis::AppHMIType::DEFAULT; + } else if ("COMMUNICATION" == str) { + return mobile_apis::AppHMIType::COMMUNICATION; + } else if ("MEDIA" == str) { + return mobile_apis::AppHMIType::MEDIA; + } else if ("MESSAGING" == str) { + return mobile_apis::AppHMIType::MESSAGING; + } else if ("NAVIGATION" == str) { + return mobile_apis::AppHMIType::NAVIGATION; + } else if ("INFORMATION" == str) { + return mobile_apis::AppHMIType::INFORMATION; + } else if ("SOCIAL" == str) { + return mobile_apis::AppHMIType::SOCIAL; + } else if ("BACKGROUND_PROCESS" == str) { + return mobile_apis::AppHMIType::BACKGROUND_PROCESS; + } else if ("TESTING" == str) { + return mobile_apis::AppHMIType::TESTING; + } else if ("SYSTEM" == str) { + return mobile_apis::AppHMIType::SYSTEM; + } else { + return mobile_apis::AppHMIType::INVALID_ENUM; + } +} - for (uint32_t i = 0; i < lenght_application_app_types; ++i) { - for (uint32_t k = 0; k < lenght_policy_app_types; ++k) { - if (from_application[i] == from_policy[k]) { - equal = true; - break; - } - } - if (!equal) { - return false; +bool ApplicationManagerImpl::CompareAppHMIType( + const smart_objects::SmartObject& from_policy, + const smart_objects::SmartObject& from_application) { + LOG4CXX_AUTO_TRACE(logger_); + bool equal = false; + uint32_t lenght_policy_app_types = from_policy.length(); + uint32_t lenght_application_app_types = from_application.length(); + + for (uint32_t i = 0; i < lenght_application_app_types; ++i) { + for (uint32_t k = 0; k < lenght_policy_app_types; ++k) { + if (from_application[i] == from_policy[k]) { + equal = true; + break; } - equal = false; } - return true; + if (!equal) { + return false; + } + equal = false; } + return true; +} - void ApplicationManagerImpl::OnUpdateHMIAppType( - std::map<std::string, std::vector<std::string>> app_hmi_types) { - LOG4CXX_AUTO_TRACE(logger_); +void ApplicationManagerImpl::OnUpdateHMIAppType( + std::map<std::string, std::vector<std::string> > app_hmi_types) { + LOG4CXX_AUTO_TRACE(logger_); - std::map<std::string, std::vector<std::string>>::iterator - it_app_hmi_types_from_policy; - std::vector<std::string> hmi_types_from_policy; - smart_objects::SmartObject transform_app_hmi_types( - smart_objects::SmartType_Array); - bool flag_diffirence_app_hmi_type = false; - DataAccessor<ApplicationSet> accessor(applications()); - for (ApplicationSetIt it = accessor.GetData().begin(); - it != accessor.GetData().end(); - ++it) { - it_app_hmi_types_from_policy = - app_hmi_types.find(((*it)->policy_app_id())); - - if (it_app_hmi_types_from_policy != app_hmi_types.end() && - ((it_app_hmi_types_from_policy->second).size())) { - flag_diffirence_app_hmi_type = false; - hmi_types_from_policy = (it_app_hmi_types_from_policy->second); - - if (transform_app_hmi_types.length()) { - transform_app_hmi_types = - smart_objects::SmartObject(smart_objects::SmartType_Array); - } + std::map<std::string, std::vector<std::string> >::iterator + it_app_hmi_types_from_policy; + std::vector<std::string> hmi_types_from_policy; + smart_objects::SmartObject transform_app_hmi_types( + smart_objects::SmartType_Array); + bool flag_diffirence_app_hmi_type = false; + DataAccessor<ApplicationSet> accessor(applications()); + for (ApplicationSetIt it = accessor.GetData().begin(); + it != accessor.GetData().end(); + ++it) { + it_app_hmi_types_from_policy = app_hmi_types.find(((*it)->policy_app_id())); + + if (it_app_hmi_types_from_policy != app_hmi_types.end() && + ((it_app_hmi_types_from_policy->second).size())) { + flag_diffirence_app_hmi_type = false; + hmi_types_from_policy = (it_app_hmi_types_from_policy->second); + + if (transform_app_hmi_types.length()) { + transform_app_hmi_types = + smart_objects::SmartObject(smart_objects::SmartType_Array); + } - for (uint32_t i = 0; i < hmi_types_from_policy.size(); ++i) { - transform_app_hmi_types[i] = - StringToAppHMIType(hmi_types_from_policy[i]); - } + for (uint32_t i = 0; i < hmi_types_from_policy.size(); ++i) { + transform_app_hmi_types[i] = + StringToAppHMIType(hmi_types_from_policy[i]); + } - ApplicationConstSharedPtr app = *it; - const smart_objects::SmartObject* save_application_hmi_type = - app->app_types(); - - if (save_application_hmi_type == NULL || - ((*save_application_hmi_type).length() != - transform_app_hmi_types.length())) { - flag_diffirence_app_hmi_type = true; - } else { - flag_diffirence_app_hmi_type = !(CompareAppHMIType( - transform_app_hmi_types, *save_application_hmi_type)); - } + ApplicationConstSharedPtr app = *it; + const smart_objects::SmartObject* save_application_hmi_type = + app->app_types(); - if (flag_diffirence_app_hmi_type) { - (*it)->set_app_types(transform_app_hmi_types); - (*it)->ChangeSupportingAppHMIType(); - if ((*it)->hmi_level() == mobile_api::HMILevel::HMI_BACKGROUND) { - MessageHelper::SendUIChangeRegistrationRequestToHMI(*it, *this); - } else if (((*it)->hmi_level() == mobile_api::HMILevel::HMI_FULL) || - ((*it)->hmi_level() == - mobile_api::HMILevel::HMI_LIMITED)) { - MessageHelper::SendUIChangeRegistrationRequestToHMI(*it, *this); - state_controller().SetRegularState( - *it, mobile_apis::HMILevel::HMI_BACKGROUND, true); - } + if (save_application_hmi_type == NULL || + ((*save_application_hmi_type).length() != + transform_app_hmi_types.length())) { + flag_diffirence_app_hmi_type = true; + } else { + flag_diffirence_app_hmi_type = !(CompareAppHMIType( + transform_app_hmi_types, *save_application_hmi_type)); + } + + if (flag_diffirence_app_hmi_type) { + (*it)->set_app_types(transform_app_hmi_types); + (*it)->ChangeSupportingAppHMIType(); + if ((*it)->hmi_level() == mobile_api::HMILevel::HMI_BACKGROUND) { + MessageHelper::SendUIChangeRegistrationRequestToHMI(*it, *this); + } else if (((*it)->hmi_level() == mobile_api::HMILevel::HMI_FULL) || + ((*it)->hmi_level() == mobile_api::HMILevel::HMI_LIMITED)) { + MessageHelper::SendUIChangeRegistrationRequestToHMI(*it, *this); + state_controller().SetRegularState( + *it, mobile_apis::HMILevel::HMI_BACKGROUND, true); } } } } +} - ProtocolVersion ApplicationManagerImpl::SupportedSDLVersion() const { - LOG4CXX_AUTO_TRACE(logger_); - bool heart_beat_support = get_settings().heart_beat_timeout(); - bool sdl4_support = protocol_handler_->get_settings().enable_protocol_4(); +ProtocolVersion ApplicationManagerImpl::SupportedSDLVersion() const { + LOG4CXX_AUTO_TRACE(logger_); + bool heart_beat_support = get_settings().heart_beat_timeout(); + bool sdl4_support = protocol_handler_->get_settings().enable_protocol_4(); - if (sdl4_support) { - LOG4CXX_DEBUG(logger_, - "SDL Supported protocol version " << ProtocolVersion::kV4); - return ProtocolVersion::kV4; - } - if (heart_beat_support) { - LOG4CXX_DEBUG(logger_, - "SDL Supported protocol version " << ProtocolVersion::kV3); - return ProtocolVersion::kV3; - } + if (sdl4_support) { LOG4CXX_DEBUG(logger_, - "SDL Supported protocol version " << ProtocolVersion::kV2); - return ProtocolVersion::kV2; + "SDL Supported protocol version " << ProtocolVersion::kV4); + return ProtocolVersion::kV4; } - - event_engine::EventDispatcher& ApplicationManagerImpl::event_dispatcher() { - return event_dispatcher_; - } - - const std::string ApplicationManagerImpl::DirectoryTypeToString( - ApplicationManagerImpl::DirectoryType type) const { - DirectoryTypeMap::const_iterator it = dir_type_to_string_map_.find(type); - if (it != dir_type_to_string_map_.end()) { - return it->second; - } - return "Unknown"; + if (heart_beat_support) { + LOG4CXX_DEBUG(logger_, + "SDL Supported protocol version " << ProtocolVersion::kV3); + return ProtocolVersion::kV3; } + LOG4CXX_DEBUG(logger_, + "SDL Supported protocol version " << ProtocolVersion::kV2); + return ProtocolVersion::kV2; +} - bool ApplicationManagerImpl::InitDirectory( - const std::string& path, - ApplicationManagerImpl::DirectoryType type) const { - const std::string directory_type = DirectoryTypeToString(type); - if (!file_system::DirectoryExists(path)) { - LOG4CXX_WARN(logger_, directory_type << " directory doesn't exist."); - // if storage directory doesn't exist try to create it - if (!file_system::CreateDirectoryRecursively(path)) { - LOG4CXX_ERROR(logger_, - "Unable to create " << directory_type << " directory " - << path); - return false; - } - LOG4CXX_DEBUG(logger_, - directory_type << " directory has been created: " << path); - } +event_engine::EventDispatcher& ApplicationManagerImpl::event_dispatcher() { + return event_dispatcher_; +} - return true; +const std::string ApplicationManagerImpl::DirectoryTypeToString( + ApplicationManagerImpl::DirectoryType type) const { + DirectoryTypeMap::const_iterator it = dir_type_to_string_map_.find(type); + if (it != dir_type_to_string_map_.end()) { + return it->second; } + return "Unknown"; +} - bool ApplicationManagerImpl::IsReadWriteAllowed(const std::string& path, - DirectoryType type) const { - const std::string directory_type = DirectoryTypeToString(type); - if (!(file_system::IsWritingAllowed(path) && - file_system::IsReadingAllowed(path))) { +bool ApplicationManagerImpl::InitDirectory( + const std::string& path, ApplicationManagerImpl::DirectoryType type) const { + const std::string directory_type = DirectoryTypeToString(type); + if (!file_system::DirectoryExists(path)) { + LOG4CXX_WARN(logger_, directory_type << " directory doesn't exist."); + // if storage directory doesn't exist try to create it + if (!file_system::CreateDirectoryRecursively(path)) { LOG4CXX_ERROR(logger_, - directory_type - << " directory doesn't have read/write permissions."); + "Unable to create " << directory_type << " directory " + << path); return false; } - LOG4CXX_DEBUG(logger_, - directory_type << " directory has read/write permissions."); - - return true; + directory_type << " directory has been created: " << path); } - void ApplicationManagerImpl::ClearTTSGlobalPropertiesList() { - LOG4CXX_AUTO_TRACE(logger_); - sync_primitives::AutoLock lock(tts_global_properties_app_list_lock_); - tts_global_properties_app_list_.clear(); - } + return true; +} - bool ApplicationManagerImpl::IsAppSubscribedForWayPoints( - const uint32_t app_id) const { - LOG4CXX_AUTO_TRACE(logger_); - sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); - if (subscribed_way_points_apps_list_.find(app_id) == - subscribed_way_points_apps_list_.end()) { - return false; - } - return true; +bool ApplicationManagerImpl::IsReadWriteAllowed(const std::string& path, + DirectoryType type) const { + const std::string directory_type = DirectoryTypeToString(type); + if (!(file_system::IsWritingAllowed(path) && + file_system::IsReadingAllowed(path))) { + LOG4CXX_ERROR(logger_, + directory_type + << " directory doesn't have read/write permissions."); + return false; } - void ApplicationManagerImpl::SubscribeAppForWayPoints(const uint32_t app_id) { - LOG4CXX_AUTO_TRACE(logger_); - sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); - subscribed_way_points_apps_list_.insert(app_id); - } + LOG4CXX_DEBUG(logger_, + directory_type << " directory has read/write permissions."); - void ApplicationManagerImpl::UnsubscribeAppFromWayPoints( - const uint32_t app_id) { - LOG4CXX_AUTO_TRACE(logger_); - sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); - subscribed_way_points_apps_list_.erase(app_id); - } + return true; +} - bool ApplicationManagerImpl::IsAnyAppSubscribedForWayPoints() const { - LOG4CXX_AUTO_TRACE(logger_); - sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); - return !subscribed_way_points_apps_list_.empty(); - } +void ApplicationManagerImpl::ClearTTSGlobalPropertiesList() { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(tts_global_properties_app_list_lock_); + tts_global_properties_app_list_.clear(); +} - const std::set<int32_t> - ApplicationManagerImpl::GetAppsSubscribedForWayPoints() const { - LOG4CXX_AUTO_TRACE(logger_); - sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); - return subscribed_way_points_apps_list_; +bool ApplicationManagerImpl::IsAppSubscribedForWayPoints( + const uint32_t app_id) const { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); + if (subscribed_way_points_apps_list_.find(app_id) == + subscribed_way_points_apps_list_.end()) { + return false; } + return true; +} + +void ApplicationManagerImpl::SubscribeAppForWayPoints(const uint32_t app_id) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); + subscribed_way_points_apps_list_.insert(app_id); +} + +void ApplicationManagerImpl::UnsubscribeAppFromWayPoints( + const uint32_t app_id) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); + subscribed_way_points_apps_list_.erase(app_id); +} + +bool ApplicationManagerImpl::IsAnyAppSubscribedForWayPoints() const { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); + return !subscribed_way_points_apps_list_.empty(); +} + +const std::set<int32_t> ApplicationManagerImpl::GetAppsSubscribedForWayPoints() + const { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); + return subscribed_way_points_apps_list_; +} - } // namespace application_manager +} // namespace application_manager diff --git a/src/components/application_manager/src/state_controller_impl.cc b/src/components/application_manager/src/state_controller_impl.cc index fbdc9d7f6b..839cc13026 100644 --- a/src/components/application_manager/src/state_controller_impl.cc +++ b/src/components/application_manager/src/state_controller_impl.cc @@ -656,27 +656,10 @@ void StateControllerImpl::on_event(const event_engine::Event& event) { } } break; - } break; - } - case FunctionID::VR_Started: { - OnVRStarted(); - break; - } - case FunctionID::VR_Stopped: { - OnVREnded(); - break; - } - case FunctionID::TTS_Started: { - OnTTSStarted(); - break; - } - case FunctionID::TTS_Stopped: { - OnTTSStopped(); - break; + } + default: + break; } - default: - break; -} } void StateControllerImpl::OnStateChanged(ApplicationSharedPtr app, diff --git a/src/components/application_manager/test/include/application_manager/policy_handler_interface_mock.h b/src/components/application_manager/test/include/application_manager/policy_handler_interface_mock.h index bc4a960a34..51a0678b24 100644 --- a/src/components/application_manager/test/include/application_manager/policy_handler_interface_mock.h +++ b/src/components/application_manager/test/include/application_manager/policy_handler_interface_mock.h @@ -93,7 +93,7 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { MOCK_METHOD2(GetUpdateUrls, void(int service_type, policy::EndpointUrls& end_points)); MOCK_METHOD0(ResetRetrySequence, void()); - MOCK_METHOD0(NextRetryTimeout, int()); + MOCK_METHOD0(NextRetryTimeout, uint32_t()); MOCK_METHOD0(TimeoutExchange, int()); MOCK_METHOD0(OnExceededTimeout, void()); MOCK_METHOD0(OnSystemReady, void()); diff --git a/src/components/include/application_manager/policies/policy_handler_interface.h b/src/components/include/application_manager/policies/policy_handler_interface.h index ef3044c0ba..3cd3315686 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -89,7 +89,7 @@ class PolicyHandlerInterface { virtual void GetServiceUrls(const std::string& service_type, EndpointUrls& end_points) = 0; virtual void ResetRetrySequence() = 0; - virtual int NextRetryTimeout() = 0; + virtual uint32_t NextRetryTimeout() = 0; virtual int TimeoutExchange() = 0; virtual void OnExceededTimeout() = 0; virtual void OnSystemReady() = 0; diff --git a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h index 83026674af..726eefd3d4 100644 --- a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h +++ b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h @@ -95,7 +95,7 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { MOCK_METHOD2(GetUpdateUrls, void(int service_type, policy::EndpointUrls& end_points)); MOCK_METHOD0(ResetRetrySequence, void()); - MOCK_METHOD0(NextRetryTimeout, int()); + MOCK_METHOD0(NextRetryTimeout, uint32_t()); MOCK_METHOD0(TimeoutExchange, int()); MOCK_METHOD0(OnExceededTimeout, void()); MOCK_METHOD0(OnSystemReady, void()); diff --git a/src/components/policy/src/policy_manager_impl.cc b/src/components/policy/src/policy_manager_impl.cc index b63732dd86..b9db9b3ae8 100644 --- a/src/components/policy/src/policy_manager_impl.cc +++ b/src/components/policy/src/policy_manager_impl.cc @@ -61,10 +61,6 @@ namespace { const uint32_t kDefaultRetryTimeoutInSec = 60u; } // namespace -namespace { -const uint32_t kDefaultRetryTimeoutInSec = 60u; -} // namespace - namespace policy { CREATE_LOGGERPTR_GLOBAL(logger_, "Policy") @@ -889,12 +885,6 @@ bool PolicyManagerImpl::CanAppStealFocus(const std::string& app_id) const { void PolicyManagerImpl::MarkUnpairedDevice(const std::string& device_id) {} -void PolicyManagerImpl::OnAppRegisteredOnMobile( - const std::string& application_id) { - SendNotificationOnPermissionsUpdated(application_id); - StartPTExchange(); -} - std::string PolicyManagerImpl::RetrieveCertificate() const { LOG4CXX_AUTO_TRACE(logger_); return cache_->GetCertificate(); |