Fix backup plugin execution information
[platform/core/appfw/app-installers.git] / src / common / step / configuration / step_parse_manifest.cc
index d47feda..39a3341 100644 (file)
@@ -9,13 +9,14 @@
 #include <pkgmgr/pkgmgr_parser.h>
 #include <pkgmgr-info.h>
 
-#include <tpk_manifest_handlers/common/appdefined_privilege_handler.h>
+#include <tpk_manifest_handlers/appdefined_privilege_handler.h>
 #include <tpk_manifest_handlers/application_manifest_constants.h>
 #include <tpk_manifest_handlers/author_handler.h>
 #include <tpk_manifest_handlers/component_based_application_handler.h>
 #include <tpk_manifest_handlers/dependencies_handler.h>
 #include <tpk_manifest_handlers/description_handler.h>
 #include <tpk_manifest_handlers/feature_handler.h>
+#include <tpk_manifest_handlers/light_user_handler.h>
 #include <tpk_manifest_handlers/package_handler.h>
 #include <tpk_manifest_handlers/privileges_handler.h>
 #include <tpk_manifest_handlers/profile_handler.h>
@@ -27,7 +28,6 @@
 #include <tpk_manifest_handlers/watch_application_handler.h>
 #include <tpk_manifest_handlers/widget_application_handler.h>
 
-#include <chrono>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 
 #include "common/feature_validator.h"
 #include "common/installer_context.h"
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/privileges.h"
 #include "common/pkgmgr_registration.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/step/step.h"
 #include "common/utils/glist_range.h"
+#include "common/utils/time_util.h"
 
 namespace app_keys = tpk::application_keys;
 namespace bf = boost::filesystem;
@@ -112,12 +113,16 @@ bool StepParseManifest::LocateConfigFile() {
                       context_->is_readonly_package.get()))
               / bf::path(context_->pkgid.get());
       install_path += ".xml";
-      if (bf::exists(backup_path))
+      bf::path backup_install_path =
+          common_installer::GetBackupPathForManifestFile(install_path);
+      if (bf::exists(backup_install_path))
+        manifest = backup_install_path;
+      else if (bf::exists(backup_path))
         manifest = backup_path;
-      else if (bf::exists(in_package_path))
-        manifest = in_package_path;
       else if (bf::exists(install_path))
         manifest = install_path;
+      else if (bf::exists(in_package_path))
+        manifest = in_package_path;
       break;
     }
     case ManifestLocation::INSTALLED: {
@@ -183,9 +188,7 @@ int StepParseManifest::GetSupportModeVal(std::string support_mode) {
 bool StepParseManifest::FillInstallationInfo(manifest_x* manifest) {
   manifest->root_path = strdup(
       (context_->root_application_path.get() / manifest->package).c_str());
-  manifest->installed_time =
-      strdup(std::to_string(std::chrono::system_clock::to_time_t(
-          std::chrono::system_clock::now())).c_str());
+  manifest->installed_time = strdup(GetCurrentTime().c_str());
   return true;
 }
 
@@ -198,34 +201,6 @@ bool StepParseManifest::FillPackageInfo(manifest_x* manifest) {
     return false;
   }
 
-  auto ui_application_list =
-      std::static_pointer_cast<const tpk::parse::UIApplicationInfoList>(
-          parser_->GetManifestData(app_keys::kUIApplicationKey));
-  auto service_application_list =
-      std::static_pointer_cast<const tpk::parse::ServiceApplicationInfoList>(
-          parser_->GetManifestData(app_keys::kServiceApplicationKey));
-  auto widget_application_list =
-      std::static_pointer_cast<const tpk::parse::WidgetApplicationInfoList>(
-          parser_->GetManifestData(app_keys::kWidgetApplicationKey));
-  auto watch_application_list =
-      std::static_pointer_cast<const tpk::parse::WatchApplicationInfoList>(
-          parser_->GetManifestData(app_keys::kWatchApplicationKey));
-  auto component_based_application_list =
-      std::static_pointer_cast<
-          const tpk::parse::ComponentBasedApplicationInfoList>(
-              parser_->GetManifestData(
-                  app_keys::kComponentBasedApplicationKey));
-
-  // mandatory check
-  if (!ui_application_list && !service_application_list &&
-      !widget_application_list && !watch_application_list &&
-      !component_based_application_list) {
-    LOG(ERROR) << "UI Application or Service Application or Widget Application "
-                  "or Watch Application or Component-Based Application "
-                  "are mandatory and has not been found.";
-    return false;
-  }
-
   int support_mode_val = GetSupportModeVal(pkg_info->support_mode());
 
   manifest->ns = strdup(pkg_info->xmlns().c_str());
@@ -297,8 +272,9 @@ bool StepParseManifest::FillPackageInfo(manifest_x* manifest) {
   }
 
   // retrieve and set plugin execution info if exists
-  if (manifest_location_ == ManifestLocation::INSTALLED ||
-      manifest_location_ == ManifestLocation::RECOVERY) {
+  if (store_location_ == StoreLocation::BACKUP && (
+      manifest_location_ == ManifestLocation::INSTALLED ||
+      manifest_location_ == ManifestLocation::RECOVERY)) {
     std::vector<PkgQueryInterface::PluginInfo> plugin_list;
     pkg_query.PluginExecutionInfo(&plugin_list);
 
@@ -519,6 +495,8 @@ bool StepParseManifest::FillWidgetApplication(manifest_x* manifest) {
       return false;
     if (!FillMetadata(widget_app, application.meta_data))
       return false;
+    if (!FillResControl(widget_app, application.res_controls))
+      return false;
   }
   return true;
 }
@@ -553,8 +531,6 @@ bool StepParseManifest::FillServiceApplication(manifest_x* manifest) {
       service_app->type = strdup(application.app_info.type().c_str());
     else
       service_app->type = strdup("capp");
-    service_app->process_pool =
-        strdup(application.app_info.process_pool().c_str());
     service_app->component_type = strdup("svcapp");
     service_app->mainapp = strdup(application.app_info.mainapp().c_str());
     service_app->nodisplay = strdup("true");
@@ -600,6 +576,8 @@ bool StepParseManifest::FillServiceApplication(manifest_x* manifest) {
     if (!FillBackgroundCategoryInfo(service_app,
         application.background_category))
       return false;
+    if (!FillResControl(service_app, application.res_controls))
+      return false;
   }
   return true;
 }
@@ -705,6 +683,8 @@ bool StepParseManifest::FillUIApplication(manifest_x* manifest) {
       return false;
     if (!FillSplashScreen(ui_app, application.app_splashscreens))
       return false;
+    if (!FillResControl(ui_app, application.res_controls))
+      return false;
   }
   return true;
 }
@@ -773,6 +753,7 @@ bool StepParseManifest::FillWatchApplication(manifest_x* manifest) {
     if (!watch_application.app_info.setup_appid().empty())
       watch_app->setup_appid =
           strdup(watch_application.app_info.setup_appid().c_str());
+    manifest->application = g_list_append(manifest->application, watch_app);
 
     if (!FillLabel(watch_app, watch_application.label))
       return false;
@@ -785,7 +766,8 @@ bool StepParseManifest::FillWatchApplication(manifest_x* manifest) {
     if (!FillBackgroundCategoryInfo(watch_app,
         watch_application.background_category))
       return false;
-    manifest->application = g_list_append(manifest->application, watch_app);
+    if (!FillResControl(watch_app, watch_application.res_controls))
+      return false;
   }
   return true;
 }
@@ -832,6 +814,26 @@ bool StepParseManifest::FillDependencyInfo(manifest_x* manifest) {
   return true;
 }
 
+bool StepParseManifest::FillLightUserInfo(manifest_x* manifest) {
+  std::shared_ptr<const tpk::parse::LightUserInfo> light_user_info =
+      std::static_pointer_cast<const tpk::parse::LightUserInfo>(
+          parser_->GetManifestData(tpk::parse::LightUserInfo::Key()));
+  if (!light_user_info) {
+    manifest->light_user_switch_mode = strdup("default");
+    return true;
+  }
+
+  if (light_user_info->switch_mode().empty()) {
+    LOG(ERROR) << "Invalid switch mode";
+    return false;
+  }
+
+  manifest->light_user_switch_mode =
+      strdup(light_user_info->switch_mode().c_str());
+
+  return true;
+}
+
 bool StepParseManifest::CheckFeatures() {
   auto feature_info =
         std::static_pointer_cast<const tpk::parse::FeatureInfo>(
@@ -1061,6 +1063,33 @@ bool StepParseManifest::FillSplashScreen(application_x* app,
   return true;
 }
 
+template <typename T>
+bool StepParseManifest::FillResControl(application_x* app,
+    const T& res_control_list) {
+  for (auto& res_control : res_control_list) {
+    if (res_control.resource_type().empty())
+      continue;
+
+    res_control_x* rc =
+        static_cast<res_control_x*>(calloc(1, sizeof(res_control_x)));
+    if (!rc) {
+      LOG(ERROR) << "Out of memory";
+      return false;
+    }
+
+    rc->res_type = strdup(res_control.resource_type().c_str());
+    if (!res_control.min_res_version().empty())
+      rc->min_res_version = strdup(res_control.min_res_version().c_str());
+    if (!res_control.max_res_version().empty())
+      rc->max_res_version = strdup(res_control.max_res_version().c_str());
+    if (!res_control.auto_close().empty())
+      rc->auto_close = strdup(res_control.auto_close().c_str());
+
+    app->res_control = g_list_prepend(app->res_control, rc);
+  }
+  return true;
+}
+
 void StepParseManifest::GetLegacySplashScreenFromMetadata(application_x* app,
     const std::string& key, const std::string& val) {
   std::string operation;
@@ -1150,6 +1179,9 @@ bool StepParseManifest::FillExtraInfo(manifest_x* manifest) {
       manifest->zip_mount_file = strdup(zip_mount_file.c_str());
   }
 
+  if (manifest->application == nullptr)
+    return true;
+
   // in case of hybrid package, main app is already set by wgt-backend
   application_x* mainapp = nullptr;
   if (!context_->cross_app_rules.get()) {
@@ -1259,6 +1291,8 @@ bool StepParseManifest::FillComponentBasedApplicationInfo(
       return false;
     if (!FillSplashScreen(app, application.app_splashscreens))
       return false;
+    if (!FillResControl(app, application.res_controls))
+      return false;
   }
 
   return true;
@@ -1293,6 +1327,8 @@ bool StepParseManifest::FillManifestX(manifest_x* manifest) {
     return false;
   if (!FillDependencyInfo(manifest))
     return false;
+  if (!FillLightUserInfo(manifest))
+    return false;
   return true;
 }