diff options
Diffstat (limited to 'src/components/application_manager/src/message_helper.cc')
-rw-r--r-- | src/components/application_manager/src/message_helper.cc | 1137 |
1 files changed, 700 insertions, 437 deletions
diff --git a/src/components/application_manager/src/message_helper.cc b/src/components/application_manager/src/message_helper.cc index ffde928db..ee41ce5bf 100644 --- a/src/components/application_manager/src/message_helper.cc +++ b/src/components/application_manager/src/message_helper.cc @@ -1,4 +1,4 @@ -/* +/* Copyright (c) 2013, Ford Motor Company All rights reserved. @@ -30,6 +30,8 @@ POSSIBILITY OF SUCH DAMAGE. */ +#include "application_manager/message_helper.h" + #define __STDC_FORMAT_MACROS #include <inttypes.h> #undef __STDC_FORMAT_MACROS @@ -43,7 +45,6 @@ #include "application_manager/application.h" #include "application_manager/application_manager_impl.h" #include "application_manager/commands/command_impl.h" -#include "application_manager/message_helper.h" #include "application_manager/policies/policy_handler.h" #include "config_profile/profile.h" #include "connection_handler/connection_handler_impl.h" @@ -51,7 +52,13 @@ #include "smart_objects/enum_schema_item.h" #include "utils/file_system.h" #include "utils/macro.h" +#include "utils/make_shared.h" #include "utils/logger.h" +#include "utils/make_shared.h" + +#include "formatters/formatter_json_rpc.h" +#include "formatters/CFormatterJsonSDLRPCv2.hpp" +#include "formatters/CFormatterJsonSDLRPCv1.hpp" namespace application_manager { @@ -59,24 +66,6 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "ApplicationManager") namespace { -hmi_apis::Common_Language::eType ToCommonLanguage( - mobile_apis::Language::eType mobile_language) { - // Update this check if mobile_api::Language - // or hmi_apis::Common_Language changes. - // Or, better, generate functions like this from XML - long lang_val = long(mobile_language); - long max_common_lang_val = long(hmi_apis::Common_Language::NO_NO); - long max_mobile_lang = long(mobile_apis::Language::NO_NO); - if (max_common_lang_val != max_mobile_lang) { - LOG4CXX_ERROR(logger_, "Mapping between Common_Language and Language" - " has changed! Please update converter function"); - } - if (lang_val > max_common_lang_val) { - LOG4CXX_ERROR(logger_, "Non-convertable language ID"); - } - return hmi_apis::Common_Language::eType(lang_val); -} - typedef std::map<std::string, hmi_apis::Common_AppPriority::eType> CommonAppPriorityMap; @@ -196,58 +185,24 @@ static VehicleInfo_Requests ivi_subrequests[] = { std::string MessageHelper::CommonLanguageToString( hmi_apis::Common_Language::eType language) { - switch (language) { - case hmi_apis::Common_Language::EN_US: - return "en-us"; - case hmi_apis::Common_Language::ES_MX: - return "es-mx"; - case hmi_apis::Common_Language::FR_CA: - return "fr-ca"; - case hmi_apis::Common_Language::DE_DE: - return "de-de"; - case hmi_apis::Common_Language::ES_ES: - return "es-es"; - case hmi_apis::Common_Language::EN_GB: - return "en-gb"; - case hmi_apis::Common_Language::RU_RU: - return "ru-ru"; - case hmi_apis::Common_Language::TR_TR: - return "tr-tr"; - case hmi_apis::Common_Language::PL_PL: - return "pl-pl"; - case hmi_apis::Common_Language::FR_FR: - return "fr-fr"; - case hmi_apis::Common_Language::IT_IT: - return "it-it"; - case hmi_apis::Common_Language::SV_SE: - return "sv-se"; - case hmi_apis::Common_Language::PT_PT: - return "pt-pt"; - case hmi_apis::Common_Language::NL_NL: - return "nl-nl"; - case hmi_apis::Common_Language::EN_AU: - return "en-au"; - case hmi_apis::Common_Language::ZH_CN: - return "zh-cn"; - case hmi_apis::Common_Language::ZH_TW: - return "zh-tw"; - case hmi_apis::Common_Language::JA_JP: - return "ja-jp"; - case hmi_apis::Common_Language::AR_SA: - return "as-sa"; - case hmi_apis::Common_Language::KO_KR: - return "ko-kr"; - case hmi_apis::Common_Language::PT_BR: - return "pt-br"; - case hmi_apis::Common_Language::CS_CZ: - return "cs-cz"; - case hmi_apis::Common_Language::DA_DK: - return "da-dk"; - case hmi_apis::Common_Language::NO_NO: - return "no-no"; - default: - return ""; + using namespace NsSmartDeviceLink::NsSmartObjects; + const char* str = 0; + if (EnumConversionHelper<hmi_apis::Common_Language::eType>::EnumToCString( + language, &str)) { + return str ? str : ""; } + return std::string(); +} + +hmi_apis::Common_Language::eType MessageHelper::CommonLanguageFromString( + const std::string& language) { + using namespace NsSmartDeviceLink::NsSmartObjects; + hmi_apis::Common_Language::eType value; + if (EnumConversionHelper<hmi_apis::Common_Language::eType>::StringToEnum( + language, &value)) { + return value; + } + return hmi_apis::Common_Language::INVALID_ENUM; } uint32_t MessageHelper::GetAppCommandLimit(const std::string& policy_app_id) { @@ -259,7 +214,8 @@ uint32_t MessageHelper::GetAppCommandLimit(const std::string& policy_app_id) { void MessageHelper::SendHMIStatusNotification( const Application& application_impl) { - smart_objects::SmartObject* notification = new smart_objects::SmartObject; + LOG4CXX_AUTO_TRACE(logger_); + smart_objects::SmartObjectSPtr notification = new smart_objects::SmartObject; if (!notification) { // TODO(VS): please add logger. return; @@ -289,108 +245,168 @@ void MessageHelper::SendHMIStatusNotification( void MessageHelper::SendOnAppRegisteredNotificationToHMI( const Application& application_impl, bool resumption, bool need_restore_vr) { - smart_objects::SmartObject* notification = new smart_objects::SmartObject; + using namespace smart_objects; + + SmartObjectSPtr notification = utils::MakeShared<SmartObject>(SmartType_Map); if (!notification) { - // TODO(VS): please add logger. + LOG4CXX_ERROR(logger_, "Failed to create smart object"); return; } - smart_objects::SmartObject& message = *notification; - message[strings::params][strings::function_id] = - static_cast<int32_t>(hmi_apis::FunctionID::BasicCommunication_OnAppRegistered); - - message[strings::params][strings::message_type] = - static_cast<int32_t>(application_manager::MessageType::kNotification); - message[strings::msg_params][strings::application][strings::app_name] = - application_impl.name(); - - const smart_objects::SmartObject* ngn_media_screen_name = application_impl - .ngn_media_screen_name(); + (*notification)[strings::params] = SmartObject(SmartType_Map); + smart_objects::SmartObject& params = (*notification)[strings::params]; + params[strings::function_id] = + static_cast<int32_t>(hmi_apis::FunctionID::BasicCommunication_OnAppRegistered); + params[strings::message_type] = static_cast<int32_t>(kNotification); + params[strings::protocol_version] = commands::CommandImpl::protocol_version_; + params[strings::protocol_type] = commands::CommandImpl::hmi_protocol_type_; + (*notification)[strings::msg_params] = SmartObject(SmartType_Map); + smart_objects::SmartObject& msg_params = (*notification)[strings::msg_params]; // Due to current requirements in case when we're in resumption mode // we have to always send resumeVRGrammar field. if (resumption) { - message[strings::msg_params][strings::resume_vr_grammars] = need_restore_vr; + msg_params[strings::resume_vr_grammars] = need_restore_vr; } - if (ngn_media_screen_name) { - message[strings::msg_params][strings::application][strings::ngn_media_screen_app_name] = - *ngn_media_screen_name; + if (application_impl.vr_synonyms()) { + msg_params[strings::vr_synonyms] = *(application_impl.vr_synonyms()); } - message[strings::msg_params][strings::application][strings::icon] = - application_impl.app_icon_path(); + if (application_impl.tts_name()) { + msg_params[strings::tts_name] = *(application_impl.tts_name()); + } - std::string dev_name = ApplicationManagerImpl::instance()->GetDeviceName( - application_impl.device()); - message[strings::msg_params][strings::application][strings::device_name] = - dev_name; + std::string priority; + policy::PolicyHandler::instance()->GetPriority( + application_impl.mobile_app_id(), &priority); + if (!priority.empty()) { + msg_params[strings::priority] = GetPriorityCode(priority); + } - message[strings::msg_params][strings::application][strings::app_id] = - application_impl.app_id(); + msg_params[strings::msg_params] = SmartObject(SmartType_Map); + smart_objects::SmartObject& application = msg_params[strings::application]; + application[strings::app_name] = application_impl.name(); + application[strings::app_id] = application_impl.app_id(); + application[hmi_response::policy_app_id] = application_impl.mobile_app_id(); + application[strings::icon] = application_impl.app_icon_path(); - message[strings::msg_params][strings::application][strings::hmi_display_language_desired] = - static_cast<int32_t>(application_impl.ui_language()); + const smart_objects::SmartObject* ngn_media_screen_name = + application_impl.ngn_media_screen_name(); + if (ngn_media_screen_name) { + application[strings::ngn_media_screen_app_name] = *ngn_media_screen_name; + } - message[strings::msg_params][strings::application][strings::is_media_application] = - application_impl.is_media_application(); + application[strings::hmi_display_language_desired] = + static_cast<int32_t>(application_impl.ui_language()); + + application[strings::is_media_application] = application_impl.is_media_application(); const smart_objects::SmartObject* app_type = application_impl.app_types(); if (app_type) { - message[strings::msg_params][strings::application][strings::app_type] = - *app_type; - } - if (application_impl.vr_synonyms()) { - message[strings::msg_params][strings::vr_synonyms] = *(application_impl - .vr_synonyms()); + application[strings::app_type] = *app_type; } - if (application_impl.tts_name()) { - message[strings::msg_params][strings::tts_name] = *(application_impl - .tts_name()); + if (application_impl.IsRegistered()) { + std::vector<std::string> request_types = + policy::PolicyHandler::instance()->GetAppRequestTypes( + application_impl.mobile_app_id()); + + application[strings::request_type] = SmartObject(SmartType_Array); + smart_objects::SmartObject& request_array = application[strings::request_type]; + + uint32_t index = 0; + std::vector<std::string>::const_iterator it = request_types.begin(); + for (; request_types.end() != it; ++it) { + request_array[index] = *it; + ++index; + } } - std::string priority; - policy::PolicyHandler::instance()->GetPriority( - application_impl.mobile_app_id()->asString(), &priority); - if (!priority.empty()) { - message[strings::msg_params][strings::priority] = GetPriorityCode(priority); + application[strings::device_info] = SmartObject(SmartType_Map); + smart_objects::SmartObject& device_info = application[strings::device_info]; + std::string device_name; + std::string mac_address; + std::string transport_type; + if (-1 == connection_handler::ConnectionHandlerImpl::instance()-> + GetDataOnDeviceID(application_impl.device(), &device_name, + NULL, &mac_address, &transport_type)) { + LOG4CXX_ERROR(logger_, "Failed to extract information for device " + << application_impl.device()); } + device_info[strings::name] = device_name; + device_info[strings::id] = mac_address; + + const policy::DeviceConsent device_consent = + policy::PolicyHandler::instance()->GetUserConsentForDevice(mac_address); + device_info[strings::isSDLAllowed] = + policy::DeviceConsent::kDeviceAllowed == device_consent; + + device_info[strings::transport_type] = + ApplicationManagerImpl::instance()->GetDeviceTransportType(transport_type); DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(notification)); } -smart_objects::SmartObject* MessageHelper::GetHashUpdateNotification( +smart_objects::SmartObjectSPtr MessageHelper::GetHashUpdateNotification( const uint32_t app_id) { LOG4CXX_INFO(logger_, "GetHashUpdateNotification" << app_id); ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application( app_id); - smart_objects::SmartObject* message = NULL; - if (NULL == app.get()) { - return message; + if (!app) { + return NULL; } - message = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject( + smart_objects::SmartType_Map); (*message)[strings::params][strings::function_id] = - mobile_apis::FunctionID::OnHashChangeID; + mobile_apis::FunctionID::OnHashChangeID; (*message)[strings::params][strings::connection_key] = app_id; (*message)[strings::params][strings::message_type] = - static_cast<int32_t>(kNotification);; + static_cast<int32_t>(kNotification); + + return message; +} + +smart_objects::SmartObject* MessageHelper::GetLockScreenIconUrlNotification(const uint32_t connection_key) { + ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application(connection_key); + DCHECK(app.get()); + + smart_objects::SmartObject* message = new smart_objects::SmartObject(smart_objects::SmartType_Map); + (*message)[strings::params][strings::function_id] = mobile_apis::FunctionID::OnSystemRequestID; + (*message)[strings::params][strings::connection_key] = connection_key; + (*message)[strings::params][strings::message_type] = mobile_apis::messageType::notification; + (*message)[strings::params][strings::protocol_type] = commands::CommandImpl::mobile_protocol_type_; + (*message)[strings::params][strings::protocol_version] = commands::CommandImpl::protocol_version_; + + (*message)[strings::msg_params][strings::request_type] = mobile_apis::RequestType::LOCK_SCREEN_ICON_URL; + + (*message)[strings::msg_params][strings::url] = policy::PolicyHandler::instance()->GetLockScreenIconUrl(); + return message; } +void MessageHelper::SendLockScreenIconUrlNotification(const uint32_t connection_key) { + LOG4CXX_INFO(logger_, "SendLockScreenIconUrlNotification"); + + smart_objects::SmartObject* so = GetLockScreenIconUrlNotification(connection_key); + PrintSmartObject(*so); + DCHECK(ApplicationManagerImpl::instance()->ManageMobileCommand(so)); +} + void MessageHelper::SendHashUpdateNotification(const uint32_t app_id) { - LOG4CXX_INFO(logger_, "SendHashUpdateNotification"); + LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObject* so = GetHashUpdateNotification(app_id); + smart_objects::SmartObjectSPtr so = GetHashUpdateNotification(app_id); if (so) { PrintSmartObject(*so); if (!ApplicationManagerImpl::instance()->ManageMobileCommand(so)) { LOG4CXX_ERROR_EXT(logger_, "Failed to send HashUpdate notification."); + } else { + ApplicationManagerImpl::instance()->resume_controller().ApplicationsDataUpdated(); } } } @@ -398,11 +414,11 @@ void MessageHelper::SendHashUpdateNotification(const uint32_t app_id) { void MessageHelper::SendOnAppInterfaceUnregisteredNotificationToMobile( int32_t connection_key, mobile_api::AppInterfaceUnregisteredReason::eType reason) { - smart_objects::SmartObject* notification = new smart_objects::SmartObject; - if (!notification) { - // TODO(VS): please add logger. - return; - } + + LOG4CXX_AUTO_TRACE(logger_); + + smart_objects::SmartObjectSPtr notification = new smart_objects::SmartObject; + DCHECK(notification); smart_objects::SmartObject& message = *notification; message[strings::params][strings::function_id] = @@ -415,7 +431,12 @@ void MessageHelper::SendOnAppInterfaceUnregisteredNotificationToMobile( message[strings::msg_params][strings::reason] = static_cast<int32_t>(reason); - DCHECK(ApplicationManagerImpl::instance()->ManageMobileCommand(notification)); + if (ApplicationManagerImpl::instance()->ManageMobileCommand(notification)) { + LOG4CXX_DEBUG(logger_, "Mobile command sent"); + } + else { + LOG4CXX_WARN(logger_, "Cannot send mobile command"); + } } const VehicleData& MessageHelper::vehicle_data() { @@ -446,6 +467,7 @@ std::string MessageHelper::StringifiedHMILevel( std::string MessageHelper::StringifiedFunctionID( mobile_apis::FunctionID::eType function_id) { + LOG4CXX_AUTO_TRACE(logger_); using namespace NsSmartDeviceLink::NsSmartObjects; const char* str = 0; if (EnumConversionHelper<mobile_apis::FunctionID::eType>::EnumToCString( @@ -494,11 +516,13 @@ static std::map<std::string, uint16_t> vehicle_data_args = create_get_vehicle_da } #endif -void MessageHelper::CreateGetVehicleDataRequest(uint32_t correlation_id, const std::vector<std::string>& params) { +void MessageHelper::CreateGetVehicleDataRequest( + uint32_t correlation_id, const std::vector<std::string>& params) { + LOG4CXX_AUTO_TRACE(logger_); #ifdef HMI_DBUS_API for (std::vector<std::string>::const_iterator it = params.begin(); it != params.end(); it++) { - smart_objects::SmartObject* request = new smart_objects::SmartObject; + smart_objects::SmartObjectSPtr request = new smart_objects::SmartObject; (*request)[strings::params][strings::message_type] = static_cast<int>(kRequest); (*request)[strings::params][strings::correlation_id] = correlation_id; @@ -511,7 +535,7 @@ void MessageHelper::CreateGetVehicleDataRequest(uint32_t correlation_id, const s ApplicationManagerImpl::instance()->ManageHMICommand(request); } #else - smart_objects::SmartObject* request = new smart_objects::SmartObject; + smart_objects::SmartObjectSPtr request = new smart_objects::SmartObject; (*request)[strings::params][strings::message_type] = static_cast<int>(kRequest); (*request)[strings::params][strings::function_id] = @@ -530,14 +554,12 @@ void MessageHelper::CreateGetVehicleDataRequest(uint32_t correlation_id, const s #endif } -smart_objects::SmartObject* MessageHelper::CreateBlockedByPoliciesResponse( - mobile_apis::FunctionID::eType function_id, - mobile_apis::Result::eType result, uint32_t correlation_id, - uint32_t connection_key) { - smart_objects::SmartObject* response = new smart_objects::SmartObject; - if (!response) { - return NULL; - } +smart_objects::SmartObjectSPtr MessageHelper::CreateBlockedByPoliciesResponse( + mobile_apis::FunctionID::eType function_id, + mobile_apis::Result::eType result, uint32_t correlation_id, + uint32_t connection_key) { + LOG4CXX_AUTO_TRACE(logger_); + smart_objects::SmartObjectSPtr response = new smart_objects::SmartObject; (*response)[strings::params][strings::function_id] = static_cast<int>(function_id); @@ -555,14 +577,11 @@ smart_objects::SmartObject* MessageHelper::CreateBlockedByPoliciesResponse( return response; } -smart_objects::SmartObject* MessageHelper::CreateDeviceListSO( +smart_objects::SmartObjectSPtr MessageHelper::CreateDeviceListSO( const connection_handler::DeviceMap& devices) { - smart_objects::SmartObject* device_list_so = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - - if (NULL == device_list_so) { - return NULL; - } + LOG4CXX_AUTO_TRACE(logger_); + smart_objects::SmartObjectSPtr device_list_so = + new smart_objects::SmartObject(smart_objects::SmartType_Map); (*device_list_so)[strings::device_list] = smart_objects::SmartObject( smart_objects::SmartType_Array); @@ -574,21 +593,24 @@ smart_objects::SmartObject* MessageHelper::CreateDeviceListSO( const connection_handler::Device& d = static_cast<connection_handler::Device>(it->second); list_so[index][strings::name] = d.user_friendly_name(); - list_so[index][strings::id] = it->second.device_handle(); + list_so[index][strings::id] = it->second.mac_address(); const policy::DeviceConsent device_consent = policy::PolicyHandler::instance()->GetUserConsentForDevice(it->second.mac_address()); list_so[index][strings::isSDLAllowed] = policy::DeviceConsent::kDeviceAllowed == device_consent; + list_so[index][strings::transport_type] = + ApplicationManagerImpl::instance()->GetDeviceTransportType(d.connection_type()); + ++index; } - ++index; return device_list_so; } -smart_objects::SmartObject* MessageHelper::CreateModuleInfoSO( - uint32_t function_id) { - smart_objects::SmartObject* module_info = new smart_objects::SmartObject( - smart_objects::SmartType_Map); +smart_objects::SmartObjectSPtr MessageHelper::CreateModuleInfoSO( + uint32_t function_id) { + LOG4CXX_AUTO_TRACE(logger_); + smart_objects::SmartObjectSPtr module_info = new smart_objects::SmartObject( + smart_objects::SmartType_Map); smart_objects::SmartObject& object = *module_info; object[strings::params][strings::message_type] = static_cast<int>(kRequest); object[strings::params][strings::function_id] = static_cast<int>(function_id); @@ -599,10 +621,11 @@ smart_objects::SmartObject* MessageHelper::CreateModuleInfoSO( return module_info; } -smart_objects::SmartObject* MessageHelper::CreateSetAppIcon( +smart_objects::SmartObjectSPtr MessageHelper::CreateSetAppIcon( const std::string& path_to_icon, uint32_t app_id) { - smart_objects::SmartObject* set_icon = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + LOG4CXX_AUTO_TRACE(logger_); + smart_objects::SmartObjectSPtr set_icon = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!set_icon) { return NULL; @@ -619,34 +642,40 @@ smart_objects::SmartObject* MessageHelper::CreateSetAppIcon( } bool MessageHelper::SendIVISubscribtions(const uint32_t app_id) { - LOG4CXX_INFO(logger_, " MessageHelper::SendIVISubscribtions "); + LOG4CXX_AUTO_TRACE(logger_); - bool succes = true; + bool result = true; ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application( app_id); - DCHECK(app.get()); - SmartObjectList requests = GetIVISubscribtionRequests(app_id); - for (SmartObjectList::const_iterator it = requests.begin(); + if (!app.valid()) { + LOG4CXX_ERROR(logger_, "Invalid application " << app_id); + return result; + } + + smart_objects::SmartObjectList requests = GetIVISubscriptionRequests(app); + for (smart_objects::SmartObjectList::const_iterator it = requests.begin(); it != requests.end(); ++it) { if (!ApplicationManagerImpl::instance()->ManageHMICommand(*it)) { - succes = false; + result = false; } } - return succes; + return result; } -MessageHelper::SmartObjectList MessageHelper::GetIVISubscribtionRequests( - const uint32_t app_id) { - LOG4CXX_INFO(logger_, " MessageHelper::GetIVISubscribtionRequests "); +smart_objects::SmartObjectList MessageHelper::GetIVISubscriptionRequests( + ApplicationSharedPtr app) { + LOG4CXX_AUTO_TRACE(logger_); - ApplicationSharedPtr app = ApplicationManagerImpl::instance()->application( - app_id); - DCHECK(app); + smart_objects::SmartObjectList hmi_requests; + if (!app.valid()) { + LOG4CXX_ERROR(logger_, "Invalid application pointer "); + return hmi_requests; + } smart_objects::SmartObject msg_params = smart_objects::SmartObject( smart_objects::SmartType_Map); - msg_params[strings::app_id] = app_id; + msg_params[strings::app_id] = app->app_id(); const VehicleData& vehicle_data = MessageHelper::vehicle_data_; VehicleData::const_iterator ivi_it = vehicle_data.begin(); const std::set<uint32_t>& subscribes = app->SubscribesIVI(); @@ -659,10 +688,9 @@ MessageHelper::SmartObjectList MessageHelper::GetIVISubscribtionRequests( } } - SmartObjectList hmi_requests; #ifdef HMI_JSON_API - smart_objects::SmartObject* request = MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData); + smart_objects::SmartObjectSPtr request = MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData); (*request)[strings::msg_params] = msg_params; hmi_requests.push_back(request); #endif // #ifdef HMI_JSON_API @@ -672,7 +700,7 @@ MessageHelper::SmartObjectList MessageHelper::GetIVISubscribtionRequests( const VehicleInfo_Requests& sr = ivi_subrequests[i]; if (true == msg_params.keyExists(sr.str) && true == msg_params[sr.str].asBool()) { - smart_objects::SmartObject* request = MessageHelper::CreateModuleInfoSO( + smart_objects::SmartObjectSPtr request = MessageHelper::CreateModuleInfoSO( sr.func_id); (*request)[strings::msg_params] = msg_params; hmi_requests.push_back(request); @@ -682,13 +710,65 @@ MessageHelper::SmartObjectList MessageHelper::GetIVISubscribtionRequests( return hmi_requests; } -void MessageHelper::SendAppDataToHMI(ApplicationConstSharedPtr app) { - uint32_t id = app->app_id(); +void MessageHelper::SendOnButtonSubscriptionNotification( + uint32_t app_id, hmi_apis::Common_ButtonName::eType button, bool is_subscribed) { + using namespace smart_objects; + using namespace hmi_apis; + LOG4CXX_AUTO_TRACE(logger_); + + SmartObjectSPtr notification_ptr = utils::MakeShared<SmartObject>(SmartType_Map); + if (!notification_ptr) { + LOG4CXX_ERROR(logger_, "Memory allocation failed."); + return; + } + SmartObject& notification = *notification_ptr; + + SmartObject msg_params = SmartObject(SmartType_Map); + msg_params[strings::app_id] = app_id; + msg_params[strings::name] = button; + msg_params[strings::is_suscribed] = is_subscribed; + + notification[strings::params][strings::message_type] = + static_cast<int32_t>(application_manager::MessageType::kNotification); + notification[strings::params][strings::protocol_version] = + commands::CommandImpl::protocol_version_; + notification[strings::params][strings::protocol_type] = + commands::CommandImpl::hmi_protocol_type_; + notification[strings::params][strings::function_id] = + hmi_apis::FunctionID::Buttons_OnButtonSubscription; + notification[strings::msg_params] = msg_params; + + if (!ApplicationManagerImpl::instance()->ManageHMICommand(notification_ptr)) { + LOG4CXX_ERROR(logger_, "Unable to send HMI notification"); + } +} - utils::SharedPtr<smart_objects::SmartObject> set_app_icon( - new smart_objects::SmartObject); +void MessageHelper::SendAllOnButtonSubscriptionNotificationsForApp( + ApplicationConstSharedPtr app) { + using namespace smart_objects; + using namespace hmi_apis; + using namespace mobile_apis; + LOG4CXX_AUTO_TRACE(logger_); + + if (!app.valid()) { + LOG4CXX_ERROR(logger_, "Invalid application pointer "); + return; + } + + std::set<ButtonName::eType> subscriptions = app->SubscribedButtons(); + std::set<ButtonName::eType>::iterator it = subscriptions.begin(); + for (; subscriptions.end() != it; ++it) { + SendOnButtonSubscriptionNotification( + app->hmi_app_id(), static_cast<Common_ButtonName::eType>(*it), true); + } +} + +void MessageHelper::SendSetAppIcon(uint32_t app_id, + const std::string& icon_path) { + using namespace smart_objects; + SmartObjectSPtr set_app_icon(new smart_objects::SmartObject); if (set_app_icon) { - smart_objects::SmartObject& so_to_send = *set_app_icon; + SmartObject& so_to_send = *set_app_icon; so_to_send[strings::params][strings::function_id] = static_cast<int>(hmi_apis::FunctionID::UI_SetAppIcon); so_to_send[strings::params][strings::message_type] = @@ -702,41 +782,52 @@ void MessageHelper::SendAppDataToHMI(ApplicationConstSharedPtr app) { so_to_send[strings::msg_params] = smart_objects::SmartObject( smart_objects::SmartType_Map); - smart_objects::SmartObject* msg_params = MessageHelper::CreateSetAppIcon( - app->app_icon_path(), id); + SmartObjectSPtr msg_params(MessageHelper::CreateSetAppIcon(icon_path, app_id)); if (msg_params) { so_to_send[strings::msg_params] = *msg_params; } - // TODO(PV): appropriate handling of result - DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(set_app_icon)); + ApplicationManagerImpl::instance()->ManageHMICommand(set_app_icon); } +} - SendGlobalPropertiesToHMI(app); - SendShowRequestToHMI(app); +void MessageHelper::SendAppDataToHMI(ApplicationConstSharedPtr app) { + LOG4CXX_AUTO_TRACE(logger_); + if (app) { + SendSetAppIcon(app, app->app_icon_path()); + SendGlobalPropertiesToHMI(app); + SendShowRequestToHMI(app); + } } void MessageHelper::SendGlobalPropertiesToHMI(ApplicationConstSharedPtr app) { - DCHECK(app.get()); + if (!app.valid()) { + LOG4CXX_ERROR(logger_, "Invalid application"); + return; + } - SmartObjectList requests = CreateGlobalPropertiesRequestsToHMI(app); - for (SmartObjectList::const_iterator it = requests.begin(); + smart_objects::SmartObjectList requests = CreateGlobalPropertiesRequestsToHMI(app); + for (smart_objects::SmartObjectList::const_iterator it = requests.begin(); it != requests.end(); ++it) { DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(*it)) } } -MessageHelper::SmartObjectList MessageHelper::CreateGlobalPropertiesRequestsToHMI( +smart_objects::SmartObjectList MessageHelper::CreateGlobalPropertiesRequestsToHMI( ApplicationConstSharedPtr app) { + LOG4CXX_AUTO_TRACE(logger_); - SmartObjectList requests; - DCHECK(app.get()); + smart_objects::SmartObjectList requests; + if (!app.valid()) { + LOG4CXX_ERROR(logger_, "Invalid application"); + return requests; + } // UI global properties if (app->vr_help_title() || app->vr_help()) { - smart_objects::SmartObject* ui_global_properties = - new smart_objects::SmartObject(smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr ui_global_properties = + new smart_objects::SmartObject(smart_objects::SmartType_Map); if (!ui_global_properties) { return requests; @@ -779,8 +870,8 @@ MessageHelper::SmartObjectList MessageHelper::CreateGlobalPropertiesRequestsToHM // TTS global properties if (app->help_prompt() || app->timeout_prompt()) { - smart_objects::SmartObject* tts_global_properties = - new smart_objects::SmartObject(smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr tts_global_properties = + new smart_objects::SmartObject(smart_objects::SmartType_Map); if (!tts_global_properties) { return requests; @@ -816,10 +907,11 @@ MessageHelper::SmartObjectList MessageHelper::CreateGlobalPropertiesRequestsToHM void MessageHelper::SendTTSGlobalProperties( ApplicationSharedPtr app, bool default_help_prompt) { - if (!app.valid()) { + LOG4CXX_AUTO_TRACE(logger_); + if (!app) { return; } - utils::SharedPtr<smart_objects::SmartObject> tts_global_properties( + smart_objects::SmartObjectSPtr tts_global_properties( new smart_objects::SmartObject); if (tts_global_properties) { smart_objects::SmartObject& so_to_send = *tts_global_properties; @@ -838,7 +930,8 @@ void MessageHelper::SendTTSGlobalProperties( msg_params[strings::help_prompt] = smart_objects::SmartObject( smart_objects::SmartType_Array); if (default_help_prompt) { - const CommandsMap& commands = app->commands_map(); + const DataAccessor<CommandsMap> accessor = app->commands_map(); + const CommandsMap& commands = accessor.GetData(); CommandsMap::const_iterator it = commands.begin(); uint32_t index = 0; for (; commands.end() != it; ++it) { @@ -859,32 +952,27 @@ void MessageHelper::SendTTSGlobalProperties( } } -smart_objects::SmartObject* MessageHelper::CreateAppVrHelp( +smart_objects::SmartObjectSPtr MessageHelper::CreateAppVrHelp( ApplicationConstSharedPtr app) { - smart_objects::SmartObject* result = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr result = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!result) { return NULL; } smart_objects::SmartObject& vr_help = *result; vr_help[strings::vr_help_title] = app->name(); - ApplicationManagerImpl::ApplicationListAccessor accessor; - const std::set<ApplicationSharedPtr> apps = accessor.applications(); - int32_t index = 0; - std::set<ApplicationSharedPtr>::const_iterator it_app = apps.begin(); - for (; apps.end() != it_app; ++it_app) { - if ((*it_app)->vr_synonyms()) { - smart_objects::SmartObject item(smart_objects::SmartType_Map); - item[strings::text] = (*((*it_app)->vr_synonyms())).getElement(0); - item[strings::position] = index + 1; - vr_help[strings::vr_help][index++] = item; - } + if (app->vr_synonyms()) { + smart_objects::SmartObject item(smart_objects::SmartType_Map); + item[strings::text] = (*(app->vr_synonyms())).getElement(0); + item[strings::position] = index + 1; + vr_help[strings::vr_help][index++] = item; } // copy all app VR commands - const CommandsMap& commands = app->commands_map(); + const DataAccessor<CommandsMap> cmd_accessor = app->commands_map(); + const CommandsMap& commands = cmd_accessor.GetData(); CommandsMap::const_iterator it = commands.begin(); for (; commands.end() != it; ++it) { @@ -896,14 +984,18 @@ smart_objects::SmartObject* MessageHelper::CreateAppVrHelp( return result; } -MessageHelper::SmartObjectList MessageHelper::CreateShowRequestToHMI( - ApplicationConstSharedPtr app) { - DCHECK(app.get()); +smart_objects::SmartObjectList MessageHelper::CreateShowRequestToHMI( + ApplicationConstSharedPtr app) { + + smart_objects::SmartObjectList requests; + if (!app) { + LOG4CXX_ERROR(logger_, "Invalid application"); + return requests; + } - SmartObjectList requests; - smart_objects::SmartObject* ui_show = new smart_objects::SmartObject( - smart_objects::SmartType_Map); if (app->show_command()) { + smart_objects::SmartObjectSPtr ui_show = new smart_objects::SmartObject( + smart_objects::SmartType_Map); (*ui_show)[strings::params][strings::function_id] = static_cast<int>(hmi_apis::FunctionID::UI_Show); (*ui_show)[strings::params][strings::message_type] = @@ -924,10 +1016,10 @@ void MessageHelper::SendShowRequestToHMI(ApplicationConstSharedPtr app) { if (!app) { return; } - SmartObjectList shows = CreateShowRequestToHMI(app); + smart_objects::SmartObjectList shows = CreateShowRequestToHMI(app); - for (SmartObjectList::const_iterator it = shows.begin(); it != shows.end(); - ++it) { + for (smart_objects::SmartObjectList::const_iterator it = shows.begin(); + it != shows.end(); ++it) { DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(*it)); } @@ -939,14 +1031,12 @@ void MessageHelper::SendShowConstantTBTRequestToHMI( return; } - smart_objects::SmartObject* navi_show_tbt = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - - if (!navi_show_tbt) { - return; - } - if (app->tbt_show_command()) { + utils::SharedPtr<smart_objects::SmartObject> navi_show_tbt = + new smart_objects::SmartObject(smart_objects::SmartType_Map); + if (!navi_show_tbt) { + return; + } (*navi_show_tbt)[strings::params][strings::function_id] = static_cast<int>(hmi_apis::FunctionID::Navigation_ShowConstantTBT); (*navi_show_tbt)[strings::params][strings::message_type] = @@ -966,25 +1056,30 @@ void MessageHelper::SendAddCommandRequestToHMI(ApplicationConstSharedPtr app) { if (!app) { return; } - SmartObjectList requests = CreateAddCommandRequestToHMI(app); - for (SmartObjectList::iterator it = requests.begin(); it != requests.end(); + smart_objects::SmartObjectList requests = CreateAddCommandRequestToHMI(app); + for (smart_objects::SmartObjectList::iterator it = requests.begin(); it != requests.end(); ++it) { DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(*it)); } } -MessageHelper::SmartObjectList MessageHelper::CreateAddCommandRequestToHMI( +smart_objects::SmartObjectList MessageHelper::CreateAddCommandRequestToHMI( ApplicationConstSharedPtr app) { - DCHECK(app.get()); - SmartObjectList requests; - const CommandsMap& commands = app->commands_map(); + smart_objects::SmartObjectList requests; + if (!app) { + LOG4CXX_ERROR(logger_, "Invalid application"); + return requests; + } + + const DataAccessor<CommandsMap> accessor = app->commands_map(); + const CommandsMap& commands = accessor.GetData(); CommandsMap::const_iterator i = commands.begin(); for (; commands.end() != i; ++i) { // UI Interface if ((*i->second).keyExists(strings::menu_params)) { - smart_objects::SmartObject* ui_command = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr ui_command = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!ui_command) { return requests; @@ -1026,10 +1121,11 @@ MessageHelper::SmartObjectList MessageHelper::CreateAddCommandRequestToHMI( return requests; } -smart_objects::SmartObject* MessageHelper::CreateChangeRegistration( - int32_t function_id, int32_t language, uint32_t app_id) { - smart_objects::SmartObject* command = new smart_objects::SmartObject( - smart_objects::SmartType_Map); +smart_objects::SmartObjectSPtr MessageHelper::CreateChangeRegistration( + int32_t function_id, int32_t language, uint32_t app_id, + const smart_objects::SmartObject* app_types) { + smart_objects::SmartObjectSPtr command = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!command) { return NULL; } @@ -1052,16 +1148,37 @@ smart_objects::SmartObject* MessageHelper::CreateChangeRegistration( msg_params[strings::language] = language; msg_params[strings::app_id] = app_id; + if (app_types != NULL) { + msg_params[strings::app_hmi_type] = *app_types; + } + params[strings::msg_params] = msg_params; return command; } +void MessageHelper::SendUIChangeRegistrationRequestToHMI(ApplicationConstSharedPtr app) { + if (!app.valid()) { + LOG4CXX_ERROR(logger_, "Application is not valid"); + return; + } + + if (NULL != app->app_types()) { + smart_objects::SmartObjectSPtr ui_command = CreateChangeRegistration( + hmi_apis::FunctionID::UI_ChangeRegistration, app->ui_language(), + app->app_id(), app->app_types()); + + if (ui_command) { + ApplicationManagerImpl::instance()->ManageHMICommand(ui_command); + } + } +} + void MessageHelper::SendChangeRegistrationRequestToHMI(ApplicationConstSharedPtr app) { if (!app.valid()) { return; } if (mobile_apis::Language::INVALID_ENUM != app->language()) { - smart_objects::SmartObject* vr_command = CreateChangeRegistration( + smart_objects::SmartObjectSPtr vr_command = CreateChangeRegistration( hmi_apis::FunctionID::VR_ChangeRegistration, app->language(), app->app_id()); @@ -1071,7 +1188,7 @@ void MessageHelper::SendChangeRegistrationRequestToHMI(ApplicationConstSharedPtr } if (mobile_apis::Language::INVALID_ENUM != app->language()) { - smart_objects::SmartObject* tts_command = CreateChangeRegistration( + smart_objects::SmartObjectSPtr tts_command = CreateChangeRegistration( hmi_apis::FunctionID::TTS_ChangeRegistration, app->language(), app->app_id()); @@ -1081,7 +1198,7 @@ void MessageHelper::SendChangeRegistrationRequestToHMI(ApplicationConstSharedPtr } if (mobile_apis::Language::INVALID_ENUM != app->ui_language()) { - smart_objects::SmartObject* ui_command = CreateChangeRegistration( + smart_objects::SmartObjectSPtr ui_command = CreateChangeRegistration( hmi_apis::FunctionID::UI_ChangeRegistration, app->ui_language(), app->app_id()); @@ -1095,18 +1212,17 @@ void MessageHelper::SendChangeRegistrationRequestToHMI(ApplicationConstSharedPtr void MessageHelper::SendAddVRCommandToHMI( uint32_t cmd_id, const smart_objects::SmartObject& vr_commands, uint32_t app_id) { - smart_objects::SmartObject* request = CreateAddVRCommandToHMI(cmd_id, + smart_objects::SmartObjectSPtr request = CreateAddVRCommandToHMI(cmd_id, vr_commands, app_id); DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(request)); } -smart_objects::SmartObject* MessageHelper::CreateAddVRCommandToHMI( - uint32_t cmd_id, - const NsSmartDeviceLink::NsSmartObjects::SmartObject& vr_commands, - uint32_t app_id) { - smart_objects::SmartObject* vr_command = new smart_objects::SmartObject( - smart_objects::SmartType_Map); +smart_objects::SmartObjectSPtr MessageHelper::CreateAddVRCommandToHMI( + uint32_t cmd_id, const smart_objects::SmartObject& vr_commands, + uint32_t app_id) { + smart_objects::SmartObjectSPtr vr_command = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!vr_command) { return NULL; @@ -1143,50 +1259,97 @@ smart_objects::SmartObject* MessageHelper::CreateAddVRCommandToHMI( bool MessageHelper::CreateHMIApplicationStruct(ApplicationConstSharedPtr app, smart_objects::SmartObject& output) { + using namespace smart_objects; + LOG4CXX_AUTO_TRACE(logger_); - if (false == app.valid()) { + if (!app) { + LOG4CXX_WARN(logger_, "Application is not valid"); return false; } - const smart_objects::SmartObject* app_types = app->app_types(); - const smart_objects::SmartObject* ngn_media_screen_name = app->ngn_media_screen_name(); + const SmartObject* app_types = app->app_types(); + DCHECK_OR_RETURN(app_types, false); + const SmartObject* ngn_media_screen_name = app->ngn_media_screen_name(); + DCHECK_OR_RETURN(ngn_media_screen_name, false); const connection_handler::DeviceHandle handle = app->device(); std::string device_name = ApplicationManagerImpl::instance()->GetDeviceName(handle); - output = smart_objects::SmartObject(smart_objects::SmartType_Map); + std::string mac_address; + std::string transport_type; + if (-1 == connection_handler::ConnectionHandlerImpl::instance()-> + GetDataOnDeviceID(app->device(), &device_name, + NULL, &mac_address, &transport_type)) { + LOG4CXX_ERROR(logger_, "Failed to extract information for device " + << app->device()); + } + + output = SmartObject(SmartType_Map); output[strings::app_name] = app->name(); output[strings::icon] = app->app_icon_path(); - output[strings::device_name] = device_name; - output[strings::app_id] = app->app_id(); - output[strings::hmi_display_language_desired] = app->ui_language(); - output[strings::is_media_application] = app->is_media_application(); + output[strings::app_id] = app->hmi_app_id(); + + if (app->IsRegistered()) { + output[strings::hmi_display_language_desired] = app->ui_language(); + output[strings::is_media_application] = app->is_media_application(); + } + + if (!app->IsRegistered()) { + output[strings::greyOut] = app->is_greyed_out(); + const SmartObject* app_tts_name = app->tts_name(); + DCHECK_OR_RETURN(app_tts_name, false); + if (!app_tts_name->empty()) { + SmartObject output_tts_name = SmartObject(SmartType_Array); + output_tts_name[0][strings::text] = *(app->tts_name()); + output_tts_name[0][strings::type] = hmi_apis::Common_SpeechCapabilities::SC_TEXT; + output[json::ttsName] = output_tts_name; + } + if (!app->vr_synonyms()->empty()) { + output[json::vrSynonyms] = *(app->vr_synonyms()); + } + } - if (NULL != ngn_media_screen_name) { + if (ngn_media_screen_name) { output[strings::ngn_media_screen_app_name] = ngn_media_screen_name->asString(); } - if (NULL != app_types) { + if (app_types) { output[strings::app_type] = *app_types; } + + output[strings::device_info] = smart_objects::SmartObject(smart_objects::SmartType_Map); + output[strings::device_info][strings::name] = device_name; + output[strings::device_info][strings::id] = mac_address; + const policy::DeviceConsent device_consent = + policy::PolicyHandler::instance()->GetUserConsentForDevice(mac_address); + output[strings::device_info][strings::isSDLAllowed] = + policy::DeviceConsent::kDeviceAllowed == device_consent; + + output[strings::device_info][strings::transport_type] = + ApplicationManagerImpl::instance()->GetDeviceTransportType(transport_type); return true; } void MessageHelper::SendAddSubMenuRequestToHMI(ApplicationConstSharedPtr app) { - DCHECK(app.get()); - SmartObjectList requests = CreateAddSubMenuRequestToHMI(app); - for (SmartObjectList::iterator it = requests.begin(); it != requests.end(); - ++it) { + if (!app.valid()) { + LOG4CXX_ERROR(logger_, "Invalid application"); + return; + } + + smart_objects::SmartObjectList requests = CreateAddSubMenuRequestToHMI(app); + for (smart_objects::SmartObjectList::iterator it = requests.begin(); + it != requests.end(); ++it) { DCHECK(ApplicationManagerImpl::instance()->ManageHMICommand(*it)); } } -MessageHelper::SmartObjectList MessageHelper::CreateAddSubMenuRequestToHMI( +smart_objects::SmartObjectList MessageHelper::CreateAddSubMenuRequestToHMI( ApplicationConstSharedPtr app) { - SmartObjectList requsets; - const SubMenuMap& sub_menu = app->sub_menu_map(); + smart_objects::SmartObjectList requsets; + const DataAccessor<SubMenuMap> accessor = app->sub_menu_map(); + const SubMenuMap& sub_menu = accessor.GetData(); SubMenuMap::const_iterator i = sub_menu.begin(); for (; sub_menu.end() != i; ++i) { - smart_objects::SmartObject* ui_sub_menu = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr ui_sub_menu = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!ui_sub_menu) { return requsets; @@ -1220,8 +1383,8 @@ MessageHelper::SmartObjectList MessageHelper::CreateAddSubMenuRequestToHMI( void MessageHelper::SendOnAppUnregNotificationToHMI( ApplicationConstSharedPtr app, bool is_unexpected_disconnect) { - smart_objects::SmartObject* notification = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr notification = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!notification) { return; } @@ -1237,46 +1400,50 @@ void MessageHelper::SendOnAppUnregNotificationToHMI( message[strings::msg_params][strings::app_id] = app->hmi_app_id(); message[strings::msg_params][strings::unexpected_disconnect] = is_unexpected_disconnect; - ApplicationManagerImpl::instance()->ManageHMICommand(&message); + ApplicationManagerImpl::instance()->ManageHMICommand(notification); } -void MessageHelper::SendActivateAppToHMI(uint32_t const app_id, - hmi_apis::Common_HMILevel::eType level) { - smart_objects::SmartObject* message = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - +uint32_t MessageHelper::SendActivateAppToHMI(uint32_t const app_id, + hmi_apis::Common_HMILevel::eType level, + bool send_policy_priority) { + uint32_t correlation_id = 0; application_manager::ApplicationConstSharedPtr app = application_manager::ApplicationManagerImpl::instance() ->application(app_id); - if (!app.valid()) { + if (!app) { LOG4CXX_WARN(logger_, "Invalid app_id: " << app_id); - return; + return correlation_id; } + correlation_id = + ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); + utils::SharedPtr<smart_objects::SmartObject> message = new smart_objects::SmartObject( + smart_objects::SmartType_Map); (*message)[strings::params][strings::function_id] = hmi_apis::FunctionID::BasicCommunication_ActivateApp; (*message)[strings::params][strings::message_type] = MessageType::kRequest; - (*message)[strings::params][strings::correlation_id] = - ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); + (*message)[strings::params][strings::correlation_id] = correlation_id; (*message)[strings::msg_params][strings::app_id] = app_id; - std::string priority; - // TODO(KKolodiy): need remove method policy_manager - - policy::PolicyHandler::instance()->GetPriority( - app->mobile_app_id()->asString(), &priority); - // According SDLAQ-CRS-2794 - // SDL have to send ActivateApp without "proirity" parameter to HMI. - // in case of unconsented device - std::string mac_adress; - connection_handler::DeviceHandle device_handle = app->device(); - connection_handler::ConnectionHandlerImpl::instance()-> - GetDataOnDeviceID(device_handle, NULL, NULL, &mac_adress, NULL); - - policy::DeviceConsent consent = - policy::PolicyHandler::instance()->GetUserConsentForDevice(mac_adress); - if (!priority.empty() && (policy::DeviceConsent::kDeviceAllowed == consent)) { - (*message)[strings::msg_params]["priority"] = GetPriorityCode(priority); + if (send_policy_priority) { + std::string priority; + // TODO(KKolodiy): need remove method policy_manager + + policy::PolicyHandler::instance()->GetPriority( + app->mobile_app_id(), &priority); + // According SDLAQ-CRS-2794 + // SDL have to send ActivateApp without "proirity" parameter to HMI. + // in case of unconsented device + std::string mac_adress; + connection_handler::DeviceHandle device_handle = app->device(); + connection_handler::ConnectionHandlerImpl::instance()-> + GetDataOnDeviceID(device_handle, NULL, NULL, &mac_adress, NULL); + + policy::DeviceConsent consent = + policy::PolicyHandler::instance()->GetUserConsentForDevice(mac_adress); + if (!priority.empty() && (policy::DeviceConsent::kDeviceAllowed == consent)) { + (*message)[strings::msg_params][strings::priority] = GetPriorityCode(priority); + } } // We haven't send HMI level to HMI in case it FULL. @@ -1286,21 +1453,22 @@ void MessageHelper::SendActivateAppToHMI(uint32_t const app_id, } ApplicationManagerImpl::instance()->ManageHMICommand(message); + return correlation_id; } void MessageHelper::SendOnResumeAudioSourceToHMI(const uint32_t app_id) { LOG4CXX_WARN(logger_, "SendOnResumeAudioSourceToHMI app_id: " << app_id); - - smart_objects::SmartObject* message = new smart_objects::SmartObject( - smart_objects::SmartType_Map); application_manager::ApplicationConstSharedPtr app = application_manager::ApplicationManagerImpl::instance() ->application(app_id); - if (!app.valid()) { + if (!app) { LOG4CXX_WARN(logger_, "Invalid app_id: " << app_id); return; } + utils::SharedPtr<smart_objects::SmartObject> message = new smart_objects::SmartObject( + smart_objects::SmartType_Map); + (*message)[strings::params][strings::function_id] = hmi_apis::FunctionID::BasicCommunication_OnResumeAudioSource; (*message)[strings::params][strings::message_type] = MessageType::kNotification; @@ -1317,7 +1485,7 @@ std::string MessageHelper::GetDeviceMacAddressForHandle( std::string device_mac_address = ""; connection_handler::ConnectionHandlerImpl::instance()->GetDataOnDeviceID( device_handle, NULL, NULL, &device_mac_address); - + LOG4CXX_DEBUG(logger_, "result : " << device_handle); return device_mac_address; } @@ -1345,8 +1513,8 @@ void MessageHelper::GetDeviceInfoForApp(uint32_t connection_key, void MessageHelper::SendSDLActivateAppResponse(policy::AppPermissions& permissions, uint32_t correlation_id) { - smart_objects::SmartObject* message = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!message) { return; } @@ -1366,7 +1534,7 @@ void MessageHelper::SendSDLActivateAppResponse(policy::AppPermissions& permissio (*message)[strings::msg_params]["device"]["name"] = permissions.deviceInfo .device_name; (*message)[strings::msg_params]["device"]["id"] = permissions.deviceInfo - .device_handle; + .device_mac_address; } (*message)[strings::msg_params]["isAppRevoked"] = permissions.appRevoked; @@ -1391,21 +1559,12 @@ void MessageHelper::SendSDLActivateAppResponse(policy::AppPermissions& permissio if (permissions.appRevoked || !permissions.isSDLAllowed) { return; } - - // Send HMI status notification to mobile - ApplicationSharedPtr app = ApplicationManagerImpl::instance() - ->application_by_policy_id(permissions.application_id); - if (app) { - ApplicationManagerImpl::instance()->ActivateApplication(app); - } else { - LOG4CXX_WARN(logger_, "Unable to find app_id: " << permissions.application_id); - } } void MessageHelper::SendOnSDLConsentNeeded( const policy::DeviceParams& device_info) { - smart_objects::SmartObject* message = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!message) { return; } @@ -1415,7 +1574,7 @@ void MessageHelper::SendOnSDLConsentNeeded( (*message)[strings::params][strings::message_type] = MessageType::kNotification; - (*message)[strings::msg_params]["device"]["id"] = device_info.device_handle; + (*message)[strings::msg_params]["device"]["id"] = device_info.device_mac_address; (*message)[strings::msg_params]["device"]["name"] = device_info.device_name; ApplicationManagerImpl::instance()->ManageHMICommand(message); @@ -1425,8 +1584,8 @@ void MessageHelper::SendPolicyUpdate( const std::string& file_path, int timeout, const std::vector<int>& retries) { - smart_objects::SmartObject* message = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject( + smart_objects::SmartType_Map); smart_objects::SmartObject& object = *message; object[strings::params][strings::function_id] = hmi_apis::FunctionID::BasicCommunication_PolicyUpdate; @@ -1451,8 +1610,8 @@ void MessageHelper::SendPolicyUpdate( void MessageHelper::SendGetUserFriendlyMessageResponse( const std::vector<policy::UserFriendlyMessage>& msg, uint32_t correlation_id) { - smart_objects::SmartObject* message = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!message) { return; } @@ -1476,12 +1635,6 @@ void MessageHelper::SendGetUserFriendlyMessageResponse( smart_objects::SmartObject& user_friendly_messages = (*message)[strings::msg_params][messages]; - - const std::string tts = "ttsString"; - const std::string label = "label"; - const std::string line1 = "line1"; - const std::string line2 = "line2"; - const std::string textBody = "textBody"; const std::string message_code = "messageCode"; std::vector<policy::UserFriendlyMessage>::const_iterator it = msg.begin(); @@ -1492,22 +1645,6 @@ void MessageHelper::SendGetUserFriendlyMessageResponse( smart_objects::SmartObject& obj = user_friendly_messages[index]; obj[message_code] = it->message_code; - - if (!it->tts.empty()) { - obj[tts] = it->tts; - } - if (!it->label.empty()) { - obj[label] = it->label; - } - if (!it->line1.empty()) { - obj[line1] = it->line1; - } - if (!it->line2.empty()) { - obj[line2] = it->line2; - } - if (!it->text_body.empty()) { - obj[textBody] = it->text_body; - } } ApplicationManagerImpl::instance()->ManageHMICommand(message); @@ -1516,8 +1653,8 @@ void MessageHelper::SendGetUserFriendlyMessageResponse( void MessageHelper::SendGetListOfPermissionsResponse( const std::vector<policy::FunctionalGroupPermission>& permissions, uint32_t correlation_id) { - smart_objects::SmartObject* message = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!message) { return; } @@ -1557,11 +1694,11 @@ void MessageHelper::SendGetListOfPermissionsResponse( ApplicationManagerImpl::instance()->ManageHMICommand(message); } -smart_objects::SmartObject* MessageHelper::CreateNegativeResponse( - uint32_t connection_key, int32_t function_id, uint32_t correlation_id, - int32_t result_code) { - smart_objects::SmartObject* response = new smart_objects::SmartObject( - smart_objects::SmartType_Map); +smart_objects::SmartObjectSPtr MessageHelper::CreateNegativeResponse( + uint32_t connection_key, int32_t function_id, uint32_t correlation_id, + int32_t result_code) { + smart_objects::SmartObjectSPtr response = new smart_objects::SmartObject( + smart_objects::SmartType_Map); smart_objects::SmartObject& response_data = *response; response_data[strings::params][strings::function_id] = function_id; response_data[strings::params][strings::message_type] = @@ -1579,9 +1716,9 @@ smart_objects::SmartObject* MessageHelper::CreateNegativeResponse( } void MessageHelper::SendNaviStartStream(int32_t connection_key) { - LOG4CXX_INFO(logger_, "MessageHelper::SendNaviStartStream"); - smart_objects::SmartObject* start_stream = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + LOG4CXX_AUTO_TRACE(logger_); + smart_objects::SmartObjectSPtr start_stream = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!start_stream) { return; @@ -1628,8 +1765,8 @@ void MessageHelper::SendNaviStartStream(int32_t connection_key) { } void MessageHelper::SendNaviStopStream(int32_t connection_key) { - smart_objects::SmartObject* stop_stream = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr stop_stream = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!stop_stream) { return; @@ -1662,8 +1799,8 @@ void MessageHelper::SendNaviStopStream(int32_t connection_key) { void MessageHelper::SendAudioStartStream(int32_t connection_key) { - smart_objects::SmartObject* start_stream = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr start_stream = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!start_stream) { return; @@ -1711,8 +1848,8 @@ void MessageHelper::SendAudioStartStream(int32_t connection_key) { } void MessageHelper::SendAudioStopStream(int32_t connection_key) { - smart_objects::SmartObject* stop_stream = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr stop_stream = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!stop_stream) { return; @@ -1743,14 +1880,43 @@ void MessageHelper::SendAudioStopStream(int32_t connection_key) { ApplicationManagerImpl::instance()->ManageHMICommand(stop_stream); } +void MessageHelper::SendOnDataStreaming(protocol_handler::ServiceType service, + bool available) { + using namespace protocol_handler; + smart_objects::SmartObjectSPtr notification = new smart_objects::SmartObject( + smart_objects::SmartType_Map); + + if (!notification) { + return; + } + + if (ServiceType::kAudio != service && ServiceType::kMobileNav != service) { + return; + } + + (*notification)[strings::params][strings::function_id] = + ServiceType::kAudio == service + ? hmi_apis::FunctionID::Navigation_OnAudioDataStreaming + : hmi_apis::FunctionID::Navigation_OnVideoDataStreaming; + (*notification)[strings::params][strings::message_type] = + hmi_apis::messageType::notification; + (*notification)[strings::params][strings::protocol_version] = + commands::CommandImpl::protocol_version_; + (*notification)[strings::params][strings::protocol_type] = + commands::CommandImpl::hmi_protocol_type_; + + (*notification)[strings::msg_params]["available"] = available; + + ApplicationManagerImpl::instance()->ManageHMICommand(notification); +} + bool MessageHelper::SendStopAudioPathThru() { LOG4CXX_INFO(logger_, "MessageHelper::SendAudioStopAudioPathThru"); - NsSmartDeviceLink::NsSmartObjects::SmartObject* result = - new NsSmartDeviceLink::NsSmartObjects::SmartObject; + smart_objects::SmartObjectSPtr result = new smart_objects::SmartObject; const uint32_t hmi_correlation_id = ApplicationManagerImpl::instance() ->GetNextHMICorrelationID(); - NsSmartDeviceLink::NsSmartObjects::SmartObject& request = *result; + smart_objects::SmartObject& request = *result; request[strings::params][strings::message_type] = MessageType::kRequest; request[strings::params][strings::function_id] = hmi_apis::FunctionID::UI_EndAudioPassThru; @@ -1765,40 +1931,102 @@ bool MessageHelper::SendStopAudioPathThru() { void MessageHelper::SendPolicySnapshotNotification( unsigned int connection_key, const std::vector<uint8_t>& policy_data, const std::string& url, int timeout) { - smart_objects::SmartObject* pt_notification = new smart_objects::SmartObject( - smart_objects::SmartType_Map); - smart_objects::SmartObject& content = *pt_notification; - ; - content[strings::params][strings::function_id] = - mobile_apis::FunctionID::OnSystemRequestID; - content[strings::params][strings::message_type] = - mobile_apis::messageType::notification; - content[strings::params][strings::protocol_type] = - commands::CommandImpl::mobile_protocol_type_; - content[strings::params][strings::protocol_version] = - commands::CommandImpl::protocol_version_; - content[strings::params][strings::connection_key] = connection_key; + + using namespace mobile_apis; + using namespace smart_objects; + + SmartObject content (SmartType_Map); if (!url.empty()) { content[strings::msg_params][mobile_notification::syncp_url] = url; } - content[strings::msg_params][strings::file_type] = - mobile_apis::FileType::BINARY; - content[strings::msg_params][strings::request_type] = - mobile_apis::RequestType::HTTP; - /*if (-1 != timeout) { - content[strings::msg_params][mobile_notification::syncp_timeout] = timeout; - }*/ - content[strings::params][strings::binary_data] = smart_objects::SmartObject( - policy_data); - ApplicationManagerImpl::instance()->ManageMobileCommand(pt_notification); + + content[strings::msg_params][strings::request_type] = RequestType::HTTP; + content[strings::params][strings::binary_data] = SmartObject(policy_data); + content[strings::msg_params][strings::file_type] = FileType::BINARY; + + SendSystemRequestNotification(connection_key, content); +} + +void MessageHelper::SendSystemRequestNotification (uint32_t connection_key, + smart_objects::SmartObject& content) { + + using namespace mobile_apis; + using namespace commands; + using namespace smart_objects; + + content[strings::params][strings::function_id] = FunctionID::OnSystemRequestID; + content[strings::params][strings::message_type] = messageType::notification; + content[strings::params][strings::protocol_type] = CommandImpl::mobile_protocol_type_; + content[strings::params][strings::protocol_version] = CommandImpl::protocol_version_; + + content[strings::params][strings::connection_key] = connection_key; + + ApplicationManagerImpl::instance()->ManageMobileCommand(new SmartObject(content)); +} + +void MessageHelper::SendLaunchApp(uint32_t connection_key, + const std::string& urlSchema, + const std::string& packageName) { + + using namespace mobile_apis; + using namespace smart_objects; + + SmartObject content (SmartType_Map); + content[strings::msg_params][strings::request_type] = RequestType::LAUNCH_APP; + content[strings::msg_params][strings::app_id] = connection_key; + if (!urlSchema.empty()) { + content[strings::msg_params][strings::url] = urlSchema; + } else if (!packageName.empty()) { + content[strings::msg_params][strings::url] = packageName; + } + + SendSystemRequestNotification(connection_key, content); +} + +void application_manager::MessageHelper::SendQueryApps( + uint32_t connection_key) { + using namespace mobile_apis; + using namespace smart_objects; + + policy::PolicyHandler* policy_handler = policy::PolicyHandler::instance(); + + SmartObject content (SmartType_Map); + content[strings::msg_params][strings::request_type] = RequestType::QUERY_APPS; + content[strings::msg_params][strings::url] = policy_handler->RemoteAppsUrl(); + content[strings::msg_params][strings::timeout] = + policy_handler->TimeoutExchange(); + + Json::Value http; + Json::Value& http_header = http[http_request::httpRequest][http_request::headers]; + + const int timeout = policy_handler->TimeoutExchange(); + + http_header[http_request::content_type] = "application/json"; + http_header[http_request::connect_timeout] = timeout; + http_header[http_request::do_output] = true; + http_header[http_request::do_input] = true; + http_header[http_request::use_caches] = false; + http_header[http_request::request_method] = http_request::GET; + http_header[http_request::read_timeout] = timeout; + http_header[http_request::instance_follow_redirect] = false; + http_header[http_request::charset] = "utf-8"; + http_header[http_request::content_lenght] = 0; + + std::string data = http_header.toStyledString(); + std::vector<uint8_t> binary_data(data.begin(), data.end()); + + content[strings::params][strings::binary_data] = SmartObject(binary_data); + content[strings::msg_params][strings::file_type] = FileType::BINARY; + + SendSystemRequestNotification(connection_key, content); } void MessageHelper::SendOnPermissionsChangeNotification( uint32_t connection_key, const policy::Permissions& permissions) { - smart_objects::SmartObject* notification = new smart_objects::SmartObject( + utils::SharedPtr<smart_objects::SmartObject> notification = new smart_objects::SmartObject( smart_objects::SmartType_Map); smart_objects::SmartObject& content = *notification; - ; + content[strings::params][strings::function_id] = mobile_apis::FunctionID::OnPermissionsChangeID; content[strings::params][strings::message_type] = @@ -1809,7 +2037,7 @@ void MessageHelper::SendOnPermissionsChangeNotification( commands::CommandImpl::protocol_version_; content[strings::params][strings::connection_key] = connection_key; - smart_objects::SmartObject* p_msg_params = new smart_objects::SmartObject( + utils::SharedPtr<smart_objects::SmartObject> p_msg_params = new smart_objects::SmartObject( smart_objects::SmartType_Map); smart_objects::SmartObject& msg_params = *p_msg_params; @@ -1937,13 +2165,13 @@ void MessageHelper::FillAppRevokedPermissions( void MessageHelper::SendOnAppPermissionsChangedNotification( uint32_t connection_key, const policy::AppPermissions& permissions) { - smart_objects::SmartObject* notification = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + using namespace smart_objects; + SmartObjectSPtr notification = new SmartObject(SmartType_Map); if (!notification) { return; } - smart_objects::SmartObject& message = *notification; + SmartObject& message = *notification; message[strings::params][strings::function_id] = hmi_apis::FunctionID::SDL_OnAppPermissionChanged; @@ -1974,14 +2202,22 @@ void MessageHelper::SendOnAppPermissionsChangedNotification( message[strings::msg_params]["priority"] = GetPriorityCode( permissions.priority); } + if (permissions.requestTypeChanged) { + SmartObject request_types_array = SmartObject(SmartType_Array); + for (uint16_t index = 0; index < permissions.requestType.size(); ++index) { + request_types_array[index] = permissions.requestType[index]; + } + message[strings::msg_params][strings::request_type] = + request_types_array; + } - ApplicationManagerImpl::instance()->ManageHMICommand(&message); + ApplicationManagerImpl::instance()->ManageHMICommand(notification); } void MessageHelper::SendGetStatusUpdateResponse(const std::string& status, uint32_t correlation_id) { - smart_objects::SmartObject* message = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!message) { return; } @@ -1998,9 +2234,10 @@ void MessageHelper::SendGetStatusUpdateResponse(const std::string& status, ApplicationManagerImpl::instance()->ManageHMICommand(message); } -void MessageHelper::SendUpdateSDLResponse(const std::string& result, uint32_t correlation_id) { - smart_objects::SmartObject* message = new smart_objects::SmartObject( - smart_objects::SmartType_Map); +void MessageHelper::SendUpdateSDLResponse(const std::string& result, + uint32_t correlation_id) { + smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!message) { return; } @@ -2017,11 +2254,9 @@ void MessageHelper::SendUpdateSDLResponse(const std::string& result, uint32_t co ApplicationManagerImpl::instance()->ManageHMICommand(message); } - - void MessageHelper::SendOnStatusUpdate(const std::string& status) { - smart_objects::SmartObject* message = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!message) { return; } @@ -2037,8 +2272,8 @@ void MessageHelper::SendOnStatusUpdate(const std::string& status) { } void MessageHelper::SendGetSystemInfoRequest() { - smart_objects::SmartObject* message = new smart_objects::SmartObject( - smart_objects::SmartType_Map); + smart_objects::SmartObjectSPtr message = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!message) { return; } @@ -2063,6 +2298,7 @@ mobile_apis::Result::eType MessageHelper::VerifyImageFiles( for (uint32_t i = 0; i < message.length(); ++i) { mobile_apis::Result::eType res = VerifyImageFiles(message[i], app); if (mobile_apis::Result::SUCCESS != res) { + LOG4CXX_DEBUG(logger_, "VerifyImageFiles result:" << res); return res; } } @@ -2073,6 +2309,7 @@ mobile_apis::Result::eType MessageHelper::VerifyImageFiles( app); if (mobile_apis::Result::SUCCESS != verification_result) { + LOG4CXX_DEBUG(logger_, "VerifyImageFiles result:" << verification_result); return verification_result; // exit point } } else { @@ -2083,6 +2320,7 @@ mobile_apis::Result::eType MessageHelper::VerifyImageFiles( if (strings::soft_buttons != (*key)) { mobile_apis::Result::eType res = VerifyImageFiles(message[*key], app); if (mobile_apis::Result::SUCCESS != res) { + LOG4CXX_DEBUG(logger_, "VerifyImageFiles result:" << res); return res; } } @@ -2112,12 +2350,25 @@ mobile_apis::Result::eType MessageHelper::VerifyImage( return mobile_apis::Result::INVALID_DATA; } - std::string full_file_path = - profile::Profile::instance()->app_storage_folder() + "/"; - + std::string full_file_path; if (file_name.size() > 0 && file_name[0] == '/') { full_file_path = file_name; } else { + const std::string& app_storage_folder = + profile::Profile::instance()->app_storage_folder(); + if (!app_storage_folder.empty()) { +// TODO(nvaganov@luxoft.com): APPLINK-11293 + if (app_storage_folder[0] == '/') { // absolute path + full_file_path = app_storage_folder + "/"; + } + else { // relative path + full_file_path = file_system::CurrentWorkingDirectory() + "/" + + app_storage_folder + "/"; + } + } + else { // empty app storage folder + full_file_path = file_system::CurrentWorkingDirectory() + "/"; + } full_file_path += app->folder_name(); full_file_path += "/"; @@ -2161,15 +2412,31 @@ bool MessageHelper::VerifySoftButtonString(const std::string& str) { return true; } +bool MessageHelper::CheckWithPolicy( + mobile_api::SystemAction::eType system_action, + const std::string& app_mobile_id) { + using namespace mobile_apis; + bool result = true; + policy::PolicyHandler* policy_handler = policy::PolicyHandler::instance(); + if (NULL != policy_handler && policy_handler->PolicyEnabled()) { + result = policy_handler->CheckSystemAction(system_action, app_mobile_id); + } + + return result; +} + mobile_apis::Result::eType MessageHelper::ProcessSoftButtons( smart_objects::SmartObject& message_params, ApplicationConstSharedPtr app) { + using namespace mobile_apis; + using namespace smart_objects; + if (!message_params.keyExists(strings::soft_buttons)) { return mobile_apis::Result::SUCCESS; } const HMICapabilities& hmi_capabilities = ApplicationManagerImpl::instance() ->hmi_capabilities(); - const smart_objects::SmartObject* soft_button_capabilities = hmi_capabilities + const SmartObject* soft_button_capabilities = hmi_capabilities .soft_button_capabilities(); bool image_supported = false; if (soft_button_capabilities) { @@ -2177,31 +2444,27 @@ mobile_apis::Result::eType MessageHelper::ProcessSoftButtons( .asBool(); } - smart_objects::SmartObject& request_soft_buttons = - message_params[strings::soft_buttons]; + SmartObject& request_soft_buttons = message_params[strings::soft_buttons]; // Check whether soft buttons request is well-formed if (!ValidateSoftButtons(request_soft_buttons)) { - return mobile_apis::Result::INVALID_DATA; + return Result::INVALID_DATA; } - smart_objects::SmartObject soft_buttons = smart_objects::SmartObject( - smart_objects::SmartType_Array); - - policy::PolicyHandler* policy_handler = policy::PolicyHandler::instance(); - std::string app_mobile_id = app->mobile_app_id()->asString(); + SmartObject soft_buttons(SmartType_Array); uint32_t j = 0; size_t size = request_soft_buttons.length(); for (uint32_t i = 0; i < size; ++i) { - int system_action = request_soft_buttons[i][strings::system_action].asInt(); - if (!policy_handler->CheckKeepContext(system_action, app_mobile_id) || - !policy_handler->CheckStealFocus(system_action, app_mobile_id)) { - return mobile_apis::Result::DISALLOWED; + const int system_action = request_soft_buttons[i][strings::system_action].asInt(); + + if (!CheckWithPolicy(static_cast<SystemAction::eType>(system_action), + app->mobile_app_id())) { + return Result::DISALLOWED; } switch (request_soft_buttons[i][strings::type].asInt()) { - case mobile_apis::SoftButtonType::SBT_IMAGE: { + case SoftButtonType::SBT_IMAGE: { if (!image_supported) { continue; } @@ -2210,46 +2473,46 @@ mobile_apis::Result::eType MessageHelper::ProcessSoftButtons( request_soft_buttons[i].erase(strings::text); } if (request_soft_buttons[i].keyExists(strings::image)) { - mobile_apis::Result::eType verification_result = VerifyImage( + Result::eType verification_result = VerifyImage( request_soft_buttons[i][strings::image], app); - if (mobile_apis::Result::SUCCESS != verification_result) { - return mobile_apis::Result::INVALID_DATA; + if (Result::SUCCESS != verification_result) { + return Result::INVALID_DATA; } } else { - return mobile_apis::Result::INVALID_DATA; + return Result::INVALID_DATA; } break; } - case mobile_apis::SoftButtonType::SBT_TEXT: { + case SoftButtonType::SBT_TEXT: { if ((!request_soft_buttons[i].keyExists(strings::text)) || (!VerifySoftButtonString( request_soft_buttons[i][strings::text].asString()))) { - return mobile_apis::Result::INVALID_DATA; + return Result::INVALID_DATA; } break; } - case mobile_apis::SoftButtonType::SBT_BOTH: { + case SoftButtonType::SBT_BOTH: { if ((!request_soft_buttons[i].keyExists(strings::text)) || ((request_soft_buttons[i][strings::text].length()) && (!VerifySoftButtonString( request_soft_buttons[i][strings::text].asString())))) { - return mobile_apis::Result::INVALID_DATA; + return Result::INVALID_DATA; } bool image_exist = false; if (image_supported) { image_exist = request_soft_buttons[i].keyExists(strings::image); if (!image_exist) { - return mobile_apis::Result::INVALID_DATA; + return Result::INVALID_DATA; } } if (image_exist) { - mobile_apis::Result::eType verification_result = VerifyImage( + Result::eType verification_result = VerifyImage( request_soft_buttons[i][strings::image], app); - if (mobile_apis::Result::SUCCESS != verification_result) { - return mobile_apis::Result::INVALID_DATA; + if (Result::SUCCESS != verification_result) { + return Result::INVALID_DATA; } } @@ -2270,7 +2533,7 @@ mobile_apis::Result::eType MessageHelper::ProcessSoftButtons( if (0 == request_soft_buttons.length()) { message_params.erase(strings::soft_buttons); } - return mobile_apis::Result::SUCCESS; + return Result::SUCCESS; } void MessageHelper::SubscribeApplicationToSoftButton( |