# Targets
SET(TARGET_UNIFIED_BACKEND "unified-backend")
+SET(TARGET_LIBNAME_UNIFIED "unified-installer")
ADD_DEFINITIONS("-DPROJECT_TAG=\"UNIFIED_BACKEND\"")
Name: unified-backend
-Summary: Unified application installer backend
+Summary: Unified Tizen package installer backend
Version: 0.0.1
Release: 1
Group: Application Framework/Package Management
%description
This is a package that installs the Unified backend of pkgmgr.
+%package -n unified-installer
+Summary: Unified Tizen package installer library
+Group: Application Framework/Package Management
+
+%description -n unified-installer
+This package contains unified-installer library
+
+%package -n unified-installer-devel
+Summary: Unified Installer development files
+Group: Application Framework/Package Management
+Requires: unified-installer = %{version}
+
+%description -n unified-installer-devel
+This package contains header files of unified-installer library
+
%prep
%setup -q
%files
%manifest %{name}.manifest
%license LICENSE
-%{_bindir}
+%{_bindir}/*
+
+%files -n unified-installer
+%{_libdir}/libunified-installer.so*
+
+%files -n unified-installer-devel
+%{_includedir}/app-installers/unified/*.h
+%{_libdir}/pkgconfig/unified-installer.pc
# Target - definition
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} UNIFIED_SRCS)
-
-ADD_EXECUTABLE(${TARGET_UNIFIED_BACKEND} ${UNIFIED_SRCS})
+ADD_LIBRARY(${TARGET_LIBNAME_UNIFIED} SHARED
+ ${UNIFIED_SRCS}
+)
+ADD_EXECUTABLE(${TARGET_UNIFIED_BACKEND} "unified_backend.cc")
# Target - includes
+TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_UNIFIED} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
TARGET_INCLUDE_DIRECTORIES(${TARGET_UNIFIED_BACKEND} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
-APPLY_PKG_CONFIG(${TARGET_UNIFIED_BACKEND} PUBLIC
+APPLY_PKG_CONFIG(${TARGET_LIBNAME_UNIFIED} PUBLIC
APP_INSTALLERS_DEPS
MANIFEST_PARSER_DEPS
MINIZIP_DEPS
WGT_INSTALLER_DEPS
)
-# Target - in-package deps
+# Target
+TARGET_LINK_LIBRARIES(${TARGET_UNIFIED_BACKEND} PRIVATE ${TARGET_LIBNAME_UNIFIED})
SET_TARGET_PROPERTIES(${TARGET_UNIFIED_BACKEND} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
SET_TARGET_PROPERTIES(${TARGET_UNIFIED_BACKEND} PROPERTIES LINK_FLAGS "-pie")
# Install
+INSTALL(TARGETS ${TARGET_LIBNAME_UNIFIED} DESTINATION ${LIB_INSTALL_DIR})
INSTALL(TARGETS ${TARGET_UNIFIED_BACKEND} DESTINATION ${BINDIR})
+
+# Export devel package
+CONFIGURE_FILE(unified-installer.pc.in unified-installer.pc @ONLY)
+INSTALL(FILES unified-installer.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+INSTALL(DIRECTORY ./ DESTINATION ${INCLUDEDIR}/app-installers/unified/
+ FILES_MATCHING PATTERN "*.h")
--- /dev/null
+// Copyright (c) 2020 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 "unified/installer_factory.h"
+
+#include <unzip.h>
+
+#include <manifest_parser/utils/logging.h>
+#include <hybrid/hybrid_installer.h>
+#include <tpk/tpk_app_query_interface.h>
+#include <tpk/tpk_installer.h>
+#include <wgt/utils/wgt_app_query_interface.h>
+#include <wgt/wgt_installer.h>
+
+#include <memory>
+#include <string>
+
+#include "common/pkgmgr_interface.h"
+#include "common/pkgmgr_query.h"
+
+namespace {
+
+std::map<const char*, const char*> kTypeMap = {
+ {"res/wgt/config.xml", "wgt"},
+ {"config.xml", "wgt"},
+ {"tizen-manifest.xml", "tpk"},
+};
+
+std::string GetPkgTypeFromPkgid(const std::string& pkgid, uid_t uid) {
+ ci::PkgQueryInterface query(pkgid, uid);
+ return query.Type();
+}
+
+std::string GetPkgTypeFromPath(const std::string& path) {
+ std::string type;
+ unzFile uf = unzOpen(path.c_str());
+ if (!uf) {
+ LOG(ERROR) << "Failed to open zip file: " << path;
+ return type;
+ }
+ for (auto it : kTypeMap) {
+ if (unzLocateFile(uf, it.first, 0) == UNZ_OK) {
+ LOG(DEBUG) << "Found: " << it.first;
+ type = it.second;
+ break;
+ }
+ }
+ if (type.empty())
+ LOG(ERROR) << "Cannot get pkg type";
+ unzClose(uf);
+ return type;
+}
+
+} // namespace
+
+namespace common_installer {
+
+std::unique_ptr<AppInstaller> InstallerFactory::CreateInstaller(
+ PkgMgrPtr pkgmgr) {
+ std::string type = GetPkgTypeFromPkgid(pkgmgr->GetRequestInfo(),
+ pkgmgr->GetUid());
+ if (type.empty())
+ type = GetPkgTypeFromPath(pkgmgr->GetRequestInfo());
+
+ if (type.empty())
+ return {};
+
+ std::unique_ptr<ci::AppInstaller> installer;
+ if (type == "tpk") {
+ // should be fixed.
+ tpk::TpkAppQueryInterface* tpk_aqi = new tpk::TpkAppQueryInterface();
+ pkgmgr->SetAppQueryInterface(tpk_aqi);
+ installer.reset(new tpk::TpkInstaller(pkgmgr));
+ } else {
+ // should be fixed
+ wgt::WgtAppQueryInterface* wgt_aqi = new wgt::WgtAppQueryInterface();
+ pkgmgr->SetAppQueryInterface(wgt_aqi);
+ if (wgt_aqi->IsHybridApplication(pkgmgr->GetRequestInfo(),
+ pkgmgr->GetUid())) {
+ LOG(INFO) << "Hybrid package detected";
+ installer.reset(new hybrid::HybridInstaller(pkgmgr));
+ } else {
+ installer.reset(new wgt::WgtInstaller(pkgmgr));
+ }
+ }
+
+ return installer;
+}
+
+} // namespace common_installer
--- /dev/null
+// Copyright (c) 2020 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 UNIFIED_INSTALLER_FACTORY_H_
+#define UNIFIED_INSTALLER_FACTORY_H_
+
+#include <common/pkgmgr_interface.h>
+
+#include <memory>
+
+namespace common_installer {
+
+class AppInstaller;
+
+class InstallerFactory {
+ public:
+ static std::unique_ptr<AppInstaller> CreateInstaller(PkgMgrPtr pkgmgr);
+};
+
+} // namespace common_installer
+
+#endif // UNIFIED_INSTALLER_FACTORY_H_
--- /dev/null
+// Copyright (c) 2020 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 "unified/installer_runner.h"
+
+#include <common/app_installer.h>
+#include <common/pkgmgr_interface.h>
+#include <manifest_parser/utils/logging.h>
+
+#include <vector>
+
+#include "unified/installer_factory.h"
+
+namespace common_installer {
+
+InstallerRunner::InstallerRunner(PkgMgrPtr pkgmgr) : pkgmgr_(pkgmgr) {
+ if (!Init())
+ LOG(ERROR) << "Initialize failed!";
+}
+
+AppInstaller::Result InstallerRunner::Run() {
+ AppInstaller::Result result = AppInstaller::Result::OK;
+ std::vector<std::unique_ptr<AppInstaller>>::iterator it =
+ installers_.begin();
+ for (; it != installers_.end(); ++it) {
+ result = (*it)->Process();
+ if (result != AppInstaller::Result::OK)
+ break;
+ }
+ if (it != installers_.end() && result == AppInstaller::Result::ERROR) {
+ do {
+ if ((*it)->Undo() != AppInstaller::Result::OK)
+ result = AppInstaller::Result::UNDO_ERROR;
+ } while (it-- != installers_.begin());
+ } else {
+ --it;
+ do {
+ if ((*it)->Clean() != AppInstaller::Result::OK)
+ result = AppInstaller::Result::CLEANUP_ERROR;
+ } while (it-- != installers_.begin());
+ }
+
+ return result;
+}
+
+bool InstallerRunner::Init() {
+ std::unique_ptr<AppInstaller> installer =
+ InstallerFactory::CreateInstaller(pkgmgr_);
+ // initialize installer list. it should handle multiple request later.
+ installers_.emplace_back(std::move(installer));
+
+ return true;
+}
+
+} // namespace common_installer
--- /dev/null
+// Copyright (c) 2020 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 UNIFIED_INSTALLER_RUNNER_H_
+#define UNIFIED_INSTALLER_RUNNER_H_
+
+#include <common/app_installer.h>
+#include <common/pkgmgr_interface.h>
+
+#include <memory>
+#include <vector>
+
+namespace common_installer {
+
+class InstallerRunner {
+ public:
+ explicit InstallerRunner(PkgMgrPtr pkgmgr);
+
+ AppInstaller::Result Run();
+
+ private:
+ bool Init();
+
+ PkgMgrPtr pkgmgr_;
+ std::vector<std::unique_ptr<AppInstaller>> installers_;
+};
+
+} // namespace common_installer
+
+#endif // UNIFIED_INSTALLER_RUNNER_H_
--- /dev/null
+prefix=@PREFIX@
+exec_prefix=@PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: unified-installer
+Description: Unified Installer library
+Version: @FULLVER@
+Requires: app-installers tpk-installer wgt-installer pkgmgr tpk-manifest-handlers manifest-parser
+Libs: -L${libdir} -lunified-installer
+Cflags: -I${includedir}/app-installers/
-// Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+// Copyright (c) 2020 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 <unzip.h>
+#include <common/app_installer.h>
-#include <common/pkgmgr_interface.h>
-#include <common/pkgmgr_query.h>
-#include <manifest_parser/utils/logging.h>
-#include <hybrid/hybrid_installer.h>
-#include <tpk/tpk_app_query_interface.h>
-#include <tpk/tpk_installer.h>
-#include <wgt/wgt_app_query_interface.h>
-#include <wgt/wgt_installer.h>
-
-#include <map>
-#include <memory>
-#include <string>
-#include <utility>
+#include "unified/installer_factory.h"
+#include "unified/installer_runner.h"
namespace ci = common_installer;
-namespace {
-
-std::map<const char*, const char*> kTypeMap = {
- {"res/wgt/config.xml", "wgt"},
- {"config.xml", "wgt"},
- {"tizen-manifest.xml", "tpk"},
-};
-
-std::string GetPkgTypeFromPkgid(const std::string& pkgid, uid_t uid) {
- ci::PkgQueryInterface query(pkgid, uid);
- return query.Type();
-}
-
-std::string GetPkgTypeFromPath(const std::string& path) {
- std::string type;
- unzFile uf = unzOpen(path.c_str());
- if (!uf) {
- LOG(ERROR) << "Failed to open zip file: " << path;
- return type;
- }
- for (auto it : kTypeMap) {
- if (unzLocateFile(uf, it.first, 0) == UNZ_OK) {
- LOG(DEBUG) << "Found: " << it.first;
- type = it.second;
- break;
- }
- }
- if (type.empty())
- LOG(ERROR) << "Cannot get pkg type";
- unzClose(uf);
- return type;
-}
-
-} // namespace
-
int main(int argc, char** argv) {
ci::PkgmgrInstaller pkgmgr_installer;
auto pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &pkgmgr_installer);
- std::string type = GetPkgTypeFromPkgid(pkgmgr->GetRequestInfo(),
- pkgmgr->GetUid());
- if (type.empty())
- type = GetPkgTypeFromPath(pkgmgr->GetRequestInfo());
-
- if (type.empty())
- return 1;
-
- std::vector<std::unique_ptr<ci::AppInstaller>> installer_list;
-
- std::unique_ptr<ci::AppInstaller> installer;
- if (type == "tpk") {
- tpk::TpkAppQueryInterface tpk_aqi;
- pkgmgr->SetAppQueryInterface(&tpk_aqi);
- installer.reset(new tpk::TpkInstaller(pkgmgr));
- } else {
- wgt::WgtAppQueryInterface wgt_aqi;
- pkgmgr->SetAppQueryInterface(&wgt_aqi);
- if (wgt_aqi.IsHybridApplication(pkgmgr->GetRequestInfo(),
- pkgmgr->GetUid())) {
- LOG(INFO) << "Hybrid package detected";
- installer.reset(new hybrid::HybridInstaller(pkgmgr));
- } else {
- installer.reset(new wgt::WgtInstaller(pkgmgr));
- }
- }
-
- // initialize installer list. it should handle multiple request later.
- installer_list.emplace_back(std::move(installer));
-
- ci::AppInstaller::Result result = ci::AppInstaller::Result::OK;
- std::vector<std::unique_ptr<ci::AppInstaller>>::iterator it =
- installer_list.begin();
- for (; it != installer_list.end(); ++it) {
- result = (*it)->Process();
- if (result != ci::AppInstaller::Result::OK)
- break;
- }
- if (it != installer_list.end() && result == ci::AppInstaller::Result::ERROR) {
- do {
- if ((*it)->Undo() != ci::AppInstaller::Result::OK)
- result = ci::AppInstaller::Result::UNDO_ERROR;
- } while (it-- != installer_list.begin());
- } else {
- --it;
- do {
- if ((*it)->Clean() != ci::AppInstaller::Result::OK)
- result = ci::AppInstaller::Result::CLEANUP_ERROR;
- } while (it-- != installer_list.begin());
- }
+ ci::InstallerRunner runner(pkgmgr);
+ ci::AppInstaller::Result result = runner.Run();
return (result == ci::AppInstaller::Result::OK) ? 0 : 1;
}