summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndriy Byzhynar <abyzhynar@luxoft.com>2019-12-06 16:05:16 +0200
committerAndriy Byzhynar <abyzhynar@luxoft.com>2019-12-06 16:06:08 +0200
commit6eb1e5774dde538b3e1021b9320e000114b978b8 (patch)
tree84842057ef81aa715eea136deb26888a5133c726
parent4758fd3d953b4c3531fdfdab27baf8505cd75f78 (diff)
downloadsdl_core-fix/SDL_crash_during_SetAppIcon.tar.gz
Rework SetAppIcon requestfix/SDL_crash_during_SetAppIcon
Update SetAppIcon request according to the changes in file system
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_app_icon_request.h9
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc54
2 files changed, 34 insertions, 29 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_app_icon_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_app_icon_request.h
index 86ca2fb126..520f27d8b9 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_app_icon_request.h
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/set_app_icon_request.h
@@ -83,9 +83,11 @@ class SetAppIconRequest : public app_mngr::commands::CommandRequestImpl {
private:
/**
* @brief Copies file to icon storage
+ * @param policy_app_id application policy app id
* @param path_to_file Path to icon
*/
- void CopyToIconStorage(const std::string& path_to_file) const;
+ void CopyToIconStorage(const std::string& policy_app_id,
+ const std::string& path_to_file) const;
/**
* @brief Remove oldest icons
@@ -108,6 +110,11 @@ class SetAppIconRequest : public app_mngr::commands::CommandRequestImpl {
* @brief Checks, if icons saving to configured folder is enabled
*/
bool is_icons_saving_enabled_;
+
+ /**
+ * @brief Contains full file path to icon
+ */
+ std::string full_file_path_for_hmi_;
};
} // namespace commands
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..acf312d532 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
@@ -106,25 +106,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 +143,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 +161,12 @@ void SetAppIconRequest::CopyToIconStorage(
const uint64_t storage_size =
static_cast<uint64_t>(file_system::DirectorySize(icon_storage));
+
+ if (0 == storage_size) {
+ LOG4CXX_ERROR(logger_, "Can't get the folder size: " << icon_storage);
+ return;
+ }
+
if (storage_max_size < (file_size + storage_size)) {
const uint32_t icons_amount =
application_manager_.get_settings().app_icons_amount_to_remove();
@@ -174,23 +182,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 +266,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() << "'");