Rework main app detection for widget-application 81/61181/3
authorTomasz Iwanek <t.iwanek@samsung.com>
Fri, 4 Mar 2016 09:47:15 +0000 (10:47 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Wed, 9 Mar 2016 11:27:55 +0000 (03:27 -0800)
Requires:
 - https://review.tizen.org/gerrit/61180

Change-Id: I5ac527b6bcb3307b2e58090f6e8828d560e605be

src/common/step/step_parse_manifest.cc
src/common/step/step_parse_manifest.h

index f351cd5..0ff5ab6 100644 (file)
@@ -202,16 +202,17 @@ bool StepParseManifest::FillPackageInfo(manifest_x* manifest) {
                                               strdup(profile.c_str()));
     }
   }
+  return true;
+}
 
-  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());
+bool StepParseManifest::FillPackageMainApp(manifest_x* manifest) {
+  // if no widget-application declared to be main app then take first one
+  if (!manifest->mainapp_id) {
+    application_x* first_app =
+        *GListRange<application_x*>(manifest->application).begin();
+    manifest->mainapp_id = strdup(first_app->appid);
+    free(const_cast<char*>(first_app->mainapp));
+    first_app->mainapp = strdup("true");
   }
   return true;
 }
@@ -276,7 +277,11 @@ bool StepParseManifest::FillWidgetApplication(manifest_x* manifest) {
 
   for (const auto& application : widget_application_list->items) {
     // if there is no app yet, set this app as mainapp
-    bool main_app = manifest->application == nullptr;
+    bool main_app = application.app_info.main() == "true";
+    if (main_app && manifest->mainapp_id) {
+      LOG(ERROR) << "Main application already set";
+      return false;
+    }
 
     application_x* widget_app =
         static_cast<application_x*>(calloc(1, sizeof(application_x)));
@@ -293,7 +298,12 @@ bool StepParseManifest::FillWidgetApplication(manifest_x* manifest) {
         strdup(application.app_info.hwacceleration().c_str());
     widget_app->onboot = strdup("false");
     widget_app->autorestart = strdup("false");
-    widget_app->mainapp = main_app ? strdup("true") : strdup("false");
+    if (main_app) {
+      widget_app->mainapp = strdup("true");
+      manifest->mainapp_id = strdup(widget_app->appid);
+    } else {
+      widget_app->mainapp = strdup("false");
+    }
     widget_app->enabled = strdup("true");
     widget_app->screenreader = strdup("use-system-setting");
     widget_app->recentimage = strdup("false");
@@ -333,9 +343,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 = manifest->application == nullptr;
-
     application_x* service_app =
         static_cast<application_x*>(calloc(1, sizeof(application_x)));
     service_app->appid = strdup(application.app_info.appid().c_str());
@@ -348,7 +355,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("false");
     service_app->enabled = strdup("true");
     service_app->hwacceleration = strdup("default");
     service_app->screenreader = strdup("use-system-setting");
@@ -398,9 +405,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 = manifest->application == nullptr;
-
     application_x* ui_app =
         static_cast<application_x*>(calloc(1, sizeof(application_x)));
     ui_app->appid = strdup(application.app_info.appid().c_str());
@@ -431,7 +435,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("false");
     ui_app->enabled = strdup("true");
     ui_app->screenreader = strdup("use-system-setting");
     ui_app->recentimage = strdup("false");
@@ -748,6 +752,8 @@ bool StepParseManifest::FillManifestX(manifest_x* manifest) {
     return false;
   if (!FillWatchApplication(manifest))
     return false;
+  if (!FillPackageMainApp(manifest))
+    return false;
   if (!FillPrivileges(manifest))
     return false;
   if (!FillAuthorInfo(manifest))
index 0fc6224..fa7f8c3 100644 (file)
@@ -70,6 +70,7 @@ class StepParseManifest : public common_installer::Step {
   bool FillServiceApplication(manifest_x* manifest);
   bool FillUIApplication(manifest_x* manifest);
   bool FillWatchApplication(manifest_x* manifest);
+  bool FillPackageMainApp(manifest_x* manifest);
 
   template <typename T>
       bool FillAppControl(application_x* manifest, const T& app_control_list);