Set installed storage and external image path when ManifestDirectInstall 06/147206/5
authorSangyoon Jang <jeremy.jang@samsung.com>
Fri, 1 Sep 2017 10:40:23 +0000 (19:40 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Wed, 6 Sep 2017 02:56:44 +0000 (11:56 +0900)
Requires:
 - https://review.tizen.org/gerrit/145167

Change-Id: I3bdeb3c825ef6a0fcb3cc8eb967871dbbd0dc364
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/app2ext_dynamic_service.cc
src/common/app2ext_dynamic_service.h
src/common/step/configuration/step_parse_manifest.cc

index b02e9eb..c2a4e96 100644 (file)
@@ -12,6 +12,7 @@ namespace {
 
 const std::string& disable_pkg_sym_name = "app2ext_usr_enable_external_pkg";
 const std::string& enable_pkg_sym_name = "app2ext_usr_enable_external_pkg";
+const std::string& get_image_path_sym_name = "app2ext_usr_get_image_path";
 const std::string& init_sym_name = "app2ext_init";
 const std::string& deinit_sym_name = "app2ext_deinit";
 const std::string& LIBNAME = "libapp2ext.so.0";
@@ -55,6 +56,18 @@ bool App2ExtDynamicService::DisableExternalPkgForUsr(const char* appname,
   return ret == 0;
 }
 
+std::string App2ExtDynamicService::GetExternalImagePath(const char* pkgid,
+    uid_t uid) {
+  char* image_path = CallMethod<char*>(nullptr, get_image_path_sym_name.c_str(),
+      pkgid, uid);
+  std::string result;
+  if (image_path) {
+    result = std::string(image_path);
+    free(image_path);
+  }
+  return result;
+}
+
 app2ext_handle* App2ExtDynamicService::InitLibrary() {
   return CallMethod<app2ext_handle*>(NULL, init_sym_name.c_str(),
                                      APP2EXT_SD_CARD);
index 4b4e8f9..ea0acac 100644 (file)
@@ -25,6 +25,8 @@ class App2ExtDynamicService final {
 
   bool DisableExternalPkgForUsr(const char* appname, uid_t uid);
 
+  std::string GetExternalImagePath(const char* pkgid, uid_t uid);
+
   bool ProperlyLoaded();
   std::shared_ptr<app2ext_handle> getInterfaceHandle();
 
index 3089f64..0816899 100644 (file)
@@ -36,6 +36,7 @@
 #include <string>
 #include <vector>
 
+#include "common/app2ext_dynamic_service.h"
 #include "common/app_installer.h"
 #include "common/feature_validator.h"
 #include "common/installer_context.h"
@@ -53,6 +54,7 @@ namespace {
 
 const char kManifestFileName[] = "tizen-manifest.xml";
 const char kInstalledInternally[] = "installed_internal";
+const char kInstalledExternally[] = "installed_external";
 const char kPortraitOrientation[] = "portrait";
 const char kLandscapeOrientation[] = "landscape";
 const char kOperationEffectKey[] = "operation_effect";
@@ -247,6 +249,20 @@ bool StepParseManifest::FillPackageInfo(manifest_x* manifest) {
     manifest->type = strdup(pkg_info->type().c_str());
   }
 
+  // Set external path if the package is installed at external storage.
+  if (req_type == RequestType::ManifestDirectInstall ||
+      req_type == RequestType::ManifestDirectUpdate ||
+      req_type == RequestType::ManifestPartialInstall ||
+      req_type == RequestType::ManifestPartialUpdate) {
+    App2ExtDynamicService service;
+    std::string image_path = service.GetExternalImagePath(
+        context_->pkgid.get().c_str(), context_->uid.get());
+    if (!image_path.empty()) {
+      manifest->external_path = strdup(image_path.c_str());
+      manifest->installed_storage = strdup(kInstalledExternally);
+    }
+  }
+
   for (auto& pair : pkg_info->labels()) {
     label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
     if (!label) {
@@ -274,18 +290,20 @@ bool StepParseManifest::FillPackageInfo(manifest_x* manifest) {
   // set installed_storage if package is installed
   // this is internal field in package manager but after reading configuration
   // we must know it
-  if (manifest_location_ == ManifestLocation::INSTALLED ||
-      manifest_location_ == ManifestLocation::RECOVERY) {
-    PkgQueryInterface pkg_query(manifest->package, context_->uid.get());
-    std::string storage = pkg_query.StorageForPkgId();
-    if (storage.empty()) {
+  if (!manifest->installed_storage) {
+    if (manifest_location_ == ManifestLocation::INSTALLED ||
+        manifest_location_ == ManifestLocation::RECOVERY) {
+      PkgQueryInterface pkg_query(manifest->package, context_->uid.get());
+      std::string storage = pkg_query.StorageForPkgId();
+      if (storage.empty()) {
         // Failed to query installation storage, assign internal
         manifest->installed_storage = strdup(kInstalledInternally);
-    } else {
+      } else {
         manifest->installed_storage = strdup(storage.c_str());
+      }
+    } else {
+      manifest->installed_storage = strdup(kInstalledInternally);
     }
-  } else {
-    manifest->installed_storage = strdup(kInstalledInternally);
   }
 
   return true;