4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
34 #include "pkgmgr-info.h"
35 #include "pkgmgrinfo_debug.h"
36 #include "pkgmgrinfo_private.h"
37 #include "pkgmgr_parser.h"
39 static GHashTable *plugin_set_list;
41 struct _pkginfo_str_map_t {
42 pkgmgrinfo_pkginfo_filter_prop_str prop;
46 static struct _pkginfo_str_map_t pkginfo_str_prop_map[] = {
47 {E_PMINFO_PKGINFO_PROP_PACKAGE_ID, PMINFO_PKGINFO_PROP_PACKAGE_ID},
48 {E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE, PMINFO_PKGINFO_PROP_PACKAGE_TYPE},
49 {E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION, PMINFO_PKGINFO_PROP_PACKAGE_VERSION},
50 {E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION, PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION},
51 {E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE, PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE},
52 {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME},
53 {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL},
54 {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF},
55 {E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE, PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE}
58 struct _pkginfo_int_map_t {
59 pkgmgrinfo_pkginfo_filter_prop_int prop;
63 static struct _pkginfo_int_map_t pkginfo_int_prop_map[] = {
64 {E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE, PMINFO_PKGINFO_PROP_PACKAGE_SIZE}
67 struct _pkginfo_bool_map_t {
68 pkgmgrinfo_pkginfo_filter_prop_bool prop;
72 static struct _pkginfo_bool_map_t pkginfo_bool_prop_map[] = {
73 {E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE},
74 {E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD},
75 {E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY, PMINFO_PKGINFO_PROP_PACKAGE_READONLY},
76 {E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE, PMINFO_PKGINFO_PROP_PACKAGE_UPDATE},
77 {E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING},
78 {E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING, PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING},
79 {E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE},
80 {E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE},
81 {E_PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE}
84 struct _appinfo_str_map_t {
85 pkgmgrinfo_appinfo_filter_prop_str prop;
89 static struct _appinfo_str_map_t appinfo_str_prop_map[] = {
90 {E_PMINFO_APPINFO_PROP_APP_ID, PMINFO_APPINFO_PROP_APP_ID},
91 {E_PMINFO_APPINFO_PROP_APP_COMPONENT, PMINFO_APPINFO_PROP_APP_COMPONENT},
92 {E_PMINFO_APPINFO_PROP_APP_EXEC, PMINFO_APPINFO_PROP_APP_EXEC},
93 {E_PMINFO_APPINFO_PROP_APP_ICON, PMINFO_APPINFO_PROP_APP_ICON},
94 {E_PMINFO_APPINFO_PROP_APP_TYPE, PMINFO_APPINFO_PROP_APP_TYPE},
95 {E_PMINFO_APPINFO_PROP_APP_OPERATION, PMINFO_APPINFO_PROP_APP_OPERATION},
96 {E_PMINFO_APPINFO_PROP_APP_URI, PMINFO_APPINFO_PROP_APP_URI},
97 {E_PMINFO_APPINFO_PROP_APP_MIME, PMINFO_APPINFO_PROP_APP_MIME},
98 {E_PMINFO_APPINFO_PROP_APP_CATEGORY, PMINFO_APPINFO_PROP_APP_CATEGORY},
99 {E_PMINFO_APPINFO_PROP_APP_HWACCELERATION, PMINFO_APPINFO_PROP_APP_HWACCELERATION},
100 {E_PMINFO_APPINFO_PROP_APP_SCREENREADER, PMINFO_APPINFO_PROP_APP_SCREENREADER},
101 {E_PMINFO_APPINFO_PROP_APP_PACKAGE, PMINFO_APPINFO_PROP_APP_PACKAGE},
102 {E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE, PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE}
105 struct _appinfo_int_map_t {
106 pkgmgrinfo_appinfo_filter_prop_int prop;
107 const char *property;
110 static struct _appinfo_int_map_t appinfo_int_prop_map[] = {
111 {E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE, PMINFO_APPINFO_PROP_APP_SUPPORT_MODE}
114 struct _appinfo_bool_map_t {
115 pkgmgrinfo_appinfo_filter_prop_bool prop;
116 const char *property;
119 static struct _appinfo_bool_map_t appinfo_bool_prop_map[] = {
120 {E_PMINFO_APPINFO_PROP_APP_NODISPLAY, PMINFO_APPINFO_PROP_APP_NODISPLAY},
121 {E_PMINFO_APPINFO_PROP_APP_MULTIPLE, PMINFO_APPINFO_PROP_APP_MULTIPLE},
122 {E_PMINFO_APPINFO_PROP_APP_ONBOOT, PMINFO_APPINFO_PROP_APP_ONBOOT},
123 {E_PMINFO_APPINFO_PROP_APP_AUTORESTART, PMINFO_APPINFO_PROP_APP_AUTORESTART},
124 {E_PMINFO_APPINFO_PROP_APP_TASKMANAGE, PMINFO_APPINFO_PROP_APP_TASKMANAGE},
125 {E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION, PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION},
126 {E_PMINFO_APPINFO_PROP_APP_UI_GADGET, PMINFO_APPINFO_PROP_APP_UI_GADGET},
127 {E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE, PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE},
128 {E_PMINFO_APPINFO_PROP_APP_DISABLE, PMINFO_APPINFO_PROP_APP_DISABLE},
129 {E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, PMINFO_APPINFO_PROP_APP_CHECK_STORAGE}
132 inline pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property)
136 pkgmgrinfo_pkginfo_filter_prop_str prop = -1;
138 if (property == NULL)
140 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR + 1;
141 for (i = 0 ; i < max; i++) {
142 if (strcmp(property, pkginfo_str_prop_map[i].property) == 0) {
143 prop = pkginfo_str_prop_map[i].prop;
150 inline pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(const char *property)
154 pkgmgrinfo_pkginfo_filter_prop_int prop = -1;
156 if (property == NULL)
158 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT + 1;
159 for (i = 0 ; i < max; i++) {
160 if (strcmp(property, pkginfo_int_prop_map[i].property) == 0) {
161 prop = pkginfo_int_prop_map[i].prop;
168 inline pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool(const char *property)
172 pkgmgrinfo_pkginfo_filter_prop_bool prop = -1;
174 if (property == NULL)
176 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL + 1;
177 for (i = 0 ; i < max; i++) {
178 if (strcmp(property, pkginfo_bool_prop_map[i].property) == 0) {
179 prop = pkginfo_bool_prop_map[i].prop;
186 inline pkgmgrinfo_appinfo_filter_prop_str _pminfo_appinfo_convert_to_prop_str(const char *property)
190 pkgmgrinfo_appinfo_filter_prop_str prop = -1;
192 if (property == NULL)
194 max = E_PMINFO_APPINFO_PROP_APP_MAX_STR - E_PMINFO_APPINFO_PROP_APP_MIN_STR + 1;
195 for (i = 0 ; i < max; i++) {
196 if (strcmp(property, appinfo_str_prop_map[i].property) == 0) {
197 prop = appinfo_str_prop_map[i].prop;
204 inline pkgmgrinfo_appinfo_filter_prop_int _pminfo_appinfo_convert_to_prop_int(const char *property)
208 pkgmgrinfo_appinfo_filter_prop_int prop = -1;
210 if (property == NULL)
212 max = E_PMINFO_APPINFO_PROP_APP_MAX_INT - E_PMINFO_APPINFO_PROP_APP_MIN_INT + 1;
213 for (i = 0 ; i < max; i++) {
214 if (strcmp(property, appinfo_int_prop_map[i].property) == 0) {
215 prop = appinfo_int_prop_map[i].prop;
222 inline pkgmgrinfo_appinfo_filter_prop_bool _pminfo_appinfo_convert_to_prop_bool(const char *property)
226 pkgmgrinfo_appinfo_filter_prop_bool prop = -1;
228 if (property == NULL)
230 max = E_PMINFO_APPINFO_PROP_APP_MAX_BOOL - E_PMINFO_APPINFO_PROP_APP_MIN_BOOL + 1;
231 for (i = 0 ; i < max; i++) {
232 if (strcmp(property, appinfo_bool_prop_map[i].property) == 0) {
233 prop = appinfo_bool_prop_map[i].prop;
240 int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **params)
242 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
243 char buf[MAX_QUERY_LEN] = {'\0'};
247 char *saveptr = NULL;
250 switch (node->prop) {
251 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
252 snprintf(buf, sizeof(buf), "pi.package=?");
254 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
255 snprintf(buf, sizeof(buf), "pi.package_type=?");
257 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
258 snprintf(buf, sizeof(buf), "pi.package_version=?");
260 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
261 snprintf(buf, sizeof(buf), "pi.install_location=?");
263 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
264 snprintf(buf, sizeof(buf), "pi.installed_storage=?");
266 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
267 snprintf(buf, sizeof(buf), "pi.author_name=?");
269 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
270 snprintf(buf, sizeof(buf), "pi.author_href=?");
272 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
273 snprintf(buf, sizeof(buf), "pi.author_email=?");
275 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE:
276 snprintf(buf, sizeof(buf), "package_privilege_info.privilege=?");
277 flag = E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO;
279 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
280 snprintf(buf, sizeof(buf), "pi.package_size=?");
282 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
283 snprintf(buf, sizeof(buf), "pi.package_removable=? COLLATE NOCASE");
285 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
286 snprintf(buf, sizeof(buf), "pi.package_preload=? COLLATE NOCASE");
288 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
289 snprintf(buf, sizeof(buf), "pi.package_readonly=? COLLATE NOCASE");
291 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
292 snprintf(buf, sizeof(buf), "pi.package_update=? COLLATE NOCASE");
294 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
295 snprintf(buf, sizeof(buf), "pi.package_appsetting=? COLLATE NOCASE");
297 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
298 snprintf(buf, sizeof(buf), "pi.package_nodisplay=? COLLATE NOCASE");
300 case E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE:
301 snprintf(buf, sizeof(buf), "pi.package_support_disable=? COLLATE NOCASE");
303 case E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE:
304 snprintf(buf, sizeof(buf), "pi.package_disable=? COLLATE NOCASE");
307 case E_PMINFO_APPINFO_PROP_APP_ID:
308 snprintf(buf, sizeof(buf), "ai.app_id=?");
310 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
311 snprintf(buf, sizeof(buf), "ai.app_component=?");
313 case E_PMINFO_APPINFO_PROP_APP_EXEC:
314 snprintf(buf, sizeof(buf), "ai.app_exec=?");
316 case E_PMINFO_APPINFO_PROP_APP_ICON:
317 snprintf(buf, sizeof(buf), "package_app_localized_info.app_icon=?");
318 flag = E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO;
320 case E_PMINFO_APPINFO_PROP_APP_TYPE:
321 snprintf(buf, sizeof(buf), "ai.app_type=?");
323 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
324 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE ?||'|%%%%|%%%%'");
325 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
327 case E_PMINFO_APPINFO_PROP_APP_URI:
328 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE '%%%%|'||?||'|%%%%'");
329 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
331 case E_PMINFO_APPINFO_PROP_APP_MIME:
332 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE '%%%%|%%%%|'||?");
333 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
335 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
336 snprintf(buf, sizeof(buf), "package_app_app_category.category IN (");
337 value = strdup(node->value);
339 _LOGE("out of memeory");
342 ptr = strtok_r(value, ",", &saveptr);
347 strncat(buf, "?", MAX_QUERY_LEN - len - 1);
349 *params = g_list_append(*params, strdup(ptr));
350 while ((ptr = strtok_r(NULL, ",", &saveptr))) {
351 strncat(buf, ", ?", MAX_QUERY_LEN - len - 1);
352 len += strlen(", ?");
353 *params = g_list_append(*params, strdup(ptr));
355 strncat(buf, ")", MAX_QUERY_LEN - len - 1);
357 *condition = strdup(buf);
358 flag = E_PMINFO_APPINFO_JOIN_CATEGORY;
362 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
363 snprintf(buf, sizeof(buf), "ai.app_nodisplay=? COLLATE NOCASE");
365 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
366 snprintf(buf, sizeof(buf), "ai.app_multiple=? COLLATE NOCASE");
368 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
369 snprintf(buf, sizeof(buf), "ai.app_onboot=? COLLATE NOCASE");
371 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
372 snprintf(buf, sizeof(buf), "ai.app_autorestart=? COLLATE NOCASE");
374 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
375 snprintf(buf, sizeof(buf), "ai.app_taskmanage=? COLLATE NOCASE");
377 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
378 snprintf(buf, sizeof(buf), "ai.app_hwacceleration=?");
380 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
381 snprintf(buf, sizeof(buf), "ai.app_screenreader=?");
383 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
384 snprintf(buf, sizeof(buf), "ai.app_launchcondition=? COLLATE NOCASE");
386 case E_PMINFO_APPINFO_PROP_APP_PACKAGE:
387 snprintf(buf, sizeof(buf), "ai.package=?");
389 case E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE:
390 snprintf(buf, sizeof(buf), "ai.app_installed_storage=?");
392 case E_PMINFO_APPINFO_PROP_APP_UI_GADGET:
393 snprintf(buf, sizeof(buf), "ai.app_ui_gadget=? COLLATE NOCASE");
395 case E_PMINFO_APPINFO_PROP_APP_DISABLE:
396 if (strcasecmp(node->value, "true") == 0)
397 snprintf(buf, MAX_QUERY_LEN, "(ai.app_disable=? COLLATE NOCASE " \
398 "OR ui.is_disabled='true' COLLATE NOCASE)");
400 snprintf(buf, MAX_QUERY_LEN, "(ai.app_disable=? COLLATE NOCASE " \
401 "AND (ui.is_disabled='false' COLLATE NOCASE " \
402 "OR ui.is_disabled IS NULL))");
404 case E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE:
405 snprintf(buf, MAX_QUERY_LEN, "ai.app_support_disable=? COLLATE NOCASE");
407 case E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE:
408 snprintf(buf, sizeof(buf), "ai.app_support_mode=?");
410 case E_PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE:
411 case E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE:
415 _LOGE("Invalid Property Type\n");
419 *condition = strdup(buf);
420 *params = g_list_append(*params, strdup(node->value));
424 int __get_metadata_filter_condition(gpointer data, char **condition,
427 pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
428 char buf[MAX_QUERY_LEN];
431 snprintf(buf, sizeof(buf), "(package_app_app_metadata.md_key=?");
432 len += strlen("(package_app_app_metadata.md_key=?");
434 strncat(buf, " AND package_app_app_metadata.md_value=?",
435 sizeof(buf) - len - 1);
436 len += strlen(" AND package_app_app_metadata.md_value=?");
438 strncat(buf, ")", sizeof(buf) - len - 1);
441 *condition = strdup(buf);
442 *params = g_list_append(*params, strdup(node->key));
444 *params = g_list_append(*params, strdup(node->value));
446 return E_PMINFO_APPINFO_JOIN_METADATA;
449 int _add_icon_info_into_list(const char *locale, char *value, GList **icon)
453 info = calloc(1, sizeof(icon_x));
455 LOGE("out of memory");
456 return PMINFO_R_ERROR;
459 info->lang = strdup(locale);
460 *icon = g_list_append(*icon, info);
465 int _add_label_info_into_list(const char *locale, char *value, GList **label)
469 info = calloc(1, sizeof(label_x));
471 LOGE("out of memory");
472 return PMINFO_R_ERROR;
475 info->lang = strdup(locale);
476 *label = g_list_append(*label, info);
481 char *_get_system_locale(void)
486 lang = vconf_get_str(VCONFKEY_LANGSET);
488 locale = strdup(DEFAULT_LOCALE);
489 if (locale == NULL) {
490 LOGE("out of memory");
496 locale = malloc(sizeof(char) * 6);
497 if (locale == NULL) {
498 LOGE("out of memory");
503 strncpy(locale, lang, 2);
505 locale[3] = tolower(lang[3]);
506 locale[4] = tolower(lang[4]);
514 int __pkginfo_check_installed_storage(package_x *pkginfo)
516 char buf[MAX_QUERY_LEN] = {'\0'};
519 retvm_if(pkginfo->package == NULL, PMINFO_R_OK, "pkgid is NULL\n");
520 retvm_if(pkginfo->installed_storage == NULL, PMINFO_R_ERROR,
521 "installed_storage is NULL\n");
523 if (strcmp(pkginfo->installed_storage, "installed_external") == 0) {
524 snprintf(buf, MAX_QUERY_LEN - 1, "%s", pkginfo->external_path);
525 ret = access(buf, R_OK);
527 _LOGE("can not access [%s] - %d", buf, ret);
528 return PMINFO_R_ERROR;
535 int __appinfo_check_installed_storage(application_x *appinfo)
537 retvm_if(appinfo->installed_storage == NULL, PMINFO_R_ERROR,
538 "installed_storage is NULL\n");
540 if (strcmp(appinfo->installed_storage, "installed_external") == 0) {
541 retvm_if(appinfo->external_path == NULL, PMINFO_R_ERROR,
542 "external path is NULL\n");
543 if (access(appinfo->external_path, R_OK) != 0) {
544 _LOGE("can not access [%s]", appinfo->external_path);
545 return PMINFO_R_ERROR;
552 #define BUSY_WAITING_USEC (1000000 / 10 / 2) /* 0.05 sec */
553 #define BUSY_WAITING_MAX 20 /* wait for max 1 sec */
554 static int __db_busy_handler(void *data, int count)
556 if (count < BUSY_WAITING_MAX) {
557 usleep(BUSY_WAITING_USEC);
560 /* sqlite3_prepare_v2 will return SQLITE_BUSY */
565 int __open_db(const char *path, sqlite3 **db, int flags)
569 ret = sqlite3_open_v2(path, db, flags, NULL);
570 if (ret != SQLITE_OK)
573 ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL);
574 if (ret != SQLITE_OK) {
575 _LOGE("failed to register busy handler: %s",
576 sqlite3_errmsg(*db));
577 sqlite3_close_v2(*db);
585 const char *manifest;
589 struct type_map type_map[] = {
590 { "res/wgt/config.xml", "wgt" },
591 { "config.xml", "wgt" },
592 { "tizen-manifest.xml", "tpk" },
596 char *__get_type_from_path(const char *pkg_path)
598 const char *type = NULL;
602 uf = unzOpen(pkg_path);
604 _LOGE("failed to open zip file %s", pkg_path);
608 for (i = 0; type_map[i].manifest != NULL; i++) {
609 if (unzLocateFile(uf, type_map[i].manifest, 0) == UNZ_OK) {
610 _LOGD("pkgtype of %s: [%s]", pkg_path,
612 type = type_map[i].type;
619 _LOGE("cannot get pkg type of file %s", pkg_path);
626 static const char *__get_library_path(const char *pkg_type)
631 snprintf(buf, sizeof(buf), "package-manager/backendlib/lib%s.so",
633 path = tzplatform_mkpath(TZ_SYS_RO_ETC, buf);
638 pkg_plugin_set *__load_library(const char *pkg_type)
640 void *library_handle;
641 pkg_plugin_set *plugin_set;
642 bool (*on_load)(pkg_plugin_set *plugin);
643 const char *library_path;
645 library_path = __get_library_path(pkg_type);
646 if (library_path == NULL) {
647 _LOGE("cannot get library path for %s", pkg_type);
651 if (plugin_set_list == NULL) {
652 plugin_set_list = g_hash_table_new_full(g_str_hash,
653 g_str_equal, free, free);
654 if (plugin_set_list == NULL) {
655 _LOGE("out of memory");
660 plugin_set = (pkg_plugin_set *)g_hash_table_lookup(plugin_set_list,
661 (gconstpointer)pkg_type);
663 _LOGD("already loaded [%s]", library_path);
667 if ((library_handle = dlopen(library_path, RTLD_LAZY)) == NULL) {
668 _LOGE("dlopen is failed library_path[%s]", library_path);
672 if ((on_load = dlsym(library_handle, "pkg_plugin_on_load")) == NULL ||
674 _LOGE("cannot find symbol");
675 dlclose(library_handle);
679 plugin_set = (pkg_plugin_set *)calloc(1, sizeof(pkg_plugin_set));
680 if (plugin_set == NULL) {
681 _LOGE("out of memory");
682 dlclose(library_handle);
686 if (on_load(plugin_set) != 0) {
687 _LOGE("pkg_plugin_on_load failed");
689 dlclose(library_handle);
694 plugin_set->plugin_handle = library_handle;
695 snprintf(plugin_set->pkg_type,
696 sizeof(plugin_set->pkg_type), "%s", pkg_type);
698 g_hash_table_insert(plugin_set_list, (gpointer)strdup(pkg_type),
699 (gpointer)plugin_set);
701 _LOGD("library [%s] is loaded", library_path);
706 void __unload_library(const char *pkg_type)
708 pkg_plugin_set *plugin_set;
710 if (plugin_set_list == NULL)
713 plugin_set = (pkg_plugin_set *)g_hash_table_lookup(plugin_set_list,
714 (gconstpointer)pkg_type);
716 if (plugin_set == NULL) {
717 _LOGE("pkg plugin for %s is not loaded", pkg_type);
721 plugin_set->plugin_on_unload();
722 dlclose(plugin_set->plugin_handle);
723 g_hash_table_remove(plugin_set_list, (gconstpointer)pkg_type);