1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache 2.0 license that can be
3 // found in the LICENSE file.
5 #include "wgt/wgt_app_query_interface.h"
10 #include <boost/filesystem/operations.hpp>
11 #include <boost/filesystem/path.hpp>
12 #include <boost/system/error_code.hpp>
14 #include <common/pkgmgr_interface.h>
15 #include <common/pkgmgr_query.h>
16 #include <common/recovery_file.h>
17 #include <common/request.h>
18 #include <common/utils/file_util.h>
20 #include <manifest_parser/manifest_parser.h>
21 #include <manifest_parser/utils/logging.h>
22 #include <wgt_manifest_handlers/application_manifest_constants.h>
23 #include <wgt_manifest_handlers/tizen_application_handler.h>
24 #include <wgt_manifest_handlers/widget_handler.h>
26 #include <tzplatform_config.h>
33 namespace bf = boost::filesystem;
34 namespace bs = boost::system;
35 namespace ci = common_installer;
39 const char kHybridConfigLocation[] = "res/wgt/config.xml";
40 const char kTizenManifestLocation[] = "tizen-manifest.xml";
42 std::string ReadPkgidFromRecovery(const std::string& recovery_path) {
43 std::unique_ptr<ci::recovery::RecoveryFile> recovery_file =
44 ci::recovery::RecoveryFile::OpenRecoveryFile(recovery_path);
45 recovery_file->Detach();
46 return recovery_file->pkgid();
53 std::string WgtAppQueryInterface::GetManifestFileName() const {
57 std::string WgtAppQueryInterface::GetPkgIdFromPath(
58 const std::string& path) const {
59 bf::path tmp_path = ExtractManifest(path);
62 std::vector<std::shared_ptr<parser::ManifestHandler>> handlers = {
63 std::make_shared<wgt::parse::WidgetHandler>(),
64 std::make_shared<wgt::parse::TizenApplicationHandler>()
66 std::unique_ptr<parser::ManifestHandlerRegistry> registry(
67 new parser::ManifestHandlerRegistry(handlers));
68 std::unique_ptr<parser::ManifestParser> parser(
69 new parser::ManifestParser(std::move(registry)));
70 bf::path config_path = tmp_path / GetManifestFileName();
71 if (!parser->ParseManifest(config_path)) {
72 ci::RemoveAll(tmp_path);
75 auto info = std::static_pointer_cast<const wgt::parse::TizenApplicationInfo>(
76 parser->GetManifestData(
77 wgt::application_widget_keys::kTizenApplicationKey));
79 ci::RemoveAll(tmp_path);
82 std::string pkg_id = info->package();
84 ci::RemoveAll(tmp_path);
88 bool WgtAppQueryInterface::IsHybridApplication(const std::string& arg,
91 bool is_recovery = arg.find("wgt-recovery-") != std::string::npos;
93 info = ReadPkgidFromRecovery(arg);
96 bf::path rw_package_directory(ci::GetRootAppPath(false, uid));
97 bf::path ro_package_directory;
98 if (uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) || uid == 0)
99 ro_package_directory = ci::GetRootAppPath(true, uid);
100 if ((bf::exists(rw_package_directory / info / kTizenManifestLocation) &&
101 bf::exists(rw_package_directory / info / kHybridConfigLocation)) ||
102 (bf::exists(ro_package_directory / info / kTizenManifestLocation) &&
103 bf::exists(ro_package_directory / info / kHybridConfigLocation))) {
105 } else if (!is_recovery) {
106 bool tizen_manifest_found = false;
107 bool config_xml_found = false;
108 if (!ci::CheckPathInZipArchive(info.c_str(), kTizenManifestLocation,
109 &tizen_manifest_found))
111 if (!ci::CheckPathInZipArchive(info.c_str(), kHybridConfigLocation,
114 if (tizen_manifest_found && config_xml_found)