Icon fix 58/58358/4 devel/ivi submit/devel/ivi/20160202.111127 submit/devel/ivi/20160202.111936
authorTomasz Iwanek <t.iwanek@samsung.com>
Thu, 28 Jan 2016 14:54:56 +0000 (15:54 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Mon, 1 Feb 2016 09:31:50 +0000 (10:31 +0100)
Application icon will be copied to shared/res/ if application->icon refers
to icon from outside of package (some preloaded apps may declare absolute path of icon).

Requires to be submitted with:
 - https://review.tizen.org/gerrit/#/c/58360/

Change-Id: I7cfc8726565a9fb7e65a2d2a3eefe40d20d1edb3

src/tpk/step/step_tpk_patch_icons.cc
src/tpk/step/step_tpk_patch_icons.h
src/tpk/tpk_installer.cc

index 756ca71..39ddb1e 100644 (file)
@@ -4,7 +4,6 @@
 
 #include "tpk/step/step_tpk_patch_icons.h"
 
-#include <boost/filesystem/path.hpp>
 #include <boost/filesystem/operations.hpp>
 #include <boost/system/error_code.hpp>
 #include <common/utils/file_util.h>
@@ -47,28 +46,63 @@ bf::path LocateIcon(const bf::path& filename, const std::string& pkgid,
 namespace tpk {
 namespace filesystem {
 
+common_installer::Step::Status StepTpkPatchIcons::ProcessIconOutsidePackage(
+    const bf::path& common_icon_location, const bf::path& icon_text,
+    application_x* app, icon_x* icon) {
+  bf::path destination = common_icon_location / app->appid;
+  if (!icon_text.extension().empty()) {
+    destination += icon_text.extension();
+  } else {
+    destination += ".png";
+  }
+  if (!common_installer::CopyFile(icon_text, destination)) {
+    return Status::ICON_ERROR;
+  }
+  free(const_cast<char*>(icon->text));
+  icon->text = strdup(destination.c_str());
+  return Status::OK;
+}
+
+common_installer::Step::Status StepTpkPatchIcons::FixIconLocation(
+    const bf::path& icon_text) {
+  bf::path source = LocateIcon(icon_text.filename(),
+                               context_->pkgid.get(),
+                               context_->root_application_path.get(),
+                               context_->uid.get());
+  if (!source.empty()) {
+    LOG(DEBUG) << "Fix location of icon: " << source << " to: " << icon_text;
+    if (!common_installer::CopyFile(source, icon_text)) {
+      return Status::ICON_ERROR;
+    }
+  }
+  return Status::OK;
+}
+
 common_installer::Step::Status StepTpkPatchIcons::process() {
   bf::path common_icon_location = context_->pkg_path.get() / "shared" / "res";
   bs::error_code error;
   bf::create_directories(common_icon_location, error);
   for (application_x* app :
       GListRange<application_x*>(context_->manifest_data.get()->application)) {
-    if (strcmp(app->type, "capp") != 0)
+    if (strcmp(app->type, "capp") != 0 && strcmp(app->type, "jsapp") != 0)
       continue;
     if (app->icon) {
       icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
       bf::path icon_text(icon->text);
-      if (!bf::exists(icon->text)) {
-        bf::path source = LocateIcon(icon_text.filename(),
-                                     context_->pkgid.get(),
-                                     context_->root_application_path.get(),
-                                     context_->uid.get());
-        if (!source.empty()) {
-          LOG(DEBUG) << "Fix location of icon: " << source << " to: "
-                     << icon_text;
-          if (!common_installer::CopyFile(source, icon_text)) {
-            return Status::ICON_ERROR;
-          }
+      if (icon_text.parent_path() != common_icon_location) {
+        // if location of icon was absolute and icon is not in common icon
+        // location, we just need to copy it and replace icon->text to insert
+        // correct information into database
+        Status status = ProcessIconOutsidePackage(common_icon_location,
+                                                  icon_text, app, icon);
+        if (status != Status::OK)
+          return status;
+      } else {
+        // look for icon in different location if it doesn't exist
+        if (!bf::exists(icon->text)) {
+          Status status = FixIconLocation(icon_text);
+          if (status != Status::OK)
+            return status;
         }
       }
     }
index 10fd3c2..556da10 100644 (file)
@@ -5,6 +5,8 @@
 #ifndef TPK_STEP_STEP_TPK_PATCH_ICONS_H_
 #define TPK_STEP_STEP_TPK_PATCH_ICONS_H_
 
+#include <boost/filesystem/path.hpp>
+
 #include <common/step/step.h>
 #include <manifest_parser/utils/logging.h>
 
@@ -25,6 +27,13 @@ class StepTpkPatchIcons : public common_installer::Step {
   Status undo() override { return Status::OK; }
   Status precheck() override { return Status::OK; }
 
+ private:
+  Status ProcessIconOutsidePackage(
+      const boost::filesystem::path& common_icon_location,
+      const boost::filesystem::path& icon_text,
+      application_x* app, icon_x* icon);
+  Status FixIconLocation(const boost::filesystem::path& icon_text);
+
   SCOPE_LOG_TAG(TpkPatchIcons)
 };
 
index feb6735..97674fb 100644 (file)
@@ -215,6 +215,7 @@ void TpkInstaller::ManifestDirectInstallSteps() {
   AddStep<ci::tpk::StepParsePreload>();
   AddStep<ci::security::StepPrivilegeCompatibility>();
   AddStep<tpk::security::StepCheckTpkBackgroundCategory>();
+  AddStep<tpk::filesystem::StepTpkPatchIcons>();
   AddStep<ci::security::StepRollbackInstallationSecurity>();
   AddStep<ci::security::StepRegisterSecurity>();
   AddStep<ci::pkgmgr::StepRegisterApplication>();
@@ -228,6 +229,7 @@ void TpkInstaller::ManifestDirectUpdateSteps() {
   AddStep<ci::tpk::StepParsePreload>();
   AddStep<ci::security::StepPrivilegeCompatibility>();
   AddStep<tpk::security::StepCheckTpkBackgroundCategory>();
+  AddStep<tpk::filesystem::StepTpkPatchIcons>();
   AddStep<ci::pkgmgr::StepKillApps>();
   AddStep<ci::security::StepRollbackInstallationSecurity>();
   AddStep<ci::security::StepRegisterSecurity>();