Generate widget element in platform manifest 37/71237/6
authorTomasz Iwanek <t.iwanek@samsung.com>
Tue, 24 May 2016 09:18:41 +0000 (11:18 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Wed, 25 May 2016 11:56:58 +0000 (04:56 -0700)
To verify, install widget with appwidget and:
 - check information generated in manifest file,
 - check creation of symlink for widgets in bin/ directory,
 - check preview icons in shared/res/ directory.

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

Change-Id: I2a38aaee729c4c1f18200d2f63764c4c87e7d730

src/hybrid/hybrid_installer.cc
src/wgt/CMakeLists.txt
src/wgt/step/configuration/step_parse.cc
src/wgt/step/configuration/step_parse.h
src/wgt/step/filesystem/step_copy_preview_icons.cc [new file with mode: 0644]
src/wgt/step/filesystem/step_copy_preview_icons.h [new file with mode: 0644]
src/wgt/step/filesystem/step_create_symbolic_link.cc
src/wgt/step/filesystem/step_create_symbolic_link.h
src/wgt/step/pkgmgr/step_generate_xml.cc
src/wgt/wgt_backend_data.h
src/wgt/wgt_installer.cc

index c2d1aa6..dd56988 100644 (file)
@@ -63,6 +63,7 @@
 #include "wgt/step/configuration/step_parse.h"
 #include "wgt/step/configuration/step_parse_recovery.h"
 #include "wgt/step/encryption/step_remove_encryption_data.h"
+#include "wgt/step/filesystem/step_copy_preview_icons.h"
 #include "wgt/step/filesystem/step_create_symbolic_link.h"
 #include "wgt/step/filesystem/step_wgt_patch_icons.h"
 #include "wgt/step/filesystem/step_wgt_patch_storage_directories.h"
@@ -104,6 +105,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr)
       AddStep<tpk::filesystem::StepTpkPatchIcons>();
       AddStep<wgt::filesystem::StepWgtPatchIcons>();
       AddStep<ci::filesystem::StepCreateIcons>();
+      AddStep<wgt::filesystem::StepCopyPreviewIcons>();
       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
       AddStep<ci::filesystem::StepCreateStorageDirectories>();
       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
@@ -146,6 +148,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr)
       AddStep<tpk::filesystem::StepTpkPatchIcons>();
       AddStep<wgt::filesystem::StepWgtPatchIcons>();
       AddStep<ci::filesystem::StepCreateIcons>();
+      AddStep<wgt::filesystem::StepCopyPreviewIcons>();
       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
       AddStep<ci::filesystem::StepCopyStorageDirectories>();
       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
@@ -209,6 +212,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr)
       AddStep<tpk::filesystem::StepTpkPatchIcons>();
       AddStep<wgt::filesystem::StepWgtPatchIcons>();
       AddStep<ci::filesystem::StepCreateIcons>();
+      AddStep<wgt::filesystem::StepCopyPreviewIcons>();
       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
       AddStep<ci::filesystem::StepCopyStorageDirectories>();
       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
@@ -264,6 +268,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr)
       AddStep<tpk::filesystem::StepTpkPatchIcons>();
       AddStep<wgt::filesystem::StepWgtPatchIcons>();
       AddStep<ci::filesystem::StepCreateIcons>();
+      AddStep<wgt::filesystem::StepCopyPreviewIcons>();
       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
       AddStep<ci::filesystem::StepCreateStorageDirectories>();
       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
@@ -307,6 +312,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr)
       AddStep<tpk::filesystem::StepTpkPatchIcons>();
       AddStep<wgt::filesystem::StepWgtPatchIcons>();
       AddStep<ci::filesystem::StepCreateIcons>();
+      AddStep<wgt::filesystem::StepCopyPreviewIcons>();
       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
       AddStep<tpk::filesystem::StepCreateSymbolicLink>();
index 1542e28..c160de9 100644 (file)
@@ -5,6 +5,7 @@ SET(SRCS
   step/configuration/step_parse_recovery.cc
   step/encryption/step_encrypt_resources.cc
   step/encryption/step_remove_encryption_data.cc
+  step/filesystem/step_copy_preview_icons.cc
   step/filesystem/step_create_symbolic_link.cc
   step/filesystem/step_wgt_patch_icons.cc
   step/filesystem/step_wgt_patch_storage_directories.cc
index c438598..0b9f251 100644 (file)
@@ -468,6 +468,19 @@ bool StepParse::FillMetadata(manifest_x* manifest) {
   return true;
 }
 
+bool StepParse::FillAppWidget() {
+  WgtBackendData* backend_data =
+      static_cast<WgtBackendData*>(context_->backend_data.get());
+
+  std::shared_ptr<const wgt::parse::AppWidgetInfo> appwidget_info =
+      std::static_pointer_cast<const wgt::parse::AppWidgetInfo>(
+          parser_->GetManifestData(
+              wgt::application_widget_keys::kTizenAppWidgetFullKey));
+  if (appwidget_info)
+    backend_data->appwidgets.set(*appwidget_info);
+  return true;
+}
+
 bool StepParse::FillAccounts(manifest_x* manifest) {
   std::shared_ptr<const wgt::parse::AccountInfo> account_info =
       std::static_pointer_cast<const wgt::parse::AccountInfo>(
@@ -507,7 +520,7 @@ bool StepParse::FillImeInfo() {
 }
 
 bool StepParse::FillExtraManifestInfo(manifest_x* manifest) {
-  return FillAccounts(manifest) && FillImeInfo();
+  return FillAccounts(manifest) && FillImeInfo() && FillAppWidget();
 }
 
 bool StepParse::FillManifestX(manifest_x* manifest) {
index 9bc1b73..4a41978 100644 (file)
@@ -66,6 +66,7 @@ class StepParse : public common_installer::Step {
   bool FillExtraManifestInfo(manifest_x* manifest);
   bool FillAccounts(manifest_x* manifest);
   bool FillImeInfo();
+  bool FillAppWidget();
   bool FillBackgroundCategoryInfo(manifest_x* manifest);
   bool FillManifestX(manifest_x* manifest);
 
diff --git a/src/wgt/step/filesystem/step_copy_preview_icons.cc b/src/wgt/step/filesystem/step_copy_preview_icons.cc
new file mode 100644 (file)
index 0000000..88fc004
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "wgt/step/filesystem/step_copy_preview_icons.h"
+
+#include <boost/filesystem/path.hpp>
+#include <common/utils/file_util.h>
+
+#include <string>
+
+#include "wgt/wgt_backend_data.h"
+
+namespace bf = boost::filesystem;
+namespace ci = common_installer;
+
+namespace {
+
+const char kResWgt[] = "res/wgt";
+const char kSharedRes[] = "shared/res";
+
+}  // namespace
+
+namespace wgt {
+namespace filesystem {
+
+ci::Step::Status StepCopyPreviewIcons::process() {
+  WgtBackendData* backend_data =
+      static_cast<WgtBackendData*>(context_->backend_data.get());
+  for (auto& appwidget : backend_data->appwidgets.get().app_widgets()) {
+    for (auto& size : appwidget.content_size) {
+      if (!size.preview.empty()) {
+        bf::path icon_path =
+            context_->pkg_path.get() / kResWgt / size.preview;
+        std::string type = wgt::parse::AppWidgetSizeTypeToString(size.type);
+        std::string icon_name = appwidget.id + "." + type + "." + "preview" +
+            bf::path(size.preview).extension().string();
+        bf::path preview_icon =
+            context_->pkg_path.get() / kSharedRes / icon_name;
+        if (!ci::CopyFile(icon_path, preview_icon)) {
+          LOG(ERROR) << "Cannot create preview icon: " << preview_icon;
+          return Status::ICON_ERROR;
+        }
+      }
+    }
+  }
+  LOG(DEBUG) << "Preview icons created";
+  return Status::OK;
+}
+
+}  // namespace filesystem
+}  // namespace wgt
diff --git a/src/wgt/step/filesystem/step_copy_preview_icons.h b/src/wgt/step/filesystem/step_copy_preview_icons.h
new file mode 100644 (file)
index 0000000..ee9c525
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef WGT_STEP_FILESYSTEM_STEP_COPY_PREVIEW_ICONS_H_
+#define WGT_STEP_FILESYSTEM_STEP_COPY_PREVIEW_ICONS_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include <common/app_installer.h>
+#include <common/installer_context.h>
+#include <common/step/step.h>
+
+namespace wgt {
+namespace filesystem {
+
+/**
+ * \brief Step that create copy of preview icons in shared/res/ directory
+ */
+class StepCopyPreviewIcons : public common_installer::Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override { return Status::OK; }
+  Status undo() override { return Status::OK; }
+  Status precheck() override { return Status::OK; }
+
+  SCOPE_LOG_TAG(CopyPreviewIcons)
+};
+
+}  // namespace filesystem
+}  // namespace wgt
+
+#endif  // WGT_STEP_FILESYSTEM_STEP_COPY_PREVIEW_ICONS_H_
index 397c7d8..b23fcae 100644 (file)
@@ -9,6 +9,7 @@
 #include <unistd.h>
 
 #include <boost/filesystem.hpp>
+#include <boost/system/error_code.hpp>
 #include <common/utils/file_util.h>
 #include <common/utils/glist_range.h>
 #include <cassert>
 #include <cstdio>
 #include <string>
 
+#include "wgt/wgt_backend_data.h"
+
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
 
 namespace {
 
 const char kWrtServiceBinaryPath[] = "/usr/bin/wrt-service";
+const char kWidgetClientBinaryPath[] = "/usr/bin/widget-client";
 
 }  // namespace
 
 namespace wgt {
 namespace filesystem {
 
-namespace bf = boost::filesystem;
-
-common_installer::Step::Status StepCreateSymbolicLink::process() {
-  assert(context_->manifest_data.get());
+bool StepCreateSymbolicLink::CreateSymlinksForApps() {
   boost::system::error_code error;
   for (application_x* app :
        GListRange<application_x*>(context_->manifest_data.get()->application)) {
@@ -52,11 +55,38 @@ common_installer::Step::Status StepCreateSymbolicLink::process() {
     if (error) {
       LOG(ERROR) << "Failed to set symbolic link "
         << boost::system::system_error(error).what();
-      return Step::Status::ERROR;
+      return false;
     }
   }
-  LOG(DEBUG) << "Symlinks created successfully";
+  return true;
+}
 
+bool StepCreateSymbolicLink::CreateSymlinksForAppWidgets() {
+  WgtBackendData* backend_data =
+      static_cast<WgtBackendData*>(context_->backend_data.get());
+  for (auto& appwidget : backend_data->appwidgets.get().app_widgets()) {
+    bf::path exec_path = context_->pkg_path.get() / "bin" / appwidget.id;
+    bs::error_code error;
+    bf::create_symlink(kWidgetClientBinaryPath, exec_path, error);
+    if (error) {
+      LOG(ERROR) << "Failed to create symlink for app widget: "
+                 << appwidget.id;
+      return false;
+    }
+  }
+  return true;
+}
+
+common_installer::Step::Status StepCreateSymbolicLink::process() {
+  assert(context_->manifest_data.get());
+
+  if (!CreateSymlinksForApps())
+    return Status::APP_DIR_ERROR;
+
+  if (!CreateSymlinksForAppWidgets())
+    return Status::APP_DIR_ERROR;
+
+  LOG(DEBUG) << "Symlinks created successfully";
   return Status::OK;
 }
 
index 0efa491..dbe650b 100644 (file)
@@ -52,6 +52,10 @@ class StepCreateSymbolicLink : public common_installer::Step {
    */
   Status precheck() override { return Status::OK; }
 
+ private:
+  bool CreateSymlinksForApps();
+  bool CreateSymlinksForAppWidgets();
+
   SCOPE_LOG_TAG(SymbolicLink)
 };
 
index 79339f1..bfcfb23 100644 (file)
 #include <string>
 
 #include "wgt/step/common/privileges.h"
+#include "wgt/wgt_backend_data.h"
 
 namespace bs = boost::system;
 namespace bf = boost::filesystem;
 
 namespace {
 
+const char kResWgt[] = "res/wgt";
+const char kSharedRes[] = "shared/res";
+
 void WriteUIApplicationAttributes(
     xmlTextWriterPtr writer, application_x *app) {
   if (app->taskmanage)
@@ -499,6 +503,77 @@ common_installer::Step::Status StepGenerateXml::process() {
     xmlTextWriterEndElement(writer);
   }
 
+  WgtBackendData* backend_data =
+      static_cast<WgtBackendData*>(context_->backend_data.get());
+  bf::path widget_content_path = context_->pkg_path.get() / kResWgt;
+  for (auto& appwidget : backend_data->appwidgets.get().app_widgets()) {
+    xmlTextWriterStartElement(writer, BAD_CAST "widget");
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "appid",
+                                BAD_CAST appwidget.id.c_str());
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "primary",
+        BAD_CAST (appwidget.primary ? "true" : "false"));  // NOLINT
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "abi",
+                                BAD_CAST "html");
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "network",
+                                BAD_CAST "true");
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay",
+                                BAD_CAST "false");
+
+    if (!appwidget.label.default_value.empty()) {
+      xmlTextWriterStartElement(writer, BAD_CAST "label");
+      xmlTextWriterWriteString(writer,
+                               BAD_CAST appwidget.label.default_value.c_str());
+      xmlTextWriterEndElement(writer);
+    }
+    for (auto& pair : appwidget.label.lang_value_map) {
+      xmlTextWriterStartElement(writer, BAD_CAST "label");
+      xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
+                                  BAD_CAST pair.first.c_str());
+      xmlTextWriterWriteString(writer, BAD_CAST pair.second.c_str());
+      xmlTextWriterEndElement(writer);
+    }
+
+    if (!appwidget.icon_src.empty()) {
+      xmlTextWriterStartElement(writer, BAD_CAST "icon");
+      xmlTextWriterWriteString(writer, BAD_CAST appwidget.icon_src.c_str());
+      xmlTextWriterEndElement(writer);
+    }
+
+    xmlTextWriterStartElement(writer, BAD_CAST "box");
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST "buffer");
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "mouse_event",
+        BAD_CAST (appwidget.content_mouse_event ? "true" : "false"));  // NOLINT
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "touch_effect",
+        BAD_CAST (appwidget.content_touch_effect ? "true" : "false"));  // NOLINT
+    xmlTextWriterStartElement(writer, BAD_CAST "script");
+    bf::path src = widget_content_path / appwidget.content_src;
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "src",
+        BAD_CAST src.c_str());
+    xmlTextWriterEndElement(writer);
+    for (auto& size : appwidget.content_size) {
+      xmlTextWriterStartElement(writer, BAD_CAST "size");
+
+      std::string type = wgt::parse::AppWidgetSizeTypeToString(size.type);
+      if (!size.preview.empty()) {
+        std::string icon_name = appwidget.id + "." + type + "." + "preview" +
+            bf::path(size.preview).extension().string();
+        bf::path preview_icon =
+            context_->pkg_path.get() / kSharedRes / icon_name;
+        xmlTextWriterWriteAttribute(writer, BAD_CAST "preview",
+            BAD_CAST preview_icon.c_str());  // NOLINT
+      }
+
+      xmlTextWriterWriteAttribute(writer, BAD_CAST "need_frame",
+                                  BAD_CAST "true");
+      xmlTextWriterWriteString(writer,
+          BAD_CAST type.c_str());
+      xmlTextWriterEndElement(writer);
+    }
+    xmlTextWriterEndElement(writer);
+
+    xmlTextWriterEndElement(writer);
+  }
+
   xmlTextWriterEndElement(writer);
 
   xmlTextWriterEndDocument(writer);
index 8fdf4a4..3d2791d 100644 (file)
@@ -8,6 +8,7 @@
 #include <common/installer_context.h>
 #include <common/utils/property.h>
 
+#include <wgt_manifest_handlers/appwidget_handler.h>
 #include <wgt_manifest_handlers/setting_handler.h>
 
 #include <string>
@@ -25,6 +26,8 @@ class WgtBackendData : public common_installer::BackendData {
    * \brief Property of SettingInfo
    */
   Property<parse::SettingInfo> settings;
+
+  Property<parse::AppWidgetInfo> appwidgets;
 };
 
 }  // namespace wgt
index e61112c..ffb2d59 100644 (file)
@@ -62,6 +62,7 @@
 #include "wgt/step/configuration/step_parse_recovery.h"
 #include "wgt/step/encryption/step_encrypt_resources.h"
 #include "wgt/step/encryption/step_remove_encryption_data.h"
+#include "wgt/step/filesystem/step_copy_preview_icons.h"
 #include "wgt/step/filesystem/step_create_symbolic_link.h"
 #include "wgt/step/filesystem/step_wgt_patch_icons.h"
 #include "wgt/step/filesystem/step_wgt_patch_storage_directories.h"
@@ -108,6 +109,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
       AddStep<wgt::filesystem::StepWgtPatchIcons>();
       AddStep<ci::filesystem::StepCreateIcons>();
+      AddStep<wgt::filesystem::StepCopyPreviewIcons>();
       AddStep<wgt::pkgmgr::StepGenerateXml>();
       AddStep<ci::pkgmgr::StepRegisterApplication>();
       AddStep<ci::pkgmgr::StepRunParserPlugin>(
@@ -144,6 +146,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
       AddStep<wgt::filesystem::StepWgtPatchIcons>();
       AddStep<ci::filesystem::StepCreateIcons>();
+      AddStep<wgt::filesystem::StepCopyPreviewIcons>();
       AddStep<ci::filesystem::StepCopyStorageDirectories>();
       AddStep<ci::security::StepUpdateSecurity>();
       AddStep<wgt::pkgmgr::StepGenerateXml>();
@@ -217,6 +220,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
       AddStep<wgt::filesystem::StepWgtPatchIcons>();
       AddStep<ci::filesystem::StepCreateIcons>();
+      AddStep<wgt::filesystem::StepCopyPreviewIcons>();
       AddStep<ci::filesystem::StepCopyStorageDirectories>();
       AddStep<ci::security::StepUpdateSecurity>();
       AddStep<wgt::pkgmgr::StepGenerateXml>();
@@ -264,6 +268,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
       AddStep<wgt::filesystem::StepWgtPatchIcons>();
       AddStep<ci::filesystem::StepCreateIcons>();
+      AddStep<wgt::filesystem::StepCopyPreviewIcons>();
       AddStep<wgt::pkgmgr::StepGenerateXml>();
       AddStep<ci::pkgmgr::StepRegisterApplication>();
       AddStep<ci::pkgmgr::StepRunParserPlugin>(
@@ -299,6 +304,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
       AddStep<wgt::filesystem::StepWgtPatchIcons>();
       AddStep<ci::filesystem::StepCreateIcons>();
+      AddStep<wgt::filesystem::StepCopyPreviewIcons>();
       AddStep<ci::security::StepUpdateSecurity>();
       AddStep<wgt::pkgmgr::StepGenerateXml>();
       AddStep<ci::pkgmgr::StepRunParserPlugin>(