Parse icon for robotapp
[platform/core/appfw/app-installers.git] / src / common / step / configuration / step_parse_manifest.cc
index 2caedf2..a12a8cc 100644 (file)
@@ -4,8 +4,6 @@
 
 #include "common/step/configuration/step_parse_manifest.h"
 
-#include <boost/tokenizer.hpp>
-
 #include <pkgmgr/pkgmgr_parser.h>
 #include <pkgmgr-info.h>
 
@@ -21,6 +19,7 @@
 #include <tpk_manifest_handlers/privileges_handler.h>
 #include <tpk_manifest_handlers/profile_handler.h>
 #include <tpk_manifest_handlers/provides_appdefined_privileges_handler.h>
+#include <tpk_manifest_handlers/robot_application_handler.h>
 #include <tpk_manifest_handlers/service_application_handler.h>
 #include <tpk_manifest_handlers/shortcut_handler.h>
 #include <tpk_manifest_handlers/trust_anchor_handler.h>
@@ -31,7 +30,9 @@
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
+#include <filesystem>
 #include <memory>
+#include <regex>
 #include <set>
 #include <type_traits>
 #include <string>
@@ -48,7 +49,7 @@
 #include "common/utils/time_util.h"
 
 namespace app_keys = tpk::application_keys;
-namespace bf = boost::filesystem;
+namespace fs = std::filesystem;
 
 namespace {
 
@@ -102,26 +103,26 @@ Step::Status StepParseManifest::precheck() {
 }
 
 bool StepParseManifest::LocateConfigFile() {
-  boost::filesystem::path manifest;
+  std::filesystem::path manifest;
   switch (manifest_location_) {
     case ManifestLocation::RECOVERY: {
-      bf::path backup_path = common_installer::GetBackupPathForPackagePath(
+      fs::path backup_path = common_installer::GetBackupPathForPackagePath(
           context_->GetPkgPath()) / kManifestFileName;
-      bf::path in_package_path = context_->GetPkgPath() / kManifestFileName;
-      bf::path install_path =
-          bf::path(getUserManifestPath(context_->uid.get(),
+      fs::path in_package_path = context_->GetPkgPath() / kManifestFileName;
+      fs::path install_path =
+          fs::path(getUserManifestPath(context_->uid.get(),
                       context_->is_readonly_package.get()))
-              / bf::path(context_->pkgid.get());
+              / fs::path(context_->pkgid.get());
       install_path += ".xml";
-      bf::path backup_install_path =
+      fs::path backup_install_path =
           common_installer::GetBackupPathForManifestFile(install_path);
-      if (bf::exists(backup_install_path))
+      if (fs::exists(backup_install_path))
         manifest = backup_install_path;
-      else if (bf::exists(backup_path))
+      else if (fs::exists(backup_path))
         manifest = backup_path;
-      else if (bf::exists(install_path))
+      else if (fs::exists(install_path))
         manifest = install_path;
-      else if (bf::exists(in_package_path))
+      else if (fs::exists(in_package_path))
         manifest = in_package_path;
       break;
     }
@@ -133,13 +134,13 @@ bool StepParseManifest::LocateConfigFile() {
         uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
       else
         uid = context_->uid.get();
-      bf::path xml_path =
-          bf::path(getUserManifestPath(uid, is_readonly))
-          / bf::path(context_->pkgid.get());
+      fs::path xml_path =
+          fs::path(getUserManifestPath(uid, is_readonly))
+          / fs::path(context_->pkgid.get());
       xml_path += ".xml";
       context_->xml_path.set(xml_path);
       manifest = context_->xml_path.get();
-      if (!boost::filesystem::exists(manifest)) {
+      if (!std::filesystem::exists(manifest)) {
         /* This routine has added for platform update */
         manifest = context_->unpacked_dir_path.get();
         manifest /= kManifestFileName;
@@ -159,7 +160,7 @@ bool StepParseManifest::LocateConfigFile() {
 
   LOG(DEBUG) << "manifest path: " << manifest;
 
-  if (!boost::filesystem::exists(manifest))
+  if (!std::filesystem::exists(manifest))
     return false;
 
   path_ = manifest;
@@ -272,8 +273,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);
 
@@ -373,7 +375,7 @@ bool StepParseManifest::FillPrivileges(manifest_x* manifest) {
     privilege->value = strdup(priv.privilege.c_str());
     privilege->type = strdup(priv.type.c_str());
     if (!priv.license.empty()) {
-      if (bf::path(priv.license).is_absolute())
+      if (fs::path(priv.license).is_absolute())
         privilege->license = strdup(priv.license.c_str());
       else
         privilege->license = strdup((context_->GetPkgPath()
@@ -409,7 +411,7 @@ bool StepParseManifest::FillProvidesAppDefinedPrivileges(
     privilege->value = strdup(priv.privilege.c_str());
     privilege->type = strdup(priv.type.c_str());
     if (!priv.license.empty()) {
-      if (bf::path(priv.license).is_absolute())
+      if (fs::path(priv.license).is_absolute())
         privilege->license = strdup(priv.license.c_str());
       else
         privilege->license = strdup((context_->GetPkgPath()
@@ -477,7 +479,7 @@ bool StepParseManifest::FillWidgetApplication(manifest_x* manifest) {
     else
       widget_app->api_version = strdup(manifest->api_version);
     manifest->application = g_list_append(manifest->application, widget_app);
-    if (bf::path(application.app_info.exec().c_str()).is_absolute())
+    if (fs::path(application.app_info.exec().c_str()).is_absolute())
       widget_app->exec = strdup(application.app_info.exec().c_str());
     else
       widget_app->exec = strdup((context_->root_application_path.get()
@@ -553,7 +555,7 @@ bool StepParseManifest::FillServiceApplication(manifest_x* manifest) {
     else
       service_app->api_version = strdup(manifest->api_version);
     manifest->application = g_list_append(manifest->application, service_app);
-    if (bf::path(application.app_info.exec().c_str()).is_absolute())
+    if (fs::path(application.app_info.exec().c_str()).is_absolute())
       service_app->exec = strdup(application.app_info.exec().c_str());
     else
       service_app->exec = strdup((context_->root_application_path.get()
@@ -656,7 +658,7 @@ bool StepParseManifest::FillUIApplication(manifest_x* manifest) {
     else
       ui_app->api_version = strdup(manifest->api_version);
     manifest->application = g_list_append(manifest->application, ui_app);
-    if (bf::path(application.app_info.exec().c_str()).is_absolute())
+    if (fs::path(application.app_info.exec().c_str()).is_absolute())
       ui_app->exec = strdup(application.app_info.exec().c_str());
     else
       ui_app->exec = strdup((context_->root_application_path.get()
@@ -708,7 +710,7 @@ bool StepParseManifest::FillWatchApplication(manifest_x* manifest) {
     }
     watch_app->appid = strdup(watch_application.app_info.appid().c_str());
 
-    if (bf::path(watch_application.app_info.exec().c_str()).is_absolute())
+    if (fs::path(watch_application.app_info.exec().c_str()).is_absolute())
       watch_app->exec = strdup(watch_application.app_info.exec().c_str());
     else
       watch_app->exec = strdup(
@@ -923,8 +925,8 @@ bool StepParseManifest::FillApplicationIconPaths(application_x* app,
       LOG(ERROR) << "Out of memory";
       return false;
     }
-    bf::path text;
-    if (bf::path(application_icon.path()).is_absolute()) {
+    fs::path text;
+    if (fs::path(application_icon.path()).is_absolute()) {
       text = application_icon.path();
     } else {
       text = context_->root_application_path.get()
@@ -1012,11 +1014,11 @@ void StepParseManifest::AppendSplashScreen(application_x* app,
     LOG(ERROR) << "Out of memory";
     return;
   }
-  if (bf::path(src).is_absolute()) {
+  if (fs::path(src).is_absolute()) {
     splashscreen->src = strdup(src.c_str());
   } else {
-    bf::path full_path = context_->GetPkgPath() / src;
-    splashscreen->src = strdup(full_path.string().c_str());
+    fs::path full_path = context_->GetPkgPath() / src;
+    splashscreen->src = strdup(full_path.c_str());
   }
   if (src.substr(src.find_last_of(".") + 1) == "edj")
     splashscreen->type = strdup("edj");
@@ -1052,7 +1054,7 @@ bool StepParseManifest::FillSplashScreen(application_x* app,
     if (context_->is_readonly_package.get())
       src = splash_screen.src();
     else
-      src = bf::path(context_->root_application_path.get()
+      src = fs::path(context_->root_application_path.get()
         / app->package / "shared" / "res" / splash_screen.src()).string();
 
     AppendSplashScreen(app, src, splash_screen.type(), splash_screen.dpi(),
@@ -1092,12 +1094,9 @@ bool StepParseManifest::FillResControl(application_x* app,
 void StepParseManifest::GetLegacySplashScreenFromMetadata(application_x* app,
     const std::string& key, const std::string& val) {
   std::string operation;
-  if (key.find(kOperationEffectKey) != std::string::npos) {
-    boost::char_separator<char> sep("=");
-    boost::tokenizer<boost::char_separator<char>> tokens(key, sep);
-    auto iter = tokens.begin();
-    iter++;
-    operation = *iter;
+  auto pos = key.find(kOperationEffectKey);
+  if (pos != std::string::npos) {
+    operation = key.substr(pos + 1, key.size());
   } else if (key.find(kLaunchEffectKey) != std::string::npos) {
     operation = std::string("launch-effect");
   } else {
@@ -1105,25 +1104,23 @@ void StepParseManifest::GetLegacySplashScreenFromMetadata(application_x* app,
     return;
   }
 
-  boost::char_separator<char> sep("=|");
-  boost::tokenizer<boost::char_separator<char>> tokens(val, sep);
-  auto iter = tokens.begin();
   std::string portrait_src;
   std::string landscape_src;
   std::string indicatordisplay;
-  while (iter != tokens.end()) {
-    if (!(*iter).compare(kPortraitEffectImageValue)) {
-      iter++;
-      portrait_src = *iter;
-    } else if (!(*iter).compare(kLandscapeEffectImageValue)) {
-      iter++;
-      landscape_src = *iter;
-    } else if (!(*iter).compare(kIndicatorDisplayValue)) {
-      iter++;
-      indicatordisplay = *iter;
-    }
-    iter++;
+
+  std::regex re("[=|]");
+  std::sregex_token_iterator first(val.begin(), val.end(), re, -1);
+  std::sregex_token_iterator last;
+  std::vector<std::string> tokens(first, last);
+  for (const auto& t : tokens) {
+    if (t.compare(kPortraitEffectImageValue))
+      portrait_src = t;
+    else if (t.compare(kLandscapeEffectImageValue))
+      landscape_src = t;
+    else if (t.compare(kIndicatorDisplayValue))
+      indicatordisplay = t;
   }
+
   if (!portrait_src.empty())
     AppendSplashScreen(app, portrait_src, {}, {}, kPortraitOrientation,
         indicatordisplay, operation, {});
@@ -1267,7 +1264,7 @@ bool StepParseManifest::FillComponentBasedApplicationInfo(
     app->splash_screen_display =
         strdup(application.app_info.splash_screen_display().c_str());
     manifest->application = g_list_append(manifest->application, app);
-    if (bf::path(application.app_info.exec().c_str()).is_absolute()) {
+    if (fs::path(application.app_info.exec().c_str()).is_absolute()) {
       app->exec = strdup(application.app_info.exec().c_str());
     } else {
       app->exec = strdup((context_->root_application_path.get()
@@ -1297,6 +1294,80 @@ bool StepParseManifest::FillComponentBasedApplicationInfo(
   return true;
 }
 
+bool StepParseManifest::FillRobotApplicationInfo(
+    manifest_x* manifest) {
+  std::shared_ptr<const tpk::parse::RobotApplicationInfoList>
+      robot_application_list = std::static_pointer_cast<
+          const tpk::parse::RobotApplicationInfoList>(
+              parser_->GetManifestData(
+                  app_keys::kRobotApplicationKey));
+  if (!robot_application_list)
+    return true;
+
+  for (const auto& application : robot_application_list->items) {
+    int package_support_mode_val = atoi(manifest->support_mode);
+    int app_support_mode_val = package_support_mode_val |
+        GetSupportModeVal(application.app_info.support_mode());
+
+    application_x* app =
+        static_cast<application_x*>(calloc(1, sizeof(application_x)));
+    if (!app) {
+      LOG(ERROR) << "Out of memory";
+      return false;
+    }
+
+    app->appid = strdup(application.app_info.appid().c_str());
+    app->multiple = strdup("false");
+    app->nodisplay = strdup("false");
+    app->support_mode = strdup((std::to_string(app_support_mode_val)).c_str());
+    app->taskmanage = strdup("false");
+    if (!application.app_info.type().empty())
+      app->type = strdup(application.app_info.type().c_str());
+    else
+      app->type = strdup("robotapp");
+    app->indicatordisplay = strdup("false");
+    app->component_type = strdup("robotapp");
+    app->hwacceleration = strdup("default");
+    app->onboot = strdup("false");
+    app->autorestart = strdup("false");
+    app->mainapp = strdup(application.app_info.mainapp().c_str());
+    app->screenreader = strdup("use-system-setting");
+    app->recentimage = strdup("false");
+    app->launchcondition = strdup("false");
+    app->guestmode_visibility = strdup("true");
+    app->permission_type = strdup("normal");
+    app->support_ambient = strdup("false");
+    app->effectimage_type = strdup("image");
+    app->submode = strdup("false");
+    app->process_pool = strdup("false");
+    app->package = strdup(manifest->package);
+    app->support_disable = strdup(manifest->support_disable);
+    app->launch_mode = strdup("single");
+    if (!application.app_info.api_version().empty())
+      app->api_version = strdup(application.app_info.api_version().c_str());
+    else
+      app->api_version = strdup(manifest->api_version);
+    manifest->application = g_list_append(manifest->application, app);
+    if (fs::path(application.app_info.exec().c_str()).is_absolute()) {
+      app->exec = strdup(application.app_info.exec().c_str());
+    } else {
+      app->exec = strdup((context_->root_application_path.get()
+                          / manifest->package / "bin"
+                          / application.app_info.exec()).c_str());
+    }
+    if (!FillApplicationIconPaths(app, application.app_icons))
+      return false;
+    if (!FillLabel(app, application.label))
+      return false;
+    if (!FillMetadata(app, application.meta_data))
+      return false;
+    if (!FillResControl(app, application.res_controls))
+      return false;
+  }
+
+  return true;
+}
+
 bool StepParseManifest::FillManifestX(manifest_x* manifest) {
   if (!FillPackageInfo(manifest))
     return false;
@@ -1312,6 +1383,8 @@ bool StepParseManifest::FillManifestX(manifest_x* manifest) {
     return false;
   if (!FillComponentBasedApplicationInfo(manifest))
     return false;
+  if (!FillRobotApplicationInfo(manifest))
+    return false;
   if (!FillPrivileges(manifest))
     return false;
   if (!FillProvidesAppDefinedPrivileges(manifest))
@@ -1347,7 +1420,7 @@ Step::Status StepParseManifest::process() {
   if (!parser_->ParseManifest(path_)) {
     if (manifest_location_ == ManifestLocation::RECOVERY) {
       LOG(DEBUG) << "Manifest for recovery is invalid";
-      bf::remove(path_);
+      fs::remove(path_);
       return Step::Status::OK;
     }
     LOG(ERROR) << "[Parse] Parse failed. " <<  parser_->GetErrorMessage();