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>
31 namespace bf = boost::filesystem;
32 namespace bs = boost::system;
33 namespace ci = common_installer;
37 const char kHybridConfigLocation[] = "res/wgt/config.xml";
38 const char kTizenManifestLocation[] = "tizen-manifest.xml";
40 std::string GetPkgIdFromPath(const std::string& path) {
41 if (!bf::exists(path))
43 bf::path tmp_path = common_installer::GenerateTmpDir("/tmp");
45 bf::create_directories(tmp_path, code);
48 if (!common_installer::ExtractToTmpDir(path.c_str(), tmp_path,
50 ci::RemoveAll(tmp_path);
53 bf::path config_path = tmp_path / "config.xml";
54 std::vector<std::shared_ptr<parser::ManifestHandler>> handlers = {
55 std::make_shared<wgt::parse::WidgetHandler>(),
56 std::make_shared<wgt::parse::TizenApplicationHandler>()
58 std::unique_ptr<parser::ManifestHandlerRegistry> registry(
59 new parser::ManifestHandlerRegistry(handlers));
60 std::unique_ptr<parser::ManifestParser> parser(
61 new parser::ManifestParser(std::move(registry)));
62 if (!parser->ParseManifest(config_path)) {
63 ci::RemoveAll(tmp_path);
66 auto info = std::static_pointer_cast<const wgt::parse::TizenApplicationInfo>(
67 parser->GetManifestData(
68 wgt::application_widget_keys::kTizenApplicationKey));
70 ci::RemoveAll(tmp_path);
73 std::string pkg_id = info->package();
75 ci::RemoveAll(tmp_path);
79 std::string ReadPkgidFromRecovery(const std::string& recovery_path) {
80 std::unique_ptr<ci::recovery::RecoveryFile> recovery_file =
81 ci::recovery::RecoveryFile::OpenRecoveryFileForPath(recovery_path);
82 recovery_file->Detach();
83 return recovery_file->pkgid();
90 bool WgtAppQueryInterface::IsPkgInstalled(const std::string& arg, uid_t uid) {
91 // argument from commandline is package id
92 if (ci::QueryIsPackageInstalled(arg, ci::GetRequestMode(uid), uid))
95 // argument from commandline is path to file
96 std::string pkg_id = GetPkgIdFromPath(arg);
99 return ci::QueryIsPackageInstalled(pkg_id, ci::GetRequestMode(uid), uid);
102 bool WgtAppQueryInterface::IsHybridApplication(const std::string& arg,
105 bool is_recovery = arg.find("wgt-recovery-") != std::string::npos;
107 info = ReadPkgidFromRecovery(arg);
111 if (ci::QueryIsPackageInstalled(info, ci::GetRequestMode(uid), uid)) {
112 bf::path package_directory(ci::GetRootAppPath(false, uid));
113 if (bf::exists(package_directory / info / kTizenManifestLocation) &&
114 bf::exists(package_directory / info / kHybridConfigLocation))
116 } else if (!is_recovery) {
117 bool tizen_manifest_found = false;
118 bool config_xml_found = false;
119 if (!ci::CheckPathInZipArchive(info.c_str(), kTizenManifestLocation,
120 &tizen_manifest_found))
122 if (!ci::CheckPathInZipArchive(info.c_str(), kHybridConfigLocation,
125 if (tizen_manifest_found && config_xml_found)
131 std::string WgtAppQueryInterface::GetPkgId(const std::string& arg) {
132 return GetPkgIdFromPath(arg);