1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "xwalk/application/common/tizen/application_storage_impl.h"
8 #include <pkgmgr-info.h>
13 #include "base/file_util.h"
14 #include "third_party/re2/re2/re2.h"
15 #include "xwalk/application/common/application_file_util.h"
16 #include "xwalk/application/common/id_util.h"
17 #include "xwalk/application/common/tizen/application_storage.h"
18 #include "xwalk/application/common/tizen/package_query.h"
22 ail_cb_ret_e appinfo_get_app_id_cb(
23 const ail_appinfo_h appinfo, void* user_data, uid_t /*uid*/) {
24 std::vector<std::string>* app_ids =
25 static_cast<std::vector<std::string>*>(user_data);
27 ail_appinfo_get_str(appinfo, AIL_PROP_X_SLP_APPID_STR, &app_id);
29 app_ids->push_back(app_id);
31 return AIL_CB_RET_CONTINUE;
34 const char kXWalkPackageType[] = "wgt";
36 bool GetPackageType(const std::string& application_id,
37 xwalk::application::Manifest::Type* package_type) {
38 if (xwalk::application::IsValidWGTID(application_id)) {
39 *package_type = xwalk::application::Manifest::TYPE_WIDGET;
43 if (xwalk::application::IsValidXPKID(application_id)) {
44 *package_type = xwalk::application::Manifest::TYPE_MANIFEST;
54 namespace application {
56 ApplicationStorageImpl::ApplicationStorageImpl(const base::FilePath& path) {
59 ApplicationStorageImpl::~ApplicationStorageImpl() {
62 bool ApplicationStorageImpl::Init() {
68 bool GetManifestType(const std::string& app_id, Manifest::Type* manifest_type) {
69 if (IsValidWGTID(app_id)) {
70 *manifest_type = Manifest::TYPE_WIDGET;
74 if (IsValidXPKID(app_id)) {
75 *manifest_type = Manifest::TYPE_MANIFEST;
84 scoped_refptr<ApplicationData> ApplicationStorageImpl::GetApplicationData(
85 const std::string& app_id) {
86 base::FilePath app_path = GetApplicationPath(app_id);
88 Manifest::Type manifest_type;
89 if (!GetManifestType(app_id, &manifest_type)) {
90 LOG(ERROR) << "Failed to detect the manifest type from app id "
96 scoped_refptr<ApplicationData> app_data =
98 app_path, app_id, ApplicationData::INTERNAL, manifest_type, &error);
100 LOG(ERROR) << "Error occurred while trying to load application: " << error;
105 bool ApplicationStorageImpl::GetInstalledApplicationIDs(
106 std::vector<std::string>& app_ids) { // NOLINT
109 uid_t uid = getuid();
111 ail_error_e ret = ail_filter_new(&filter);
112 if (ret != AIL_ERROR_OK) {
113 LOG(ERROR) << "Failed to create AIL filter.";
116 // Filters out web apps (installed from WGT and XPK packages).
117 ret = ail_filter_add_str(
118 filter, AIL_PROP_X_SLP_PACKAGETYPE_STR, kXWalkPackageType);
119 if (ret != AIL_ERROR_OK) {
120 LOG(ERROR) << "Failed to init AIL filter.";
121 ail_filter_destroy(filter);
125 if (uid != GLOBAL_USER)
126 ret = ail_filter_count_usr_appinfo(filter, &count, uid);
128 ret = ail_filter_count_appinfo(filter, &count);
130 if (ret != AIL_ERROR_OK) {
131 LOG(ERROR) << "Failed to count AIL app info.";
132 ail_filter_destroy(filter);
137 if (uid != GLOBAL_USER)
138 ail_filter_list_usr_appinfo_foreach(filter, appinfo_get_app_id_cb,
141 ail_filter_list_appinfo_foreach(filter, appinfo_get_app_id_cb, &app_ids);
144 ail_filter_destroy(filter);
148 bool ApplicationStorageImpl::AddApplication(const ApplicationData* application,
149 const base::Time& install_time) {
153 bool ApplicationStorageImpl::UpdateApplication(
154 ApplicationData* application, const base::Time& install_time) {
158 bool ApplicationStorageImpl::RemoveApplication(const std::string& id) {
162 bool ApplicationStorageImpl::ContainsApplication(const std::string& app_id) {
163 return !GetApplicationPath(app_id).empty();
166 } // namespace application