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 ail_cb_ret_e callback_x_slp_exe_path(const ail_appinfo_h appinfo,
19 void* user_data, uid_t /*uid*/) {
21 ail_appinfo_get_str(appinfo, AIL_PROP_X_SLP_EXE_PATH, &package_exec);
23 return AIL_CB_RET_CONTINUE;
25 std::string* x_slp_exe_path = static_cast<std::string*>(user_data);
26 *x_slp_exe_path = package_exec;
27 return AIL_CB_RET_CANCEL;
30 ail_cb_ret_e callback_installed_time(const ail_appinfo_h appinfo,
31 void* user_data, uid_t /*uid*/) {
32 int* installed_time = static_cast<int*>(user_data);
33 ail_appinfo_get_int(appinfo, AIL_PROP_X_SLP_INSTALLEDTIME_INT,
35 return AIL_CB_RET_CANCEL;
38 void GetProperty(const std::string& id,
40 PropertyCallback callback,
43 ail_error_e ret = ail_filter_new(&filter);
44 if (ret != AIL_ERROR_OK) {
45 LOG(ERROR) << "Failed to create AIL filter.";
49 ret = ail_filter_add_str(filter, type, id.c_str());
50 if (ret != AIL_ERROR_OK) {
51 LOG(ERROR) << "Failed to init AIL filter.";
52 ail_filter_destroy(filter);
58 if (uid != GLOBAL_USER)
59 ret = ail_filter_count_usr_appinfo(filter, &count, uid);
61 ret = ail_filter_count_appinfo(filter, &count);
62 if (ret != AIL_ERROR_OK) {
63 LOG(ERROR) << "Failed to count AIL app info.";
64 ail_filter_destroy(filter);
69 LOG(ERROR) << "Invalid count (" << count
70 << ") of the AIL DB records for the app id " << id;
71 ail_filter_destroy(filter);
76 if (uid != GLOBAL_USER)
77 ail_filter_list_usr_appinfo_foreach(filter, callback,
80 ail_filter_list_appinfo_foreach(filter,
82 ail_filter_destroy(filter);
85 base::FilePath GetPath(const std::string& app_id, const char* type) {
86 std::string x_slp_exe_path;
89 callback_x_slp_exe_path,
90 static_cast<void*>(&x_slp_exe_path));
92 if (x_slp_exe_path.empty()) {
93 return base::FilePath();
96 // x_slp_exe_path is <app_path>/bin/<app_id>, we need to
97 // return just <app_path>.
98 return base::FilePath(x_slp_exe_path).DirName().DirName();
104 namespace application {
106 base::FilePath GetApplicationPath(const std::string& app_id) {
107 return GetPath(app_id, AIL_PROP_X_SLP_APPID_STR);
110 base::FilePath GetPackagePath(const std::string& pkg_id) {
111 return GetPath(pkg_id, AIL_PROP_X_SLP_PKGID_STR);
114 base::Time GetApplicationInstallationTime(const std::string& app_id) {
115 int installed_time = 0; // seconds since epoch
117 AIL_PROP_X_SLP_APPID_STR,
118 callback_installed_time,
119 static_cast<void*>(&installed_time));
120 return base::Time::FromTimeT(installed_time);
123 } // namespace application