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},
82 {E_PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM, PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM}
85 struct _appinfo_str_map_t {
86 pkgmgrinfo_appinfo_filter_prop_str prop;
90 static struct _appinfo_str_map_t appinfo_str_prop_map[] = {
91 {E_PMINFO_APPINFO_PROP_APP_ID, PMINFO_APPINFO_PROP_APP_ID},
92 {E_PMINFO_APPINFO_PROP_APP_COMPONENT, PMINFO_APPINFO_PROP_APP_COMPONENT},
93 {E_PMINFO_APPINFO_PROP_APP_EXEC, PMINFO_APPINFO_PROP_APP_EXEC},
94 {E_PMINFO_APPINFO_PROP_APP_ICON, PMINFO_APPINFO_PROP_APP_ICON},
95 {E_PMINFO_APPINFO_PROP_APP_TYPE, PMINFO_APPINFO_PROP_APP_TYPE},
96 {E_PMINFO_APPINFO_PROP_APP_OPERATION, PMINFO_APPINFO_PROP_APP_OPERATION},
97 {E_PMINFO_APPINFO_PROP_APP_URI, PMINFO_APPINFO_PROP_APP_URI},
98 {E_PMINFO_APPINFO_PROP_APP_MIME, PMINFO_APPINFO_PROP_APP_MIME},
99 {E_PMINFO_APPINFO_PROP_APP_CATEGORY, PMINFO_APPINFO_PROP_APP_CATEGORY},
100 {E_PMINFO_APPINFO_PROP_APP_HWACCELERATION, PMINFO_APPINFO_PROP_APP_HWACCELERATION},
101 {E_PMINFO_APPINFO_PROP_APP_SCREENREADER, PMINFO_APPINFO_PROP_APP_SCREENREADER},
102 {E_PMINFO_APPINFO_PROP_APP_PACKAGE, PMINFO_APPINFO_PROP_APP_PACKAGE},
103 {E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE, PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE}
106 struct _appinfo_int_map_t {
107 pkgmgrinfo_appinfo_filter_prop_int prop;
108 const char *property;
111 static struct _appinfo_int_map_t appinfo_int_prop_map[] = {
112 {E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE, PMINFO_APPINFO_PROP_APP_SUPPORT_MODE}
115 struct _appinfo_bool_map_t {
116 pkgmgrinfo_appinfo_filter_prop_bool prop;
117 const char *property;
120 static struct _appinfo_bool_map_t appinfo_bool_prop_map[] = {
121 {E_PMINFO_APPINFO_PROP_APP_NODISPLAY, PMINFO_APPINFO_PROP_APP_NODISPLAY},
122 {E_PMINFO_APPINFO_PROP_APP_MULTIPLE, PMINFO_APPINFO_PROP_APP_MULTIPLE},
123 {E_PMINFO_APPINFO_PROP_APP_ONBOOT, PMINFO_APPINFO_PROP_APP_ONBOOT},
124 {E_PMINFO_APPINFO_PROP_APP_AUTORESTART, PMINFO_APPINFO_PROP_APP_AUTORESTART},
125 {E_PMINFO_APPINFO_PROP_APP_TASKMANAGE, PMINFO_APPINFO_PROP_APP_TASKMANAGE},
126 {E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION, PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION},
127 {E_PMINFO_APPINFO_PROP_APP_UI_GADGET, PMINFO_APPINFO_PROP_APP_UI_GADGET},
128 {E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE, PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE},
129 {E_PMINFO_APPINFO_PROP_APP_DISABLE, PMINFO_APPINFO_PROP_APP_DISABLE},
130 {E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, PMINFO_APPINFO_PROP_APP_CHECK_STORAGE},
131 {E_PMINFO_APPINFO_PROP_PKG_DISABLE, PMINFO_APPINFO_PROP_PKG_DISABLE}
134 inline pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property)
138 pkgmgrinfo_pkginfo_filter_prop_str prop = -1;
140 if (property == NULL)
142 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR + 1;
143 for (i = 0 ; i < max; i++) {
144 if (strcmp(property, pkginfo_str_prop_map[i].property) == 0) {
145 prop = pkginfo_str_prop_map[i].prop;
152 inline pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(const char *property)
156 pkgmgrinfo_pkginfo_filter_prop_int prop = -1;
158 if (property == NULL)
160 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT + 1;
161 for (i = 0 ; i < max; i++) {
162 if (strcmp(property, pkginfo_int_prop_map[i].property) == 0) {
163 prop = pkginfo_int_prop_map[i].prop;
170 inline pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool(const char *property)
174 pkgmgrinfo_pkginfo_filter_prop_bool prop = -1;
176 if (property == NULL)
178 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL + 1;
179 for (i = 0 ; i < max; i++) {
180 if (strcmp(property, pkginfo_bool_prop_map[i].property) == 0) {
181 prop = pkginfo_bool_prop_map[i].prop;
188 inline pkgmgrinfo_appinfo_filter_prop_str _pminfo_appinfo_convert_to_prop_str(const char *property)
192 pkgmgrinfo_appinfo_filter_prop_str prop = -1;
194 if (property == NULL)
196 max = E_PMINFO_APPINFO_PROP_APP_MAX_STR - E_PMINFO_APPINFO_PROP_APP_MIN_STR + 1;
197 for (i = 0 ; i < max; i++) {
198 if (strcmp(property, appinfo_str_prop_map[i].property) == 0) {
199 prop = appinfo_str_prop_map[i].prop;
206 inline pkgmgrinfo_appinfo_filter_prop_int _pminfo_appinfo_convert_to_prop_int(const char *property)
210 pkgmgrinfo_appinfo_filter_prop_int prop = -1;
212 if (property == NULL)
214 max = E_PMINFO_APPINFO_PROP_APP_MAX_INT - E_PMINFO_APPINFO_PROP_APP_MIN_INT + 1;
215 for (i = 0 ; i < max; i++) {
216 if (strcmp(property, appinfo_int_prop_map[i].property) == 0) {
217 prop = appinfo_int_prop_map[i].prop;
224 inline pkgmgrinfo_appinfo_filter_prop_bool _pminfo_appinfo_convert_to_prop_bool(const char *property)
228 pkgmgrinfo_appinfo_filter_prop_bool prop = -1;
230 if (property == NULL)
232 max = E_PMINFO_APPINFO_PROP_APP_MAX_BOOL - E_PMINFO_APPINFO_PROP_APP_MIN_BOOL + 1;
233 for (i = 0 ; i < max; i++) {
234 if (strcmp(property, appinfo_bool_prop_map[i].property) == 0) {
235 prop = appinfo_bool_prop_map[i].prop;
242 int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **params)
244 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
245 char buf[MAX_QUERY_LEN] = {'\0'};
249 char *saveptr = NULL;
251 switch (node->prop) {
252 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
253 snprintf(buf, sizeof(buf), "pi.package=?");
255 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
256 snprintf(buf, sizeof(buf), "pi.package_type=?");
258 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
259 snprintf(buf, sizeof(buf), "pi.package_version=?");
261 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
262 snprintf(buf, sizeof(buf), "pi.install_location=?");
264 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
265 snprintf(buf, sizeof(buf), "pi.installed_storage=?");
267 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
268 snprintf(buf, sizeof(buf), "pi.author_name=?");
270 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
271 snprintf(buf, sizeof(buf), "pi.author_href=?");
273 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
274 snprintf(buf, sizeof(buf), "pi.author_email=?");
276 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE:
277 snprintf(buf, sizeof(buf), "package_privilege_info.privilege=?");
278 flag = E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO;
280 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
281 snprintf(buf, sizeof(buf), "pi.package_size=?");
283 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
284 snprintf(buf, sizeof(buf), "pi.package_removable=? COLLATE NOCASE");
286 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
287 snprintf(buf, sizeof(buf), "pi.package_preload=? COLLATE NOCASE");
289 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
290 snprintf(buf, sizeof(buf), "pi.package_readonly=? COLLATE NOCASE");
292 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
293 snprintf(buf, sizeof(buf), "pi.package_update=? COLLATE NOCASE");
295 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
296 snprintf(buf, sizeof(buf), "pi.package_appsetting=? COLLATE NOCASE");
298 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
299 snprintf(buf, sizeof(buf), "pi.package_nodisplay=? COLLATE NOCASE");
301 case E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE:
302 snprintf(buf, sizeof(buf), "pi.package_support_disable=? COLLATE NOCASE");
304 case E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE:
305 snprintf(buf, sizeof(buf), "pi.package_disable=? COLLATE NOCASE");
307 case E_PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM:
308 snprintf(buf, sizeof(buf), "pi.package_system=? COLLATE NOCASE");
311 case E_PMINFO_APPINFO_PROP_APP_ID:
312 snprintf(buf, sizeof(buf), "ai.app_id=?");
314 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
315 snprintf(buf, sizeof(buf), "ai.app_component=?");
317 case E_PMINFO_APPINFO_PROP_APP_EXEC:
318 snprintf(buf, sizeof(buf), "ai.app_exec=?");
320 case E_PMINFO_APPINFO_PROP_APP_ICON:
321 snprintf(buf, sizeof(buf), "package_app_localized_info.app_icon=?");
322 flag = E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO;
324 case E_PMINFO_APPINFO_PROP_APP_TYPE:
325 snprintf(buf, sizeof(buf), "ai.app_type=?");
327 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
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_URI:
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_MIME:
336 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE '%%%%|%%%%|'||?");
337 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
339 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
340 snprintf(buf, sizeof(buf), "package_app_app_category.category IN (");
341 value = strdup(node->value);
343 _LOGE("out of memeory");
346 ptr = strtok_r(value, ",", &saveptr);
351 strncat(buf, "?", sizeof(buf) - strlen(buf) - 1);
352 *params = g_list_append(*params, strdup(ptr));
353 while ((ptr = strtok_r(NULL, ",", &saveptr))) {
354 strncat(buf, ", ?", sizeof(buf) - strlen(buf) - 1);
355 *params = g_list_append(*params, strdup(ptr));
357 strncat(buf, ")", sizeof(buf) - strlen(buf) - 1);
358 *condition = strdup(buf);
359 flag = E_PMINFO_APPINFO_JOIN_CATEGORY;
363 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
364 snprintf(buf, sizeof(buf), "ai.app_nodisplay=? COLLATE NOCASE");
366 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
367 snprintf(buf, sizeof(buf), "ai.app_multiple=? COLLATE NOCASE");
369 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
370 snprintf(buf, sizeof(buf), "ai.app_onboot=? COLLATE NOCASE");
372 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
373 snprintf(buf, sizeof(buf), "ai.app_autorestart=? COLLATE NOCASE");
375 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
376 snprintf(buf, sizeof(buf), "ai.app_taskmanage=? COLLATE NOCASE");
378 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
379 snprintf(buf, sizeof(buf), "ai.app_hwacceleration=?");
381 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
382 snprintf(buf, sizeof(buf), "ai.app_screenreader=?");
384 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
385 snprintf(buf, sizeof(buf), "ai.app_launchcondition=? COLLATE NOCASE");
387 case E_PMINFO_APPINFO_PROP_APP_PACKAGE:
388 snprintf(buf, sizeof(buf), "ai.package=?");
390 case E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE:
391 snprintf(buf, sizeof(buf), "ai.app_installed_storage=?");
393 case E_PMINFO_APPINFO_PROP_APP_UI_GADGET:
394 snprintf(buf, sizeof(buf), "ai.app_ui_gadget=? COLLATE NOCASE");
396 case E_PMINFO_APPINFO_PROP_APP_DISABLE:
397 if (strcasecmp(node->value, "true") == 0)
398 snprintf(buf, MAX_QUERY_LEN, "(ai.app_disable=? COLLATE NOCASE " \
399 "OR ui.is_disabled='true' COLLATE NOCASE)");
401 snprintf(buf, MAX_QUERY_LEN, "(ai.app_disable=? COLLATE NOCASE " \
402 "AND (ui.is_disabled='false' COLLATE NOCASE " \
403 "OR ui.is_disabled IS NULL))");
405 case E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE:
406 snprintf(buf, MAX_QUERY_LEN, "ai.app_support_disable=? COLLATE NOCASE");
408 case E_PMINFO_APPINFO_PROP_PKG_DISABLE:
409 snprintf(buf, MAX_QUERY_LEN,
410 "ai.package IN (SELECT package FROM " \
411 "package_info WHERE package_disable=?)");
413 case E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE:
414 snprintf(buf, sizeof(buf), "ai.app_support_mode=?");
416 case E_PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE:
417 case E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE:
421 _LOGE("Invalid Property Type\n");
425 *condition = strdup(buf);
426 *params = g_list_append(*params, strdup(node->value));
430 int __get_metadata_filter_condition(gpointer data, char **condition,
433 pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
434 char buf[MAX_QUERY_LEN];
436 snprintf(buf, sizeof(buf), "(package_app_app_metadata.md_key=?");
438 strncat(buf, " AND package_app_app_metadata.md_value=?",
439 sizeof(buf) - strlen(buf) - 1);
440 strncat(buf, ")", sizeof(buf) - strlen(buf) - 1);
442 *condition = strdup(buf);
443 *params = g_list_append(*params, strdup(node->key));
445 *params = g_list_append(*params, strdup(node->value));
447 return E_PMINFO_APPINFO_JOIN_METADATA;
450 int _add_icon_info_into_list(const char *locale, char *value, GList **icon)
454 info = calloc(1, sizeof(icon_x));
456 LOGE("out of memory");
457 return PMINFO_R_ERROR;
460 info->lang = strdup(locale);
461 *icon = g_list_append(*icon, info);
466 int _add_label_info_into_list(const char *locale, char *value, GList **label)
470 info = calloc(1, sizeof(label_x));
472 LOGE("out of memory");
473 return PMINFO_R_ERROR;
476 info->lang = strdup(locale);
477 *label = g_list_append(*label, info);
482 char *_get_system_locale(void)
487 lang = vconf_get_str(VCONFKEY_LANGSET);
489 locale = strdup(DEFAULT_LOCALE);
490 if (locale == NULL) {
491 LOGE("out of memory");
497 locale = malloc(sizeof(char) * 6);
498 if (locale == NULL) {
499 LOGE("out of memory");
504 strncpy(locale, lang, 2);
506 locale[3] = tolower(lang[3]);
507 locale[4] = tolower(lang[4]);
515 int __pkginfo_check_installed_storage(package_x *pkginfo)
517 char buf[MAX_QUERY_LEN] = {'\0'};
520 retvm_if(pkginfo->package == NULL, PMINFO_R_OK, "pkgid is NULL\n");
521 retvm_if(pkginfo->installed_storage == NULL, PMINFO_R_ERROR,
522 "installed_storage is NULL\n");
524 if (strcmp(pkginfo->installed_storage, "installed_external") == 0) {
525 snprintf(buf, MAX_QUERY_LEN - 1, "%s", pkginfo->external_path);
526 ret = access(buf, R_OK);
528 _LOGE("can not access [%s] - %d", buf, ret);
529 return PMINFO_R_ERROR;
536 int __appinfo_check_installed_storage(application_x *appinfo)
538 retvm_if(appinfo->installed_storage == NULL, PMINFO_R_ERROR,
539 "installed_storage is NULL\n");
541 if (strcmp(appinfo->installed_storage, "installed_external") == 0) {
542 retvm_if(appinfo->external_path == NULL, PMINFO_R_ERROR,
543 "external path is NULL\n");
544 if (access(appinfo->external_path, R_OK) != 0) {
545 _LOGE("can not access [%s]", appinfo->external_path);
546 return PMINFO_R_ERROR;
553 #define BUSY_WAITING_USEC (1000000 / 10 / 2) /* 0.05 sec */
554 #define BUSY_WAITING_MAX 20 /* wait for max 1 sec */
555 static int __db_busy_handler(void *data, int count)
557 if (count < BUSY_WAITING_MAX) {
558 usleep(BUSY_WAITING_USEC);
561 /* sqlite3_prepare_v2 will return SQLITE_BUSY */
566 int __open_db(const char *path, sqlite3 **db, int flags)
570 ret = sqlite3_open_v2(path, db, flags, NULL);
571 if (ret != SQLITE_OK)
574 ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL);
575 if (ret != SQLITE_OK) {
576 _LOGE("failed to register busy handler: %s",
577 sqlite3_errmsg(*db));
578 sqlite3_close_v2(*db);
586 const char *manifest;
590 struct type_map type_map[] = {
591 { "res/wgt/config.xml", "wgt" },
592 { "config.xml", "wgt" },
593 { "tizen-manifest.xml", "tpk" },
597 char *__get_type_from_path(const char *pkg_path)
599 const char *type = NULL;
603 uf = unzOpen(pkg_path);
605 _LOGE("failed to open zip file %s", pkg_path);
609 for (i = 0; type_map[i].manifest != NULL; i++) {
610 if (unzLocateFile(uf, type_map[i].manifest, 0) == UNZ_OK) {
611 _LOGD("pkgtype of %s: [%s]", pkg_path,
613 type = type_map[i].type;
620 _LOGE("cannot get pkg type of file %s", pkg_path);
627 static const char *__get_library_path(const char *pkg_type)
632 snprintf(buf, sizeof(buf), "package-manager/backendlib/lib%s.so",
634 path = tzplatform_mkpath(TZ_SYS_RO_ETC, buf);
639 pkg_plugin_set *__load_library(const char *pkg_type)
641 void *library_handle;
642 pkg_plugin_set *plugin_set;
643 bool (*on_load)(pkg_plugin_set *plugin);
644 const char *library_path;
646 library_path = __get_library_path(pkg_type);
647 if (library_path == NULL) {
648 _LOGE("cannot get library path for %s", pkg_type);
652 if (plugin_set_list == NULL) {
653 plugin_set_list = g_hash_table_new_full(g_str_hash,
654 g_str_equal, free, free);
655 if (plugin_set_list == NULL) {
656 _LOGE("out of memory");
661 plugin_set = (pkg_plugin_set *)g_hash_table_lookup(plugin_set_list,
662 (gconstpointer)pkg_type);
664 _LOGD("already loaded [%s]", library_path);
668 if ((library_handle = dlopen(library_path, RTLD_LAZY)) == NULL) {
669 _LOGE("dlopen is failed library_path[%s]", library_path);
673 if ((on_load = dlsym(library_handle, "pkg_plugin_on_load")) == NULL ||
675 _LOGE("cannot find symbol");
676 dlclose(library_handle);
680 plugin_set = (pkg_plugin_set *)calloc(1, sizeof(pkg_plugin_set));
681 if (plugin_set == NULL) {
682 _LOGE("out of memory");
683 dlclose(library_handle);
687 if (on_load(plugin_set) != 0) {
688 _LOGE("pkg_plugin_on_load failed");
690 dlclose(library_handle);
695 plugin_set->plugin_handle = library_handle;
696 snprintf(plugin_set->pkg_type,
697 sizeof(plugin_set->pkg_type), "%s", pkg_type);
699 g_hash_table_insert(plugin_set_list, (gpointer)strdup(pkg_type),
700 (gpointer)plugin_set);
702 _LOGD("library [%s] is loaded", library_path);
707 void __unload_library(const char *pkg_type)
709 pkg_plugin_set *plugin_set;
711 if (plugin_set_list == NULL)
714 plugin_set = (pkg_plugin_set *)g_hash_table_lookup(plugin_set_list,
715 (gconstpointer)pkg_type);
717 if (plugin_set == NULL) {
718 _LOGE("pkg plugin for %s is not loaded", pkg_type);
722 plugin_set->plugin_on_unload();
723 dlclose(plugin_set->plugin_handle);
724 g_hash_table_remove(plugin_set_list, (gconstpointer)pkg_type);