1 // Copyright (c) 2014 Intel Corporation. All rights reserved.
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
7 #include <pkgmgr-info.h>
11 #include "base/logging.h"
12 #include "xwalk/application/common/tizen/package_query.h"
16 typedef ail_cb_ret_e (*PropertyCallback)(const ail_appinfo_h, void*, uid_t);
18 char kFieldInstalledTime[] = AIL_PROP_X_SLP_INSTALLEDTIME_INT;
19 char kFieldPackageType[] = AIL_PROP_X_SLP_PACKAGETYPE_STR;
20 char kFieldExePath[] = AIL_PROP_X_SLP_EXE_PATH;
22 template<const char* field> struct CallbackForStr {
23 static ail_cb_ret_e callback(const ail_appinfo_h appinfo,
24 void* user_data, uid_t /*uid*/) {
26 ail_appinfo_get_str(appinfo, field, &str_name);
28 return AIL_CB_RET_CONTINUE;
30 std::string* data = static_cast<std::string*>(user_data);
32 return AIL_CB_RET_CANCEL;
36 template<const char* field> struct CallbackForInt {
37 static ail_cb_ret_e callback(const ail_appinfo_h appinfo,
38 void* user_data, uid_t /*uid*/) {
39 int* data = static_cast<int*>(user_data);
40 ail_appinfo_get_int(appinfo, field, data);
41 return AIL_CB_RET_CANCEL;
45 void GetProperty(const std::string& id,
47 PropertyCallback callback,
50 ail_error_e ret = ail_filter_new(&filter);
51 if (ret != AIL_ERROR_OK) {
52 LOG(ERROR) << "Failed to create AIL filter.";
56 ret = ail_filter_add_str(filter, type, id.c_str());
57 if (ret != AIL_ERROR_OK) {
58 LOG(ERROR) << "Failed to init AIL filter.";
59 ail_filter_destroy(filter);
65 if (uid != GLOBAL_USER)
66 ret = ail_filter_count_usr_appinfo(filter, &count, uid);
68 ret = ail_filter_count_appinfo(filter, &count);
69 if (ret != AIL_ERROR_OK) {
70 LOG(ERROR) << "Failed to count AIL app info.";
71 ail_filter_destroy(filter);
76 LOG(ERROR) << "Invalid count (" << count
77 << ") of the AIL DB records for the app id " << id;
78 ail_filter_destroy(filter);
82 if (uid != GLOBAL_USER)
83 ail_filter_list_usr_appinfo_foreach(filter, callback,
86 ail_filter_list_appinfo_foreach(filter,
88 ail_filter_destroy(filter);
91 base::FilePath GetPath(const std::string& app_id, const char* type) {
92 std::string x_slp_exe_path;
95 CallbackForStr<kFieldExePath>::callback,
98 if (x_slp_exe_path.empty()) {
99 return base::FilePath();
102 // x_slp_exe_path is <app_path>/bin/<app_id>, we need to
103 // return just <app_path>.
104 return base::FilePath(x_slp_exe_path).DirName().DirName();
110 namespace application {
112 base::FilePath GetApplicationPath(const std::string& app_id) {
113 return GetPath(app_id, AIL_PROP_X_SLP_APPID_STR);
116 base::FilePath GetPackagePath(const std::string& pkg_id) {
117 return GetPath(pkg_id, AIL_PROP_X_SLP_PKGID_STR);
120 std::string GetPackageType(const std::string& pkg_id) {
123 AIL_PROP_X_SLP_PKGID_STR,
124 CallbackForStr<kFieldPackageType>::callback,
129 base::Time GetApplicationInstallationTime(const std::string& app_id) {
130 int installed_time = 0; // seconds since epoch
132 AIL_PROP_X_SLP_APPID_STR,
133 CallbackForInt<kFieldInstalledTime>::callback,
135 return base::Time::FromTimeT(installed_time);
138 } // namespace application