Implement wgt backend library 09/99009/5 accepted/tizen/3.0/common/20161124.181949 accepted/tizen/3.0/ivi/20161124.030516 accepted/tizen/3.0/mobile/20161124.030401 accepted/tizen/3.0/tv/20161124.030430 accepted/tizen/3.0/wearable/20161124.030456 submit/tizen_3.0/20161123.114701
authorSangyoon Jang <s89.jang@samsung.com>
Mon, 21 Nov 2016 07:00:25 +0000 (16:00 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Wed, 23 Nov 2016 06:16:12 +0000 (15:16 +0900)
This backend library is for getting package information from file.
The functions are called by dlsym from pkgmgr_client api.
(Refer to: https://review.tizen.org/gerrit/73286)

Change-Id: I547fae4bf0a431a28826ef8c4f6e83768c4acc18
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
CMakeLists.txt
packaging/wgt-backend.spec
src/CMakeLists.txt
src/lib/CMakeLists.txt [new file with mode: 0644]
src/lib/wgt_archive_info.cc [new file with mode: 0644]
src/lib/wgt_archive_info.h [new file with mode: 0644]
src/lib/wgt_pkgmgr.cc [new file with mode: 0644]

index f39937d..77ad385 100644 (file)
@@ -28,6 +28,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EXTRA_LINKER_FLAGS}")
 
 # Targets
 SET(TARGET_LIBNAME_WGT "wgt-installer")
+SET(TARGET_LIBNAME_WGT_ARCHIVE_INFO "wgt")
 SET(TARGET_WGT_BACKEND "wgt-backend")
 SET(TARGET_LIBNAME_HYBRID "hybrid-installer")
 
@@ -46,8 +47,10 @@ PKG_CHECK_MODULES(APP_INSTALLERS_DEPS REQUIRED app-installers)
 PKG_CHECK_MODULES(WGT_MANIFEST_HANDLERS_DEPS REQUIRED wgt-manifest-handlers)
 PKG_CHECK_MODULES(MANIFEST_PARSER_DEPS REQUIRED manifest-parser)
 PKG_CHECK_MODULES(PKGMGR_INSTALLER_DEPS REQUIRED pkgmgr-installer)
+PKG_CHECK_MODULES(PKGMGR_TYPES_DEPS REQUIRED pkgmgr-types)
 PKG_CHECK_MODULES(ENCRYPTION_DEPS REQUIRED libwebappenc)
 PKG_CHECK_MODULES(TPK_INSTALLER_DEPS REQUIRED tpk-installer)
+PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf)
 
 FIND_PACKAGE(Boost REQUIRED COMPONENTS system filesystem regex program_options)
 FIND_PACKAGE(GTest REQUIRED)
index dbc504c..998fc24 100644 (file)
@@ -16,8 +16,10 @@ BuildRequires:  pkgconfig(app-installers)
 BuildRequires:  pkgconfig(manifest-parser)
 BuildRequires:  pkgconfig(wgt-manifest-handlers)
 BuildRequires:  pkgconfig(pkgmgr-installer)
+BuildRequires:  pkgconfig(pkgmgr-types)
 BuildRequires:  pkgconfig(libwebappenc)
 BuildRequires:  pkgconfig(tpk-installer)
+BuildRequires:  pkgconfig(vconf)
 
 %description
 This is a package that installs the WGT backend of pkgmgr.
@@ -57,6 +59,7 @@ ln -s %{_bindir}/wgt-backend %{buildroot}%{_sysconfdir}/package-manager/backend/
 %manifest wgt-backend.manifest
 %license LICENSE
 %{_sysconfdir}/package-manager/backend/wgt
+%{_sysconfdir}/package-manager/backendlib/libwgt.so
 %{_bindir}/wgt-backend
 %{_datadir}/wgt-backend/default.png
 
index 0136fd6..5384753 100644 (file)
@@ -1,4 +1,5 @@
 ADD_SUBDIRECTORY(hybrid)
+ADD_SUBDIRECTORY(lib)
 ADD_SUBDIRECTORY(wgt)
 ADD_SUBDIRECTORY(wgt_backend)
 ADD_SUBDIRECTORY(unit_tests)
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a14aaae
--- /dev/null
@@ -0,0 +1,15 @@
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} LIB_SRCS)
+ADD_LIBRARY(${TARGET_LIBNAME_WGT_ARCHIVE_INFO} SHARED ${LIB_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_WGT_ARCHIVE_INFO} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
+
+APPLY_PKG_CONFIG(${TARGET_LIBNAME_WGT_ARCHIVE_INFO} PUBLIC
+  APP_INSTALLERS_DEPS
+  PKGMGR_TYPES_DEPS
+  MANIFEST_PARSER_DEPS
+  WGT_MANIFEST_HANDLERS_DEPS
+  VCONF_DEPS
+  Boost
+)
+
+INSTALL(TARGETS ${TARGET_LIBNAME_WGT_ARCHIVE_INFO} DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/backendlib)
diff --git a/src/lib/wgt_archive_info.cc b/src/lib/wgt_archive_info.cc
new file mode 100644 (file)
index 0000000..bcaa43b
--- /dev/null
@@ -0,0 +1,214 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "lib/wgt_archive_info.h"
+
+#include <package-manager-plugin.h>
+#include <pkgmgr-info.h>
+#include <vconf.h>
+
+#include <wgt_manifest_handlers/widget_config_parser.h>
+#include <wgt_manifest_handlers/application_icons_handler.h>
+#include <wgt_manifest_handlers/application_manifest_constants.h>
+#include <wgt_manifest_handlers/permissions_handler.h>
+#include <wgt_manifest_handlers/tizen_application_handler.h>
+#include <wgt_manifest_handlers/widget_handler.h>
+
+#include <common/utils/file_util.h>
+
+#include <cstdio>
+#include <cstdlib>
+#include <fstream>
+#include <string>
+#include <vector>
+
+namespace bf = boost::filesystem;
+namespace ci = common_installer;
+
+namespace {
+
+const char kVconfLanguageKey[] = "db/menu_widget/language";
+
+bool ExtractPackageArchive(const char* file_path, const bf::path& tmp_dir) {
+  if (!ci::ExtractToTmpDir(file_path, tmp_dir)) {
+    LOG(ERROR) << "Failed to extract";
+    return false;
+  }
+  return true;
+}
+
+bool GetPackageInfo(wgt::parse::WidgetConfigParser& parser,
+    package_manager_pkg_detail_info_t* info) {
+  auto widget_info =
+      std::static_pointer_cast<const wgt::parse::WidgetInfo>(
+          parser.GetManifestData(wgt::parse::WidgetInfo::Key()));
+  auto app_info =
+      std::static_pointer_cast<const wgt::parse::TizenApplicationInfo>(
+          parser.GetManifestData(wgt::parse::TizenApplicationInfo::Key()));
+  if (!widget_info || !app_info) {
+    LOG(ERROR) << "WidgetInfo / TizenApplicationInfo not found";
+    return false;
+  }
+
+  snprintf(info->pkg_type, sizeof(info->pkg_type), "wgt");
+  snprintf(info->version, sizeof(info->version), "%s",
+      widget_info->version().c_str());
+  snprintf(info->author, sizeof(info->version), "%s",
+      widget_info->author().c_str());
+
+  snprintf(info->pkg_name, sizeof(info->pkg_name), "%s",
+      app_info->package().c_str());
+  snprintf(info->pkgid, sizeof(info->pkgid), "%s", app_info->package().c_str());
+  snprintf(info->api_version, sizeof(info->api_version), "%s",
+      app_info->required_version().c_str());
+
+  return true;
+}
+
+bool GetPrivilegesInfo(wgt::parse::WidgetConfigParser& parser,
+    package_manager_pkg_detail_info_t* info) {
+  auto privileges_info =
+      std::static_pointer_cast<const wgt::parse::PermissionsInfo>(
+          parser.GetManifestData(wgt::parse::PermissionsInfo::Key()));
+  if (!privileges_info)
+    return false;
+
+  const auto& privileges = privileges_info->GetAPIPermissions();
+  for (auto& priv : privileges) {
+    info->privilege_list = g_list_append(info->privilege_list,
+        strdup(priv.c_str()));
+  }
+
+  return true;
+}
+
+bool GetLabelInfo(wgt::parse::WidgetConfigParser& parser, const char* locale,
+    package_manager_pkg_detail_info_t* info) {
+  auto widget_info =
+      std::static_pointer_cast<const wgt::parse::WidgetInfo>(
+          parser.GetManifestData(wgt::parse::WidgetInfo::Key()));
+  if (!widget_info)
+    return false;
+
+  std::string name;
+  const auto& labels = widget_info->name_set();
+  if (labels.find(locale) != labels.end()) {
+    name = labels.find(locale)->second;
+    snprintf(info->label, sizeof(info->label), "%s", name.c_str());
+    return true;
+  } else if (labels.find("") != labels.end()) {
+    name = labels.find("")->second;
+    snprintf(info->label, sizeof(info->label), "%s", name.c_str());
+    return true;
+  }
+
+  return false;
+}
+
+bool GetDescriptionInfo(wgt::parse::WidgetConfigParser& parser,
+    const char* locale, package_manager_pkg_detail_info_t* info) {
+  auto widget_info =
+      std::static_pointer_cast<const wgt::parse::WidgetInfo>(
+          parser.GetManifestData(wgt::parse::WidgetInfo::Key()));
+  if (!widget_info)
+    return false;
+
+  std::string desc;
+  const auto& descriptions = widget_info->description_set();
+  if (descriptions.find(locale) != descriptions.end()) {
+    desc = descriptions.find(locale)->second;
+    snprintf(info->pkg_description, sizeof(info->pkg_description), "%s",
+        desc.c_str());
+    return true;
+  } else if (descriptions.find("") != descriptions.end()) {
+    desc = descriptions.find("")->second;
+    snprintf(info->pkg_description, sizeof(info->pkg_description), "%s",
+        desc.c_str());
+    return true;
+  }
+
+  return false;
+}
+
+bool ReadIcon(const bf::path& icon, const bf::path& tmp_dir,
+    package_manager_pkg_detail_info_t* info) {
+  bf::path icon_path;
+  if (icon.is_absolute())
+    icon_path = icon;
+  else
+    icon_path = tmp_dir / icon;
+
+  LOG(INFO) << "Icon file path: " << icon_path;
+
+  std::ifstream ifs(icon_path.c_str(),
+      std::ifstream::in | std::ifstream::binary);
+  ifs.seekg(0, ifs.end);
+  int len = ifs.tellg();
+  ifs.seekg(0, ifs.beg);
+
+  if (len <= 0)
+    return false;
+
+  char* buf = static_cast<char*>(malloc(sizeof(char) * len));
+
+  LOG(INFO) << "Reading icon file, " << len << " bytes";
+  ifs.read(buf, len);
+
+  info->icon_buf = buf;
+  info->icon_size = len;
+
+  return true;
+}
+
+bool GetIconInfo(wgt::parse::WidgetConfigParser& parser,
+    bf::path& tmp_dir, package_manager_pkg_detail_info_t* info) {
+  auto icons_info =
+      std::static_pointer_cast<const wgt::parse::ApplicationIconsInfo>(
+          parser.GetManifestData(wgt::parse::ApplicationIconsInfo::Key()));
+  if (!icons_info)
+    return false;
+
+  return ReadIcon(icons_info->icons().front().path(), tmp_dir, info);
+}
+
+}  // namespace
+
+bool WgtArchiveInfo::GetArchiveInfo(const char* file_path,
+    package_manager_pkg_detail_info_t* info) {
+  bf::path tmp_dir = ci::GenerateTmpDir("/tmp");
+  if (!ci::CreateDir(tmp_dir))
+    return false;
+  LOG(DEBUG) << "Unpack at temporary dir: " << tmp_dir;
+  if (!ExtractPackageArchive(file_path, tmp_dir))
+    return false;
+
+  wgt::parse::WidgetConfigParser parser;
+  bf::path manifest_path = tmp_dir / "config.xml";
+  if (!parser.ParseManifest(manifest_path)) {
+    LOG(ERROR) << "Failed to parse";
+    bf::remove_all(tmp_dir);
+    return false;
+  }
+
+  if (!GetPackageInfo(parser, info)) {
+    LOG(ERROR) << "Failed to get package info";
+    bf::remove_all(tmp_dir);
+    return false;
+  }
+  if (!GetPrivilegesInfo(parser, info))
+    LOG(WARNING) << "Failed to get privileges info";
+  if (!GetIconInfo(parser, tmp_dir, info))
+    LOG(WARNING) << "Failed to get icon info";
+
+  char* locale = vconf_get_str(kVconfLanguageKey);
+  if (!GetLabelInfo(parser, locale, info))
+    LOG(WARNING) << "Failed to get label info";
+  if (!GetDescriptionInfo(parser, locale, info))
+    LOG(WARNING) << "Failed to get description info";
+
+  free(locale);
+  bf::remove_all(tmp_dir);
+
+  return true;
+}
diff --git a/src/lib/wgt_archive_info.h b/src/lib/wgt_archive_info.h
new file mode 100644 (file)
index 0000000..3882f78
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef LIB_WGT_ARCHIVE_INFO_H_
+#define LIB_WGT_ARCHIVE_INFO_H_
+
+#include <package-manager-plugin.h>
+
+#include <manifest_parser/utils/logging.h>
+
+#include <common/utils/singleton.h>
+
+class WgtArchiveInfo : public common_installer::Singleton<WgtArchiveInfo> {
+  CRTP_DECLARE_DEFAULT_CONSTRUCTOR_CLASS(WgtArchiveInfo)
+ public:
+  bool GetArchiveInfo(const char* file_path,
+    package_manager_pkg_detail_info_t* info);
+
+  SCOPE_LOG_TAG(WgtArchiveInfo)
+};
+
+#endif  // LIB_WGT_ARCHIVE_INFO
diff --git a/src/lib/wgt_pkgmgr.cc b/src/lib/wgt_pkgmgr.cc
new file mode 100644 (file)
index 0000000..129c185
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include <package-manager-plugin.h>
+
+#include "lib/wgt_archive_info.h"
+
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace {
+
+int GetPackageArchiveInfo(const char* path,
+    package_manager_pkg_detail_info_t* info) {
+  if (!WgtArchiveInfo::Instance().GetArchiveInfo(path, info))
+    return -1;
+  return 0;
+}
+
+void PluginOnUnload() {
+}
+
+}  // namespace
+
+extern "C" EXPORT_API int pkg_plugin_on_load(pkg_plugin_set* set) {
+  if (set == nullptr)
+    return -1;
+  set->plugin_on_unload = PluginOnUnload;
+  set->pkg_is_installed = nullptr;
+  set->get_installed_pkg_list = nullptr;
+  set->get_pkg_detail_info = nullptr;
+  set->get_pkg_detail_info_from_package = GetPackageArchiveInfo;
+  return 0;
+}