diff options
Diffstat (limited to 'src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc')
-rw-r--r-- | src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc index b2363e870f..ed77d8a550 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc @@ -60,6 +60,14 @@ SetAppIconRequest::SetAppIconRequest( , is_icons_saving_enabled_(false) { const std::string path = application_manager_.get_settings().app_icons_folder(); + + if (!file_system::DirectoryExists(path)) { + LOG4CXX_WARN(logger_, "App icons folder doesn't exist."); + if (!file_system::CreateDirectoryRecursively(path)) { + LOG4CXX_ERROR(logger_, "Unable to create app icons directory: " << path); + } + } + is_icons_saving_enabled_ = file_system::IsWritingAllowed(path) && file_system::IsReadingAllowed(path); } @@ -106,25 +114,22 @@ void SetAppIconRequest::Run() { msg_params[strings::sync_file_name] = smart_objects::SmartObject(smart_objects::SmartType_Map); - // Panasonic requres unchanged path value without encoded special characters - const std::string full_file_path_for_hmi = - file_system::ConvertPathForURL(full_file_path); + // For further use in on_event function + full_file_path_for_hmi_ = file_system::ConvertPathForURL(full_file_path); - msg_params[strings::sync_file_name][strings::value] = full_file_path_for_hmi; + msg_params[strings::sync_file_name][strings::value] = full_file_path_for_hmi_; // TODO(VS): research why is image_type hardcoded msg_params[strings::sync_file_name][strings::image_type] = static_cast<int32_t>(SetAppIconRequest::ImageType::DYNAMIC); - // for further use in on_event function - (*message_)[strings::msg_params][strings::sync_file_name] = - msg_params[strings::sync_file_name]; StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_SetAppIcon, &msg_params, true); } void SetAppIconRequest::CopyToIconStorage( - const std::string& path_to_file) const { + const std::string& policy_app_id, const std::string& path_to_file) const { + LOG4CXX_AUTO_TRACE(logger_); if (!(application_manager_.protocol_handler() .get_settings() .max_supported_protocol_version() >= @@ -146,6 +151,11 @@ void SetAppIconRequest::CopyToIconStorage( application_manager_.get_settings().app_icons_folder_max_size()); const uint64_t file_size = file_system::FileSize(path_to_file); + if (0 == file_size) { + LOG4CXX_ERROR(logger_, "Can't get the icon file size: " << path_to_file); + return; + } + if (storage_max_size < file_size) { LOG4CXX_ERROR(logger_, "Icon size (" << file_size @@ -159,6 +169,7 @@ void SetAppIconRequest::CopyToIconStorage( const uint64_t storage_size = static_cast<uint64_t>(file_system::DirectorySize(icon_storage)); + if (storage_max_size < (file_size + storage_size)) { const uint32_t icons_amount = application_manager_.get_settings().app_icons_amount_to_remove(); @@ -174,23 +185,15 @@ void SetAppIconRequest::CopyToIconStorage( RemoveOldestIcons(icon_storage, icons_amount); } } - ApplicationConstSharedPtr app = - application_manager_.application(connection_key()); - if (!app) { - LOG4CXX_ERROR( - logger_, - "Can't get application for connection key: " << connection_key()); - return; - } + const std::string icon_path = icon_storage + "/" + policy_app_id; - const std::string icon_path = icon_storage + "/" + app->policy_app_id(); if (!file_system::CreateFile(icon_path)) { LOG4CXX_ERROR(logger_, "Can't create icon: " << icon_path); return; } - if (!file_system::Write(icon_path, file_content)) { + if (!file_system::WriteBinaryFile(icon_path, file_content)) { LOG4CXX_ERROR(logger_, "Can't write icon: " << icon_path); return; } @@ -266,21 +269,19 @@ void SetAppIconRequest::on_event(const event_engine::Event& event) { ApplicationSharedPtr app = application_manager_.application(connection_key()); - if ((message_.use_count() == 0) || (app.use_count() == 0)) { - LOG4CXX_ERROR(logger_, "NULL pointer."); + if (!app) { + LOG4CXX_ERROR( + logger_, + "Can't get application for connection key: " << connection_key()); return; } - const std::string& path = - (*message_)[strings::msg_params][strings::sync_file_name] - [strings::value] - .asString(); - - if (is_icons_saving_enabled_) { - CopyToIconStorage(path); + if (is_icons_saving_enabled_ && !full_file_path_for_hmi_.empty()) { + const auto policy_app_id = app->policy_app_id(); + CopyToIconStorage(policy_app_id, full_file_path_for_hmi_); } - app->set_app_icon_path(path); + app->set_app_icon_path(full_file_path_for_hmi_); LOG4CXX_INFO(logger_, "Icon path was set to '" << app->app_icon_path() << "'"); |