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.
32 #include "pkgmgr-info.h"
33 #include "pkgmgrinfo_debug.h"
34 #include "pkgmgrinfo_private.h"
35 #include "pkgmgr_parser.h"
37 struct _pkginfo_str_map_t {
38 pkgmgrinfo_pkginfo_filter_prop_str prop;
42 static struct _pkginfo_str_map_t pkginfo_str_prop_map[] = {
43 {E_PMINFO_PKGINFO_PROP_PACKAGE_ID, PMINFO_PKGINFO_PROP_PACKAGE_ID},
44 {E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE, PMINFO_PKGINFO_PROP_PACKAGE_TYPE},
45 {E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION, PMINFO_PKGINFO_PROP_PACKAGE_VERSION},
46 {E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION, PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION},
47 {E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE, PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE},
48 {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME},
49 {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL},
50 {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF},
51 {E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE, PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE}
54 struct _pkginfo_int_map_t {
55 pkgmgrinfo_pkginfo_filter_prop_int prop;
59 static struct _pkginfo_int_map_t pkginfo_int_prop_map[] = {
60 {E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE, PMINFO_PKGINFO_PROP_PACKAGE_SIZE}
63 struct _pkginfo_bool_map_t {
64 pkgmgrinfo_pkginfo_filter_prop_bool prop;
68 static struct _pkginfo_bool_map_t pkginfo_bool_prop_map[] = {
69 {E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE},
70 {E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD},
71 {E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY, PMINFO_PKGINFO_PROP_PACKAGE_READONLY},
72 {E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE, PMINFO_PKGINFO_PROP_PACKAGE_UPDATE},
73 {E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING},
74 {E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING, PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING},
75 {E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE},
76 {E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE},
77 {E_PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE}
80 struct _appinfo_str_map_t {
81 pkgmgrinfo_appinfo_filter_prop_str prop;
85 static struct _appinfo_str_map_t appinfo_str_prop_map[] = {
86 {E_PMINFO_APPINFO_PROP_APP_ID, PMINFO_APPINFO_PROP_APP_ID},
87 {E_PMINFO_APPINFO_PROP_APP_COMPONENT, PMINFO_APPINFO_PROP_APP_COMPONENT},
88 {E_PMINFO_APPINFO_PROP_APP_EXEC, PMINFO_APPINFO_PROP_APP_EXEC},
89 {E_PMINFO_APPINFO_PROP_APP_ICON, PMINFO_APPINFO_PROP_APP_ICON},
90 {E_PMINFO_APPINFO_PROP_APP_TYPE, PMINFO_APPINFO_PROP_APP_TYPE},
91 {E_PMINFO_APPINFO_PROP_APP_OPERATION, PMINFO_APPINFO_PROP_APP_OPERATION},
92 {E_PMINFO_APPINFO_PROP_APP_URI, PMINFO_APPINFO_PROP_APP_URI},
93 {E_PMINFO_APPINFO_PROP_APP_MIME, PMINFO_APPINFO_PROP_APP_MIME},
94 {E_PMINFO_APPINFO_PROP_APP_CATEGORY, PMINFO_APPINFO_PROP_APP_CATEGORY},
95 {E_PMINFO_APPINFO_PROP_APP_HWACCELERATION, PMINFO_APPINFO_PROP_APP_HWACCELERATION},
96 {E_PMINFO_APPINFO_PROP_APP_SCREENREADER, PMINFO_APPINFO_PROP_APP_SCREENREADER},
97 {E_PMINFO_APPINFO_PROP_APP_PACKAGE, PMINFO_APPINFO_PROP_APP_PACKAGE},
98 {E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE, PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE}
101 struct _appinfo_int_map_t {
102 pkgmgrinfo_appinfo_filter_prop_int prop;
103 const char *property;
106 static struct _appinfo_int_map_t appinfo_int_prop_map[] = {
107 {E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE, PMINFO_APPINFO_PROP_APP_SUPPORT_MODE}
110 struct _appinfo_bool_map_t {
111 pkgmgrinfo_appinfo_filter_prop_bool prop;
112 const char *property;
115 static struct _appinfo_bool_map_t appinfo_bool_prop_map[] = {
116 {E_PMINFO_APPINFO_PROP_APP_NODISPLAY, PMINFO_APPINFO_PROP_APP_NODISPLAY},
117 {E_PMINFO_APPINFO_PROP_APP_MULTIPLE, PMINFO_APPINFO_PROP_APP_MULTIPLE},
118 {E_PMINFO_APPINFO_PROP_APP_ONBOOT, PMINFO_APPINFO_PROP_APP_ONBOOT},
119 {E_PMINFO_APPINFO_PROP_APP_AUTORESTART, PMINFO_APPINFO_PROP_APP_AUTORESTART},
120 {E_PMINFO_APPINFO_PROP_APP_TASKMANAGE, PMINFO_APPINFO_PROP_APP_TASKMANAGE},
121 {E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION, PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION},
122 {E_PMINFO_APPINFO_PROP_APP_UI_GADGET, PMINFO_APPINFO_PROP_APP_UI_GADGET},
123 {E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE, PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE},
124 {E_PMINFO_APPINFO_PROP_APP_DISABLE, PMINFO_APPINFO_PROP_APP_DISABLE},
125 {E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, PMINFO_APPINFO_PROP_APP_CHECK_STORAGE}
128 inline pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property)
132 pkgmgrinfo_pkginfo_filter_prop_str prop = -1;
134 if (property == NULL)
136 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR + 1;
137 for (i = 0 ; i < max; i++) {
138 if (strcmp(property, pkginfo_str_prop_map[i].property) == 0) {
139 prop = pkginfo_str_prop_map[i].prop;
146 inline pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(const char *property)
150 pkgmgrinfo_pkginfo_filter_prop_int prop = -1;
152 if (property == NULL)
154 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT + 1;
155 for (i = 0 ; i < max; i++) {
156 if (strcmp(property, pkginfo_int_prop_map[i].property) == 0) {
157 prop = pkginfo_int_prop_map[i].prop;
164 inline pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool(const char *property)
168 pkgmgrinfo_pkginfo_filter_prop_bool prop = -1;
170 if (property == NULL)
172 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL + 1;
173 for (i = 0 ; i < max; i++) {
174 if (strcmp(property, pkginfo_bool_prop_map[i].property) == 0) {
175 prop = pkginfo_bool_prop_map[i].prop;
182 inline pkgmgrinfo_appinfo_filter_prop_str _pminfo_appinfo_convert_to_prop_str(const char *property)
186 pkgmgrinfo_appinfo_filter_prop_str prop = -1;
188 if (property == NULL)
190 max = E_PMINFO_APPINFO_PROP_APP_MAX_STR - E_PMINFO_APPINFO_PROP_APP_MIN_STR + 1;
191 for (i = 0 ; i < max; i++) {
192 if (strcmp(property, appinfo_str_prop_map[i].property) == 0) {
193 prop = appinfo_str_prop_map[i].prop;
200 inline pkgmgrinfo_appinfo_filter_prop_int _pminfo_appinfo_convert_to_prop_int(const char *property)
204 pkgmgrinfo_appinfo_filter_prop_int prop = -1;
206 if (property == NULL)
208 max = E_PMINFO_APPINFO_PROP_APP_MAX_INT - E_PMINFO_APPINFO_PROP_APP_MIN_INT + 1;
209 for (i = 0 ; i < max; i++) {
210 if (strcmp(property, appinfo_int_prop_map[i].property) == 0) {
211 prop = appinfo_int_prop_map[i].prop;
218 inline pkgmgrinfo_appinfo_filter_prop_bool _pminfo_appinfo_convert_to_prop_bool(const char *property)
222 pkgmgrinfo_appinfo_filter_prop_bool prop = -1;
224 if (property == NULL)
226 max = E_PMINFO_APPINFO_PROP_APP_MAX_BOOL - E_PMINFO_APPINFO_PROP_APP_MIN_BOOL + 1;
227 for (i = 0 ; i < max; i++) {
228 if (strcmp(property, appinfo_bool_prop_map[i].property) == 0) {
229 prop = appinfo_bool_prop_map[i].prop;
236 int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **params)
238 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
239 char buf[MAX_QUERY_LEN] = {'\0'};
243 char *saveptr = NULL;
246 switch (node->prop) {
247 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
248 snprintf(buf, sizeof(buf), "pi.package=?");
250 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
251 snprintf(buf, sizeof(buf), "pi.package_type=?");
253 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
254 snprintf(buf, sizeof(buf), "pi.package_version=?");
256 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
257 snprintf(buf, sizeof(buf), "pi.install_location=?");
259 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
260 snprintf(buf, sizeof(buf), "pi.installed_storage=?");
262 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
263 snprintf(buf, sizeof(buf), "pi.author_name=?");
265 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
266 snprintf(buf, sizeof(buf), "pi.author_href=?");
268 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
269 snprintf(buf, sizeof(buf), "pi.author_email=?");
271 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE:
272 snprintf(buf, sizeof(buf), "package_privilege_info.privilege=?");
273 flag = E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO;
275 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
276 snprintf(buf, sizeof(buf), "pi.package_size=?");
278 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
279 snprintf(buf, sizeof(buf), "pi.package_removable=? COLLATE NOCASE");
281 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
282 snprintf(buf, sizeof(buf), "pi.package_preload=? COLLATE NOCASE");
284 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
285 snprintf(buf, sizeof(buf), "pi.package_readonly=? COLLATE NOCASE");
287 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
288 snprintf(buf, sizeof(buf), "pi.package_update=? COLLATE NOCASE");
290 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
291 snprintf(buf, sizeof(buf), "pi.package_appsetting=? COLLATE NOCASE");
293 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
294 snprintf(buf, sizeof(buf), "pi.package_nodisplay=? COLLATE NOCASE");
296 case E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE:
297 snprintf(buf, sizeof(buf), "pi.package_support_disable=? COLLATE NOCASE");
299 case E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE:
300 snprintf(buf, sizeof(buf), "pi.package_disable=? COLLATE NOCASE");
303 case E_PMINFO_APPINFO_PROP_APP_ID:
304 snprintf(buf, sizeof(buf), "ai.app_id=?");
306 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
307 snprintf(buf, sizeof(buf), "ai.app_component=?");
309 case E_PMINFO_APPINFO_PROP_APP_EXEC:
310 snprintf(buf, sizeof(buf), "ai.app_exec=?");
312 case E_PMINFO_APPINFO_PROP_APP_ICON:
313 snprintf(buf, sizeof(buf), "package_app_localized_info.app_icon=?");
314 flag = E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO;
316 case E_PMINFO_APPINFO_PROP_APP_TYPE:
317 snprintf(buf, sizeof(buf), "ai.app_type=?");
319 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
320 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE ?||'|%%%%|%%%%'");
321 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
323 case E_PMINFO_APPINFO_PROP_APP_URI:
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_MIME:
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_CATEGORY:
332 snprintf(buf, sizeof(buf), "package_app_app_category.category IN (");
333 value = strdup(node->value);
335 _LOGE("out of memeory");
338 ptr = strtok_r(value, ",", &saveptr);
343 strncat(buf, "?", MAX_QUERY_LEN - len - 1);
345 *params = g_list_append(*params, strdup(ptr));
346 while ((ptr = strtok_r(NULL, ",", &saveptr))) {
347 strncat(buf, ", ?", MAX_QUERY_LEN - len - 1);
348 len += strlen(", ?");
349 *params = g_list_append(*params, strdup(ptr));
351 strncat(buf, ")", MAX_QUERY_LEN - len - 1);
353 *condition = strdup(buf);
354 flag = E_PMINFO_APPINFO_JOIN_CATEGORY;
358 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
359 snprintf(buf, sizeof(buf), "ai.app_nodisplay=? COLLATE NOCASE");
361 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
362 snprintf(buf, sizeof(buf), "ai.app_multiple=? COLLATE NOCASE");
364 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
365 snprintf(buf, sizeof(buf), "ai.app_onboot=? COLLATE NOCASE");
367 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
368 snprintf(buf, sizeof(buf), "ai.app_autorestart=? COLLATE NOCASE");
370 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
371 snprintf(buf, sizeof(buf), "ai.app_taskmanage=? COLLATE NOCASE");
373 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
374 snprintf(buf, sizeof(buf), "ai.app_hwacceleration=?");
376 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
377 snprintf(buf, sizeof(buf), "ai.app_screenreader=?");
379 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
380 snprintf(buf, sizeof(buf), "ai.app_launchcondition=? COLLATE NOCASE");
382 case E_PMINFO_APPINFO_PROP_APP_PACKAGE:
383 snprintf(buf, sizeof(buf), "ai.package=?");
385 case E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE:
386 snprintf(buf, sizeof(buf), "ai.app_installed_storage=?");
388 case E_PMINFO_APPINFO_PROP_APP_UI_GADGET:
389 snprintf(buf, sizeof(buf), "ai.app_ui_gadget=? COLLATE NOCASE");
391 case E_PMINFO_APPINFO_PROP_APP_DISABLE:
392 if (strcasecmp(node->value, "true") == 0)
393 snprintf(buf, MAX_QUERY_LEN, "(ai.app_disable=? COLLATE NOCASE OR "
394 "ai.app_id IN (SELECT app_id FROM package_app_info_for_uid "
395 "WHERE uid=%d AND is_disabled='true'))", uid);
397 snprintf(buf, MAX_QUERY_LEN, "(ai.app_disable=? COLLATE NOCASE AND "
398 "ai.app_id NOT IN (SELECT app_id FROM package_app_info_for_uid "
399 "WHERE uid=%d AND is_disabled='true'))", uid);
400 flag = E_PMINFO_APPINFO_JOIN_APPINFO_FOR_UID;
402 case E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE:
403 snprintf(buf, MAX_QUERY_LEN, "ai.app_support_disable=? COLLATE NOCASE");
405 case E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE:
406 snprintf(buf, sizeof(buf), "ai.app_support_mode=?");
408 case E_PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE:
409 case E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE:
413 _LOGE("Invalid Property Type\n");
417 *condition = strdup(buf);
418 *params = g_list_append(*params, strdup(node->value));
422 int __get_metadata_filter_condition(gpointer data, char **condition,
425 pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
426 char buf[MAX_QUERY_LEN];
429 snprintf(buf, sizeof(buf), "(package_app_app_metadata.md_key=?");
430 len += strlen("(package_app_app_metadata.md_key=?");
432 strncat(buf, " AND package_app_app_metadata.md_value=?",
433 sizeof(buf) - len - 1);
434 len += strlen(" AND package_app_app_metadata.md_value=?");
436 strncat(buf, ")", sizeof(buf) - len - 1);
439 *condition = strdup(buf);
440 *params = g_list_append(*params, strdup(node->key));
442 *params = g_list_append(*params, strdup(node->value));
444 return E_PMINFO_APPINFO_JOIN_METADATA;
447 int _add_icon_info_into_list(const char *locale, char *value, GList **icon)
451 info = calloc(1, sizeof(icon_x));
453 LOGE("out of memory");
454 return PMINFO_R_ERROR;
457 info->lang = strdup(locale);
458 *icon = g_list_append(*icon, info);
463 int _add_label_info_into_list(const char *locale, char *value, GList **label)
467 info = calloc(1, sizeof(label_x));
469 LOGE("out of memory");
470 return PMINFO_R_ERROR;
473 info->lang = strdup(locale);
474 *label = g_list_append(*label, info);
479 char *_get_system_locale(void)
484 lang = vconf_get_str(VCONFKEY_LANGSET);
486 locale = strdup(DEFAULT_LOCALE);
487 if (locale == NULL) {
488 LOGE("out of memory");
494 locale = malloc(sizeof(char) * 6);
495 if (locale == NULL) {
496 LOGE("out of memory");
501 strncpy(locale, lang, 2);
503 locale[3] = tolower(lang[3]);
504 locale[4] = tolower(lang[4]);
512 int __pkginfo_check_installed_storage(package_x *pkginfo)
514 char buf[MAX_QUERY_LEN] = {'\0'};
517 retvm_if(pkginfo->package == NULL, PMINFO_R_OK, "pkgid is NULL\n");
518 retvm_if(pkginfo->installed_storage == NULL, PMINFO_R_ERROR,
519 "installed_storage is NULL\n");
521 if (strcmp(pkginfo->installed_storage, "installed_external") == 0) {
522 snprintf(buf, MAX_QUERY_LEN - 1, "%s", pkginfo->external_path);
523 ret = access(buf, R_OK);
525 _LOGE("can not access [%s] - %d", buf, ret);
526 return PMINFO_R_ERROR;
533 int __appinfo_check_installed_storage(application_x *appinfo)
535 retvm_if(appinfo->installed_storage == NULL, PMINFO_R_ERROR,
536 "installed_storage is NULL\n");
538 if (strcmp(appinfo->installed_storage, "installed_external") == 0) {
539 retvm_if(appinfo->external_path == NULL, PMINFO_R_ERROR,
540 "external path is NULL\n");
541 if (access(appinfo->external_path, R_OK) != 0) {
542 _LOGE("can not access [%s]", appinfo->external_path);
543 return PMINFO_R_ERROR;
550 #define BUSY_WAITING_USEC (1000000 / 10 / 2) /* 0.05 sec */
551 #define BUSY_WAITING_MAX 20 /* wait for max 1 sec */
552 static int __db_busy_handler(void *data, int count)
554 if (count < BUSY_WAITING_MAX) {
555 usleep(BUSY_WAITING_USEC);
558 /* sqlite3_prepare_v2 will return SQLITE_BUSY */
563 int __open_db(const char *path, sqlite3 **db, int flags)
567 ret = sqlite3_open_v2(path, db, flags, NULL);
568 if (ret != SQLITE_OK)
571 ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL);
572 if (ret != SQLITE_OK) {
573 _LOGE("failed to register busy handler: %s",
574 sqlite3_errmsg(*db));
575 sqlite3_close_v2(*db);