Fix setting mainapp attribute 80/105780/4
authorSangyoon Jang <s89.jang@samsung.com>
Mon, 19 Dec 2016 11:37:03 +0000 (20:37 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Tue, 20 Dec 2016 07:42:36 +0000 (16:42 +0900)
Use parsed mainapp first, but if there is no parsed mainapp, take first
app as mainapp.

Requires:
 - https://review.tizen.org/gerrit/106007

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

index b1edd268c42a3aa90a41ef1f71f78f817f5523b9..b51ec2b6628cc85ca7679a654ad39463102f18e7 100644 (file)
@@ -287,19 +287,6 @@ bool StepParseManifest::FillPackageInfo(manifest_x* manifest) {
     manifest->installed_storage = strdup(kInstalledInternally);
   }
 
-  if (ui_application_list) {
-    manifest->mainapp_id =
-        strdup(ui_application_list->items[0].app_info.appid().c_str());
-  } else if (service_application_list) {
-    manifest->mainapp_id =
-        strdup(service_application_list->items[0].app_info.appid().c_str());
-  } else if (widget_application_list) {
-    manifest->mainapp_id =
-        strdup(widget_application_list->items[0].app_info.appid().c_str());
-  } else if (watch_application_list) {
-    manifest->mainapp_id =
-        strdup(watch_application_list->items[0].app_info.appid().c_str());
-  }
   return true;
 }
 
@@ -363,20 +350,8 @@ bool StepParseManifest::FillWidgetApplication(manifest_x* manifest) {
           parser_->GetManifestData(app_keys::kWidgetApplicationKey));
   if (!widget_application_list)
     return true;
-  int mainapps = std::count_if(widget_application_list->items.begin(),
-          widget_application_list->items.end(),
-          [](const tpk::parse::WidgetApplicationSingleEntry& app) {
-            return app.app_info.main() == "true";
-          });
-  if (mainapps > 1)  // only one main app is permitted
-      return false;
 
   for (const auto& application : widget_application_list->items) {
-    // if there is no app yet and not hybrid package installation,
-    // set this app as mainapp
-    bool main_app = (context_->cross_app_rules.get() == false &&
-        manifest->application == nullptr);
-
     int package_support_mode_val = atoi(manifest->support_mode);
     int app_support_mode_val = package_support_mode_val |
         GetSupportModeVal(application.app_info.support_mode());
@@ -399,11 +374,7 @@ bool StepParseManifest::FillWidgetApplication(manifest_x* manifest) {
         strdup(application.app_info.hwacceleration().c_str());
     widget_app->onboot = strdup("false");
     widget_app->autorestart = strdup("false");
-    if (mainapps == 1) {
-        widget_app->mainapp = strdup(application.app_info.main().c_str());
-    } else {
-        widget_app->mainapp = main_app ? strdup("true") : strdup("false");
-    }
+    widget_app->mainapp = strdup(application.app_info.mainapp().c_str());
     widget_app->enabled = strdup("true");
     widget_app->screenreader = strdup("use-system-setting");
     widget_app->recentimage = strdup("false");
@@ -449,10 +420,6 @@ bool StepParseManifest::FillServiceApplication(manifest_x* manifest) {
     return true;
 
   for (const auto& application : service_application_list->items) {
-    // if there is no app yet, set this app as mainapp
-    bool main_app = (context_->cross_app_rules.get() == false &&
-        manifest->application == nullptr);
-
     int package_support_mode_val = atoi(manifest->support_mode);
     int app_support_mode_val = package_support_mode_val |
         GetSupportModeVal(application.app_info.support_mode());
@@ -471,7 +438,7 @@ bool StepParseManifest::FillServiceApplication(manifest_x* manifest) {
     service_app->process_pool =
         strdup(application.app_info.process_pool().c_str());
     service_app->component_type = strdup("svcapp");
-    service_app->mainapp = main_app ? strdup("true") : strdup("false");
+    service_app->mainapp = strdup(application.app_info.mainapp().c_str());
     service_app->enabled = strdup("true");
     service_app->nodisplay = strdup("true");
     service_app->hwacceleration = strdup("default");
@@ -522,10 +489,6 @@ bool StepParseManifest::FillUIApplication(manifest_x* manifest) {
     return true;
 
   for (const auto& application : ui_application_list->items) {
-    // if there is no app yet, set this app as mainapp
-    bool main_app = (context_->cross_app_rules.get() == false &&
-        manifest->application == nullptr);
-
     int package_support_mode_val = atoi(manifest->support_mode);
     int app_support_mode_val = package_support_mode_val |
         GetSupportModeVal(application.app_info.support_mode());
@@ -570,7 +533,7 @@ bool StepParseManifest::FillUIApplication(manifest_x* manifest) {
     ui_app->onboot = strdup("false");
     ui_app->autorestart = strdup("false");
     ui_app->component_type = strdup("uiapp");
-    ui_app->mainapp = main_app ? strdup("true") : strdup("false");
+    ui_app->mainapp = strdup(application.app_info.mainapp().c_str());
     ui_app->enabled = strdup("true");
     ui_app->screenreader = strdup("use-system-setting");
     ui_app->recentimage = strdup("false");
@@ -621,9 +584,6 @@ bool StepParseManifest::FillWatchApplication(manifest_x* manifest) {
     return true;
 
   for (const auto& watch_application : watch_application_list->items) {
-    bool main_app = (context_->cross_app_rules.get() == false &&
-        manifest->application == nullptr);
-
     int package_support_mode_val = atoi(manifest->support_mode);
     int app_support_mode_val = package_support_mode_val |
         GetSupportModeVal(watch_application.app_info.support_mode());
@@ -646,7 +606,7 @@ bool StepParseManifest::FillWatchApplication(manifest_x* manifest) {
     watch_app->enabled = strdup("true");
     watch_app->hwacceleration = strdup("default");
     watch_app->screenreader = strdup("use-system-setting");
-    watch_app->mainapp = main_app ? strdup("true") : strdup("false");
+    watch_app->mainapp = strdup(watch_application.app_info.mainapp().c_str());
     watch_app->recentimage = strdup("false");
     watch_app->launchcondition = strdup("false");
     watch_app->indicatordisplay = strdup("true");
@@ -955,6 +915,49 @@ bool StepParseManifest::FillBackgroundCategoryInfo(application_x* app,
   return true;
 }
 
+bool StepParseManifest::FillExtraInfo(manifest_x* manifest) {
+  if (manifest_location_ == ManifestLocation::INSTALLED) {
+    // recovery of tep value for installed package
+    std::string old_tep =
+        QueryTepPath(context_->pkgid.get(), context_->uid.get());
+    if (!old_tep.empty())
+      manifest->tep_name = strdup(old_tep.c_str());
+
+    // recovery of zip mount file for installed package
+    std::string zip_mount_file =
+        QueryZipMountFile(context_->pkgid.get(), context_->uid.get());
+    if (!zip_mount_file.empty())
+      manifest->zip_mount_file = strdup(zip_mount_file.c_str());
+  }
+
+  // in case of hybrid package, main app is already set by wgt-backend
+  application_x* mainapp = nullptr;
+  if (!context_->cross_app_rules.get()) {
+    // find mainapp
+    for (const auto& app : GListRange<application_x*>(manifest->application)) {
+      if (!strcmp(app->mainapp, "true")) {
+        mainapp = app;
+        break;
+      }
+    }
+    if (mainapp == nullptr)
+      mainapp = reinterpret_cast<application_x*>(
+          g_list_first(manifest->application)->data);
+    free(mainapp->mainapp);
+    mainapp->mainapp = strdup("true");
+    manifest->mainapp_id = strdup(mainapp->appid);
+  }
+
+  // mark mainapp=false at other apps
+  for (auto& app : GListRange<application_x*>(manifest->application)) {
+    if (app == mainapp)
+      continue;
+    free(app->mainapp);
+    app->mainapp = strdup("false");
+  }
+  return true;
+}
+
 bool StepParseManifest::FillManifestX(manifest_x* manifest) {
   if (!FillPackageInfo(manifest))
     return false;
@@ -974,6 +977,8 @@ bool StepParseManifest::FillManifestX(manifest_x* manifest) {
     return false;
   if (!FillDescriptionInfo(manifest))
     return false;
+  if (!FillExtraInfo(manifest))
+    return false;
   return true;
 }
 
@@ -1013,20 +1018,6 @@ Step::Status StepParseManifest::process() {
     return Step::Status::PARSE_ERROR;
   }
 
-  if (manifest_location_ == ManifestLocation::INSTALLED) {
-    // recovery of tep value for installed package
-    std::string old_tep =
-        QueryTepPath(context_->pkgid.get(), context_->uid.get());
-    if (!old_tep.empty())
-      manifest->tep_name = strdup(old_tep.c_str());
-
-    // recovery of zip mount file for installed package
-    std::string zip_mount_file =
-        QueryZipMountFile(context_->pkgid.get(), context_->uid.get());
-    if (!zip_mount_file.empty())
-      manifest->zip_mount_file = strdup(zip_mount_file.c_str());
-  }
-
   // write pkgid for recovery file
   if (context_->recovery_info.get().recovery_file) {
     context_->recovery_info.get().recovery_file->set_pkgid(manifest->package);
index 7bd8d5864c096df6d5e17c0059deb53442517b85..858bea603c2a04e4cb3d0bb0dd95eb1c9fcf83cf 100644 (file)
@@ -103,6 +103,7 @@ class StepParseManifest : public common_installer::Step {
   template <typename T>
   bool FillSplashScreen(application_x* app,
       const T& splashscreen_list);
+  bool FillExtraInfo(manifest_x* manifest);
   bool FillManifestX(manifest_x* manifest);
 
   std::unique_ptr<tpk::parse::TPKConfigParser> parser_;