diff options
Diffstat (limited to 'src/components/application_manager/src/message_helper.cc')
-rw-r--r-- | src/components/application_manager/src/message_helper.cc | 715 |
1 files changed, 403 insertions, 312 deletions
diff --git a/src/components/application_manager/src/message_helper.cc b/src/components/application_manager/src/message_helper.cc index 8048b37dda..15e0d5365f 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. @@ -259,7 +259,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,9 +290,9 @@ void MessageHelper::SendHMIStatusNotification( void MessageHelper::SendOnAppRegisteredNotificationToHMI( const Application& application_impl, bool resumption, bool need_restore_vr) { - smart_objects::SmartObject* notification = new smart_objects::SmartObject; + smart_objects::SmartObjectSPtr notification = new smart_objects::SmartObject; if (!notification) { - // TODO(VS): please add logger. + LOG4CXX_ERROR(logger_, "Failed to create smart object"); return; } smart_objects::SmartObject& message = *notification; @@ -352,7 +353,7 @@ void MessageHelper::SendOnAppRegisteredNotificationToHMI( std::string priority; policy::PolicyHandler::instance()->GetPriority( - application_impl.mobile_app_id()->asString(), &priority); + application_impl.mobile_app_id(), &priority); if (!priority.empty()) { message[strings::msg_params][strings::priority] = GetPriorityCode(priority); } @@ -360,64 +361,38 @@ void MessageHelper::SendOnAppRegisteredNotificationToHMI( 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);; - - 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(); - + static_cast<int32_t>(kNotification); 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(); } } } @@ -425,11 +400,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] = @@ -442,7 +417,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() { @@ -473,6 +453,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( @@ -521,11 +502,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; @@ -538,7 +521,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] = @@ -557,14 +540,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); @@ -582,14 +563,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); @@ -607,15 +585,16 @@ smart_objects::SmartObject* MessageHelper::CreateDeviceListSO( policy::PolicyHandler::instance()->GetUserConsentForDevice(it->second.mac_address()); list_so[index][strings::isSDLAllowed] = policy::DeviceConsent::kDeviceAllowed == device_consent; + ++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); @@ -626,10 +605,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; @@ -646,34 +626,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(); @@ -686,10 +672,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 @@ -699,7 +684,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); @@ -709,13 +694,12 @@ MessageHelper::SmartObjectList MessageHelper::GetIVISubscribtionRequests( return hmi_requests; } -void MessageHelper::SendAppDataToHMI(ApplicationConstSharedPtr app) { - uint32_t id = app->app_id(); - - utils::SharedPtr<smart_objects::SmartObject> set_app_icon( - new smart_objects::SmartObject); +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] = @@ -729,41 +713,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; @@ -806,8 +801,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; @@ -843,10 +838,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; @@ -865,7 +861,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) { @@ -886,10 +883,10 @@ 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; } @@ -897,11 +894,11 @@ smart_objects::SmartObject* MessageHelper::CreateAppVrHelp( 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) { + ApplicationManagerImpl::ApplictionSetConstIt it_app = + accessor.begin(); + for (; accessor.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); @@ -911,7 +908,8 @@ smart_objects::SmartObject* MessageHelper::CreateAppVrHelp( } // 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) { @@ -923,14 +921,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] = @@ -951,10 +953,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)); } @@ -966,14 +968,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] = @@ -993,25 +993,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; @@ -1053,10 +1058,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; } @@ -1079,16 +1085,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()); @@ -1098,7 +1125,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()); @@ -1108,7 +1135,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()); @@ -1122,18 +1149,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; @@ -1170,8 +1196,8 @@ smart_objects::SmartObject* MessageHelper::CreateAddVRCommandToHMI( bool MessageHelper::CreateHMIApplicationStruct(ApplicationConstSharedPtr app, smart_objects::SmartObject& output) { - - if (false == app.valid()) { + if (!app) { + LOG4CXX_WARN(logger_, "Application is not valid"); return false; } @@ -1184,36 +1210,41 @@ bool MessageHelper::CreateHMIApplicationStruct(ApplicationConstSharedPtr app, 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::app_id] = app->hmi_app_id(); output[strings::hmi_display_language_desired] = app->ui_language(); output[strings::is_media_application] = app->is_media_application(); - 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; } 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; @@ -1247,8 +1278,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; } @@ -1264,22 +1295,23 @@ 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); - + hmi_apis::Common_HMILevel::eType level, + bool send_policy_priority) { 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_ActivateApp; (*message)[strings::params][strings::message_type] = MessageType::kRequest; @@ -1287,23 +1319,25 @@ void MessageHelper::SendActivateAppToHMI(uint32_t const app_id, ApplicationManagerImpl::instance()->GetNextHMICorrelationID(); (*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. @@ -1317,17 +1351,17 @@ void MessageHelper::SendActivateAppToHMI(uint32_t const app_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; @@ -1344,7 +1378,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; } @@ -1372,8 +1406,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; } @@ -1418,21 +1452,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; } @@ -1452,8 +1477,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; @@ -1478,8 +1503,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; } @@ -1543,8 +1568,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; } @@ -1584,11 +1609,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] = @@ -1606,9 +1631,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; @@ -1655,8 +1680,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; @@ -1689,8 +1714,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; @@ -1738,8 +1763,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; @@ -1773,11 +1798,10 @@ void MessageHelper::SendAudioStopStream(int32_t connection_key) { 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; @@ -1792,40 +1816,80 @@ 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::urlSchema] = urlSchema; + } else if (!packageName.empty()) { + content[strings::msg_params][strings::packageName] = 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(); + + 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] = @@ -1836,7 +1900,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; @@ -1964,8 +2028,8 @@ 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); + smart_objects::SmartObjectSPtr notification = new smart_objects::SmartObject( + smart_objects::SmartType_Map); if (!notification) { return; } @@ -2002,13 +2066,13 @@ void MessageHelper::SendOnAppPermissionsChangedNotification( permissions.priority); } - 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; } @@ -2025,9 +2089,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; } @@ -2044,11 +2109,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; } @@ -2064,8 +2127,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; } @@ -2090,6 +2153,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; } } @@ -2100,6 +2164,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 { @@ -2110,6 +2175,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; } } @@ -2139,12 +2205,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 += "/"; @@ -2188,15 +2267,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) { @@ -2204,31 +2299,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; } @@ -2237,46 +2328,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; } } @@ -2297,7 +2388,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( |