13 #include "pkgmgr-info.h"
14 #include "pkgmgrinfo_debug.h"
15 #include "pkgmgrinfo_private.h"
16 #include "pkgmgr_parser.h"
18 static bool _get_bool_value(const char *str)
22 else if (!strcasecmp(str, "true"))
28 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
30 pkgmgr_appinfo_x *info = data;
31 pkgmgr_appinfo_x *tmp;
33 while (info != NULL) {
36 free((void *)info->package);
38 free((void *)info->locale);
40 pkgmgrinfo_basic_free_application(info->app_info);
47 static char *_get_filtered_query(const char *query_raw,
48 pkgmgrinfo_filter_x *filter)
50 char buf[MAX_QUERY_LEN] = { 0, };
59 strncat(buf, query_raw, MAX_QUERY_LEN - 1);
61 for (list = head; list; list = list->next) {
62 /* TODO: revise condition getter function */
63 __get_filter_condition(list->data, &condition);
64 if (condition == NULL)
66 if (buf[strlen(query_raw)] == '\0') {
67 len += strlen(" WHERE ");
68 strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
70 len += strlen(" AND ");
71 strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
73 len += strlen(condition);
74 strncat(buf, condition, sizeof(buf) - len - 1);
82 static gint __list_strcmp(gconstpointer a, gconstpointer b)
84 return strcmp((char *)a, (char *)b);
87 static gint _appinfo_get_list(sqlite3 *db, const char *locale,
88 pkgmgrinfo_filter_x *filter, GList **list)
90 static const char query_raw[] =
91 "SELECT DISTINCT package_app_info.app_id FROM package_app_info"
92 " LEFT OUTER JOIN package_app_localized_info"
93 " ON package_app_info.app_id=package_app_localized_info.app_id"
94 " AND package_app_localized_info.app_locale=%Q"
95 " LEFT OUTER JOIN package_app_app_category"
96 " ON package_app_info.app_id=package_app_app_category.app_id"
97 " LEFT OUTER JOIN package_app_app_control"
98 " ON package_app_info.app_id=package_app_app_control.app_id"
99 " LEFT OUTER JOIN package_app_app_metadata"
100 " ON package_app_info.app_id=package_app_app_metadata.app_id ";
103 char *query_localized;
107 query = _get_filtered_query(query_raw, filter);
109 return PMINFO_R_ERROR;
110 query_localized = sqlite3_mprintf(query, locale);
112 if (query_localized == NULL)
113 return PMINFO_R_ERROR;
115 ret = sqlite3_prepare_v2(db, query_localized,
116 strlen(query_localized), &stmt, NULL);
117 sqlite3_free(query_localized);
118 if (ret != SQLITE_OK) {
119 LOGE("prepare failed: %s", sqlite3_errmsg(db));
120 return PMINFO_R_ERROR;
123 while (sqlite3_step(stmt) == SQLITE_ROW) {
124 _save_column_str(stmt, 0, (const char **)&appid);
126 *list = g_list_insert_sorted(*list, appid,
130 sqlite3_finalize(stmt);
135 static int _appinfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid,
145 locale = _get_system_locale();
147 return PMINFO_R_ERROR;
149 dbpath = getUserPkgParserDBPathUID(uid);
150 if (dbpath == NULL) {
152 return PMINFO_R_ERROR;
155 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
156 if (ret != SQLITE_OK) {
157 _LOGE("failed to open db: %d", ret);
159 return PMINFO_R_ERROR;
162 if (_appinfo_get_list(db, locale, filter, list)) {
164 sqlite3_close_v2(db);
165 return PMINFO_R_ERROR;
167 sqlite3_close_v2(db);
169 if (uid == GLOBAL_USER) {
174 /* search again from global */
175 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
176 if (dbpath == NULL) {
178 return PMINFO_R_ERROR;
181 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
182 if (ret != SQLITE_OK) {
183 _LOGE("failed to open db: %d", ret);
185 return PMINFO_R_ERROR;
188 if (_appinfo_get_list(db, locale, filter, list)) {
190 sqlite3_close_v2(db);
191 return PMINFO_R_ERROR;
193 sqlite3_close_v2(db);
195 /* remove duplicate element:
196 * since the list is sorted, we can remove duplicates in linear time
198 for (tmp = *list, tmp2 = g_list_next(tmp); tmp;
199 tmp = tmp2, tmp2 = g_list_next(tmp)) {
200 if (tmp->prev == NULL || tmp->data == NULL)
202 if (strcmp((const char *)tmp->prev->data,
203 (const char *)tmp->data) == 0)
204 *list = g_list_delete_link(*list, tmp);
212 static int _appinfo_get_label(sqlite3 *db, const char *appid,
213 const char *locale, GList **label)
215 static const char query_raw[] =
216 "SELECT app_label, app_locale "
217 "FROM package_app_localized_info "
218 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
225 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
227 LOGE("out of memory");
228 return PMINFO_R_ERROR;
231 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
233 if (ret != SQLITE_OK) {
234 LOGE("prepare failed: %s", sqlite3_errmsg(db));
235 return PMINFO_R_ERROR;
238 while (sqlite3_step(stmt) == SQLITE_ROW) {
239 info = calloc(1, sizeof(label_x));
241 LOGE("out of memory");
242 sqlite3_finalize(stmt);
243 return PMINFO_R_ERROR;
246 _save_column_str(stmt, idx++, &info->text);
247 _save_column_str(stmt, idx++, &info->lang);
248 *label = g_list_append(*label, info);
251 sqlite3_finalize(stmt);
256 static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
259 static const char query_raw[] =
260 "SELECT app_icon, app_locale "
261 "FROM package_app_localized_info "
262 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
269 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
271 LOGE("out of memory");
272 return PMINFO_R_ERROR;
275 ret = sqlite3_prepare_v2(db, query, strlen(query),
278 if (ret != SQLITE_OK) {
279 LOGE("prepare failed: %s", sqlite3_errmsg(db));
280 return PMINFO_R_ERROR;
283 while (sqlite3_step(stmt) == SQLITE_ROW) {
284 info = calloc(1, sizeof(icon_x));
286 LOGE("out of memory");
287 sqlite3_finalize(stmt);
288 return PMINFO_R_ERROR;
291 _save_column_str(stmt, idx++, &info->text);
292 _save_column_str(stmt, idx++, &info->lang);
293 *icon = g_list_append(*icon, info);
296 sqlite3_finalize(stmt);
301 static int _appinfo_get_category(sqlite3 *db, const char *appid,
304 static const char query_raw[] =
305 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
311 query = sqlite3_mprintf(query_raw, appid);
313 LOGE("out of memory");
314 return PMINFO_R_ERROR;
317 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
319 if (ret != SQLITE_OK) {
320 LOGE("prepare failed: %s", sqlite3_errmsg(db));
321 return PMINFO_R_ERROR;
324 while (sqlite3_step(stmt) == SQLITE_ROW) {
326 _save_column_str(stmt, 0, &val);
328 *category = g_list_append(*category, (gpointer)val);
331 sqlite3_finalize(stmt);
336 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
343 if (appcontrol_str == NULL)
346 dup = strdup(appcontrol_str);
348 ac = calloc(1, sizeof(appcontrol_x));
350 _LOGE("out of memory");
353 token = strtok_r(dup, "|", &ptr);
354 if (token && strcmp(token, "NULL"))
355 ac->operation = strdup(token);
356 token = strtok_r(NULL, "|", &ptr);
357 if (token && strcmp(token, "NULL"))
358 ac->uri = strdup(token);
359 token = strtok_r(NULL, "|", &ptr);
360 if (token && strcmp(token, "NULL"))
361 ac->mime = strdup(token);
362 *appcontrol = g_list_append(*appcontrol, ac);
363 } while ((token = strtok_r(NULL, ";", &ptr)));
368 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
371 static const char query_raw[] =
372 "SELECT app_control FROM package_app_app_control "
379 query = sqlite3_mprintf(query_raw, appid);
381 LOGE("out of memory");
382 return PMINFO_R_ERROR;
385 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
387 if (ret != SQLITE_OK) {
388 LOGE("prepare failed: %s", sqlite3_errmsg(db));
389 return PMINFO_R_ERROR;
392 while (sqlite3_step(stmt) == SQLITE_ROW) {
394 _save_column_str(stmt, 0, (const char **)&str);
396 __parse_appcontrol(appcontrol, str);
400 sqlite3_finalize(stmt);
405 static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
408 static const char query_raw[] =
409 "SELECT providerid, access, type "
410 "FROM package_app_data_control WHERE app_id=%Q";
417 query = sqlite3_mprintf(query_raw, appid);
419 LOGE("out of memory");
420 return PMINFO_R_ERROR;
423 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
425 if (ret != SQLITE_OK) {
426 LOGE("prepare failed: %s", sqlite3_errmsg(db));
427 return PMINFO_R_ERROR;
430 while (sqlite3_step(stmt) == SQLITE_ROW) {
431 info = calloc(1, sizeof(datacontrol_x));
433 LOGE("out of memory");
434 sqlite3_finalize(stmt);
435 return PMINFO_R_ERROR;
438 _save_column_str(stmt, idx++, &info->providerid);
439 _save_column_str(stmt, idx++, &info->access);
440 _save_column_str(stmt, idx++, &info->type);
441 *datacontrol = g_list_append(*datacontrol, info);
444 sqlite3_finalize(stmt);
449 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
452 static const char query_raw[] =
453 "SELECT md_key, md_value "
454 "FROM package_app_app_metadata WHERE app_id=%Q";
461 query = sqlite3_mprintf(query_raw, appid);
463 LOGE("out of memory");
464 return PMINFO_R_ERROR;
467 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
469 if (ret != SQLITE_OK) {
470 LOGE("prepare failed: %s", sqlite3_errmsg(db));
471 return PMINFO_R_ERROR;
474 while (sqlite3_step(stmt) == SQLITE_ROW) {
475 info = calloc(1, sizeof(metadata_x));
477 LOGE("out of memory");
478 sqlite3_finalize(stmt);
479 return PMINFO_R_ERROR;
482 _save_column_str(stmt, idx++, &info->key);
483 _save_column_str(stmt, idx++, &info->value);
484 *metadata = g_list_append(*metadata, info);
487 sqlite3_finalize(stmt);
493 static int _appinfo_get_application(sqlite3 *db, const char *appid,
494 const char *locale, application_x **application)
496 static const char query_raw[] =
497 "SELECT app_id, app_component, app_exec, app_nodisplay, "
498 "app_type, app_onboot, app_multiple, app_autorestart, "
499 "app_taskmanage, app_enabled, app_hwacceleration, "
500 "app_screenreader, app_mainapp, app_recentimage, "
501 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
502 "app_landscapeimg, app_guestmodevisibility, "
503 "app_permissiontype, app_preload, app_submode, "
504 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
505 "app_support_disable, "
506 "component_type, package, app_process_pool, app_installed_storage "
507 "FROM package_app_info WHERE app_id=%Q";
514 query = sqlite3_mprintf(query_raw, appid);
516 LOGE("out of memory");
517 return PMINFO_R_ERROR;
520 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
522 if (ret != SQLITE_OK) {
523 LOGE("prepare failed: %s", sqlite3_errmsg(db));
524 return PMINFO_R_ERROR;
527 ret = sqlite3_step(stmt);
528 if (ret == SQLITE_DONE) {
529 sqlite3_finalize(stmt);
530 return PMINFO_R_ENOENT;
531 } else if (ret != SQLITE_ROW) {
532 LOGE("step failed: %s", sqlite3_errmsg(db));
533 sqlite3_finalize(stmt);
534 return PMINFO_R_ERROR;
537 info = calloc(1, sizeof(application_x));
539 LOGE("out of memory");
540 sqlite3_finalize(stmt);
541 return PMINFO_R_ERROR;
544 _save_column_str(stmt, idx++, &info->appid);
545 _save_column_str(stmt, idx++, &info->component);
546 _save_column_str(stmt, idx++, &info->exec);
547 _save_column_str(stmt, idx++, &info->nodisplay);
548 _save_column_str(stmt, idx++, &info->type);
549 _save_column_str(stmt, idx++, &info->onboot);
550 _save_column_str(stmt, idx++, &info->multiple);
551 _save_column_str(stmt, idx++, &info->autorestart);
552 _save_column_str(stmt, idx++, &info->taskmanage);
553 _save_column_str(stmt, idx++, &info->enabled);
554 _save_column_str(stmt, idx++, &info->hwacceleration);
555 _save_column_str(stmt, idx++, &info->screenreader);
556 _save_column_str(stmt, idx++, &info->mainapp);
557 _save_column_str(stmt, idx++, &info->recentimage);
558 _save_column_str(stmt, idx++, &info->launchcondition);
559 _save_column_str(stmt, idx++, &info->indicatordisplay);
560 _save_column_str(stmt, idx++, &info->portraitimg);
561 _save_column_str(stmt, idx++, &info->landscapeimg);
562 _save_column_str(stmt, idx++, &info->guestmode_visibility);
563 _save_column_str(stmt, idx++, &info->permission_type);
564 _save_column_str(stmt, idx++, &info->preload);
565 _save_column_str(stmt, idx++, &info->submode);
566 _save_column_str(stmt, idx++, &info->submode_mainid);
567 _save_column_str(stmt, idx++, &info->launch_mode);
568 _save_column_str(stmt, idx++, &info->ui_gadget);
569 _save_column_str(stmt, idx++, &info->support_disable);
570 _save_column_str(stmt, idx++, &info->component_type);
571 _save_column_str(stmt, idx++, &info->package);
572 _save_column_str(stmt, idx++, &info->process_pool);
573 _save_column_str(stmt, idx++, &info->installed_storage);
575 if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
576 pkgmgrinfo_basic_free_application(info);
577 sqlite3_finalize(stmt);
578 return PMINFO_R_ERROR;
581 if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
582 pkgmgrinfo_basic_free_application(info);
583 sqlite3_finalize(stmt);
584 return PMINFO_R_ERROR;
587 if (_appinfo_get_category(db, info->appid, &info->category)) {
588 pkgmgrinfo_basic_free_application(info);
589 sqlite3_finalize(stmt);
590 return PMINFO_R_ERROR;
593 if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
594 pkgmgrinfo_basic_free_application(info);
595 sqlite3_finalize(stmt);
596 return PMINFO_R_ERROR;
599 if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
600 pkgmgrinfo_basic_free_application(info);
601 sqlite3_finalize(stmt);
602 return PMINFO_R_ERROR;
605 if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
606 pkgmgrinfo_basic_free_application(info);
607 sqlite3_finalize(stmt);
608 return PMINFO_R_ERROR;
613 sqlite3_finalize(stmt);
618 static int _appinfo_get_appinfo(const char *appid, uid_t uid,
619 pkgmgr_appinfo_x **appinfo)
625 pkgmgr_appinfo_x *info;
627 dbpath = getUserPkgParserDBPathUID(uid);
629 return PMINFO_R_ERROR;
631 locale = _get_system_locale();
633 return PMINFO_R_ERROR;
635 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
636 if (ret != SQLITE_OK) {
637 _LOGE("failed to open db: %d", ret);
639 return PMINFO_R_ERROR;
642 info = calloc(1, sizeof(pkgmgr_appinfo_x));
644 _LOGE("out of memory");
646 sqlite3_close_v2(db);
647 return PMINFO_R_ERROR;
650 ret = _appinfo_get_application(db, appid, locale, &info->app_info);
651 if (ret != PMINFO_R_OK) {
654 sqlite3_close_v2(db);
658 info->locale = locale;
659 info->package = strdup(info->app_info->package);
663 sqlite3_close_v2(db);
668 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
669 pkgmgrinfo_appinfo_h *handle)
673 if (appid == NULL || handle == NULL) {
674 LOGE("invalid parameter");
675 return PMINFO_R_EINVAL;
678 ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle);
679 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
680 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
681 (pkgmgr_appinfo_x **)handle);
683 if (ret != PMINFO_R_OK)
684 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
689 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
691 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
694 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
695 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
699 pkgmgr_appinfo_x *info;
705 ret = _appinfo_get_filtered_list(filter, uid, &list);
706 if (ret != PMINFO_R_OK)
707 return PMINFO_R_ERROR;
709 for (tmp = list; tmp; tmp = tmp->next) {
710 appid = (char *)tmp->data;
712 ret = _appinfo_get_appinfo(appid, uid, &info);
713 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
714 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
716 if (ret != PMINFO_R_OK) {
720 if (app_list_cb(info, user_data) < 0)
722 pkgmgrinfo_appinfo_destroy_appinfo(info);
732 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
733 pkgmgrinfo_app_component component,
734 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
737 pkgmgrinfo_appinfo_filter_h filter;
739 const char *comp_str = NULL;
741 if (handle == NULL || app_func == NULL) {
742 LOGE("invalied parameter");
743 return PMINFO_R_EINVAL;
746 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
747 LOGE("invalid parameter");
748 return PMINFO_R_EINVAL;
751 if (pkgmgrinfo_appinfo_filter_create(&filter))
752 return PMINFO_R_ERROR;
754 if (pkgmgrinfo_appinfo_filter_add_string(filter,
755 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
756 pkgmgrinfo_appinfo_filter_destroy(filter);
757 return PMINFO_R_ERROR;
763 comp_str = PMINFO_APPINFO_UI_APP;
766 comp_str = PMINFO_APPINFO_SVC_APP;
773 if (pkgmgrinfo_appinfo_filter_add_string(filter,
774 PMINFO_APPINFO_PROP_APP_COMPONENT,
776 pkgmgrinfo_appinfo_filter_destroy(filter);
777 return PMINFO_R_ERROR;
781 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
784 pkgmgrinfo_appinfo_filter_destroy(filter);
789 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
790 pkgmgrinfo_app_list_cb app_func, void *user_data)
792 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
795 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
797 if (app_func == NULL) {
798 LOGE("invalid parameter");
799 return PMINFO_R_EINVAL;
802 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
806 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
808 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
811 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
813 if (app_func == NULL) {
814 LOGE("invalid parameter");
815 return PMINFO_R_EINVAL;
818 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
822 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
824 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
827 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
829 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
831 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
832 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
834 if (info->app_info == NULL || info->app_info->appid == NULL)
835 return PMINFO_R_ERROR;
836 *appid = (char *)info->app_info->appid;
841 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
843 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
845 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
846 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
848 if (info->package == NULL)
849 return PMINFO_R_ERROR;
851 *pkg_name = (char *)info->package;
856 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
858 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
860 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
861 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
863 if (info->package == NULL)
864 return PMINFO_R_ERROR;
866 *pkgid = (char *)info->package;
871 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
873 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
875 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
876 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
878 if (info->app_info == NULL || info->app_info->exec == NULL)
879 return PMINFO_R_ERROR;
880 *exec = (char *)info->app_info->exec;
886 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
891 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
893 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
894 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
896 locale = info->locale;
897 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
899 if (info->app_info == NULL)
900 return PMINFO_R_ERROR;
902 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
903 ptr = (icon_x *)tmp->data;
904 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
905 !strcasecmp(ptr->text, "(null)") ||
906 strcmp(ptr->lang, locale))
908 *icon = (char *)ptr->text;
912 locale = DEFAULT_LOCALE;
913 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
914 ptr = (icon_x *)tmp->data;
915 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
916 strcmp(ptr->lang, locale))
918 *icon = (char *)ptr->text;
922 return PMINFO_R_ERROR;
926 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
931 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
933 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
934 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
936 locale = info->locale;
937 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
939 if (info->app_info == NULL)
940 return PMINFO_R_ERROR;
942 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
943 ptr = (label_x *)tmp->data;
944 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
945 strcmp(ptr->lang, locale))
947 *label = (char *)ptr->text;
951 locale = DEFAULT_LOCALE;
952 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
953 ptr = (label_x *)tmp->data;
954 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
955 strcmp(ptr->lang, locale))
957 *label = (char *)ptr->text;
961 return PMINFO_R_ERROR;
964 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
968 sqlite3_stmt *stmt = NULL;
971 const char *manifest_db;
973 manifest_db = getUserPkgParserDBPathUID(uid);
974 if (manifest_db == NULL) {
975 _LOGE("Failed to get manifest db path");
979 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
980 _LOGE("DB open fail\n");
984 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
986 _LOGE("Out of memory");
990 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
991 _LOGE("prepare_v2 fail\n");
995 if (sqlite3_step(stmt) == SQLITE_ROW) {
996 val = (char *)sqlite3_column_text(stmt, 0);
998 result = strdup(val);
1002 sqlite3_finalize(stmt);
1003 sqlite3_free(query);
1009 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1013 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1015 val = _get_localed_label(appid, locale, uid);
1017 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1020 return PMINFO_R_ERROR;
1027 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1029 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
1032 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1034 if ( strcasecmp(comp, "uiapp") == 0)
1035 return PMINFO_UI_APP;
1036 else if ( strcasecmp(comp, "svcapp") == 0)
1037 return PMINFO_SVC_APP;
1042 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1044 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1047 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1048 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1050 if (info->app_info == NULL)
1051 return PMINFO_R_ERROR;
1053 comp = __appcomponent_convert(info->app_info->component);
1055 return PMINFO_R_ERROR;
1062 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1064 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1066 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1067 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1069 if (info->app_info == NULL || info->app_info->type == NULL)
1070 return PMINFO_R_ERROR;
1071 *app_type = (char *)info->app_info->type;
1076 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1077 int *operation_count, char ***operation)
1079 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1080 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1081 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1082 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1083 *operation_count = data->operation_count;
1084 *operation = data->operation;
1088 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1089 int *uri_count, char ***uri)
1091 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1092 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1093 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1094 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1095 *uri_count = data->uri_count;
1100 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1101 int *mime_count, char ***mime)
1103 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1104 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1105 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1106 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1107 *mime_count = data->mime_count;
1112 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1113 int *subapp_count, char ***subapp)
1115 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1116 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1117 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1118 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1119 *subapp_count = data->subapp_count;
1120 *subapp = data->subapp;
1124 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1129 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1131 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1132 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1134 if (info->app_info == NULL)
1135 return PMINFO_R_ERROR;
1137 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1138 ptr = (icon_x *)tmp->data;
1139 if (ptr == NULL || ptr->section == NULL)
1142 val = (char *)ptr->section;
1143 if (val && strcmp(val, "setting") == 0) {
1144 *icon = (char *)ptr->text;
1149 return PMINFO_R_ERROR;
1153 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1158 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1160 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1161 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1163 if (info->app_info == NULL)
1164 return PMINFO_R_ERROR;
1166 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1167 ptr = (icon_x *)tmp->data;
1168 if (ptr == NULL || ptr->section == NULL)
1171 val = (char *)ptr->section;
1172 if (val && strcmp(val, "notification") == 0){
1173 *icon = (char *)ptr->text;
1178 return PMINFO_R_ERROR;
1181 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1184 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1186 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1187 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1189 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1190 return PMINFO_R_ERROR;
1192 val = (char *)info->app_info->recentimage;
1193 if (strcasecmp(val, "capture") == 0)
1194 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1195 else if (strcasecmp(val, "icon") == 0)
1196 *type = PMINFO_RECENTIMAGE_USE_ICON;
1198 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1203 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1208 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1210 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1211 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1213 if (info->app_info == NULL)
1214 return PMINFO_R_ERROR;
1216 for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1217 ptr = (image_x *)tmp->data;
1218 if (ptr == NULL || ptr->section == NULL)
1221 val = (char *)ptr->section;
1222 if (val && strcmp(val, "preview") == 0) {
1223 *preview_img = (char *)ptr->text;
1228 return PMINFO_R_ERROR;
1231 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1234 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1236 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1237 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1239 val = info->app_info->permission_type;
1241 return PMINFO_R_ERROR;
1243 if (strcmp(val, "signature") == 0)
1244 *permission = PMINFO_PERMISSION_SIGNATURE;
1245 else if (strcmp(val, "privilege") == 0)
1246 *permission = PMINFO_PERMISSION_PRIVILEGE;
1248 *permission = PMINFO_PERMISSION_NORMAL;
1253 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1255 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1257 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1258 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1260 if (info->app_info == NULL || info->app_info->component_type == NULL)
1261 return PMINFO_R_ERROR;
1263 *component_type = (char *)info->app_info->component_type;
1268 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1271 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1273 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1274 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1276 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1277 return PMINFO_R_ERROR;
1279 val = (char *)info->app_info->hwacceleration;
1280 if (strcasecmp(val, "not-use-GL") == 0)
1281 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1282 else if (strcasecmp(val, "use-GL") == 0)
1283 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1285 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1290 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1293 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1295 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1296 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1298 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1299 return PMINFO_R_ERROR;
1301 val = (char *)info->app_info->screenreader;
1302 if (strcasecmp(val, "screenreader-off") == 0)
1303 *screenreader = PMINFO_SCREENREADER_OFF;
1304 else if (strcasecmp(val, "screenreader-on") == 0)
1305 *screenreader = PMINFO_SCREENREADER_ON;
1307 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1312 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1314 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1316 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1317 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1318 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1320 if (info->app_info == NULL || info->app_info->portraitimg ||
1321 info->app_info->landscapeimg == NULL)
1322 return PMINFO_R_ERROR;
1324 *portrait_img = (char *)info->app_info->portraitimg;
1325 *landscape_img = (char *)info->app_info->landscapeimg;
1330 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1332 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1334 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1335 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1337 if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1338 return PMINFO_R_ERROR;
1340 *submode_mainid = (char *)info->app_info->submode_mainid;
1345 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
1347 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1348 retvm_if(process_pool == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1350 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1351 val = (char *)info->app_info->process_pool;
1353 if (strcasecmp(val, "true") == 0)
1355 else if (strcasecmp(val, "false") == 0)
1363 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
1365 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1366 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1368 if (info->app_info && info->app_info->installed_storage){
1369 if (strcmp(info->app_info->installed_storage,"installed_internal") == 0)
1370 *storage = PMINFO_INTERNAL_STORAGE;
1371 else if (strcmp(info->app_info->installed_storage,"installed_external") == 0)
1372 *storage = PMINFO_EXTERNAL_STORAGE;
1374 return PMINFO_R_ERROR;
1376 return PMINFO_R_ERROR;
1381 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1383 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1385 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1386 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1388 if (info->app_info->launch_mode == NULL)
1389 return PMINFO_R_ERROR;
1391 *mode = (char *)(info->app_info->launch_mode);
1396 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1398 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1399 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1400 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1401 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1403 int ret = PMINFO_R_OK;
1405 sqlite3_stmt *stmt = NULL;
1408 ret = __open_manifest_db(uid, true);
1409 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1411 /*Start constructing query*/
1412 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1415 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1416 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1419 ret = sqlite3_step(stmt);
1420 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1422 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1423 *access = strdup((char *)sqlite3_column_text(stmt, 2));
1428 sqlite3_free(query);
1429 sqlite3_finalize(stmt);
1430 __close_manifest_db();
1434 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1436 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1439 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1441 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1442 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1444 int ret = PMINFO_R_OK;
1446 sqlite3_stmt *stmt = NULL;
1449 ret = __open_manifest_db(uid, true);
1450 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1452 /*Start constructing query*/
1453 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1456 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1457 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1460 ret = sqlite3_step(stmt);
1461 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1463 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1468 sqlite3_free(query);
1469 sqlite3_finalize(stmt);
1470 __close_manifest_db();
1474 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1476 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1479 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1480 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1482 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1483 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1487 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1489 if (info->app_info == NULL)
1490 return PMINFO_R_ERROR;
1492 for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
1493 ptr = (permission_x *)tmp->data;
1497 ret = permission_func(ptr->value, user_data);
1505 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1506 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1508 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1509 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1511 const char *category;
1513 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1515 if (info->app_info == NULL)
1516 return PMINFO_R_ERROR;
1518 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1519 category = (const char *)tmp->data;
1521 ret = category_func(category, user_data);
1529 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1530 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1532 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1533 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1537 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1539 if (info->app_info == NULL)
1540 return PMINFO_R_ERROR;
1542 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
1543 ptr = (metadata_x *)tmp->data;
1547 ret = metadata_func(ptr->key, ptr->value, user_data);
1555 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1556 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1558 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1559 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1561 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1562 appcontrol_x *appcontrol;
1565 if (info->app_info == NULL)
1566 return PMINFO_R_ERROR;
1568 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
1569 appcontrol = (appcontrol_x *)tmp->data;
1570 if (appcontrol == NULL)
1572 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1580 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1582 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1583 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1584 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1586 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
1587 return PMINFO_R_ERROR;
1589 *nodisplay = _get_bool_value(info->app_info->nodisplay);
1594 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1596 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1597 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1598 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1600 if (info->app_info == NULL || info->app_info->multiple == NULL)
1601 return PMINFO_R_ERROR;
1603 *multiple = _get_bool_value(info->app_info->multiple);
1608 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1610 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1611 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1612 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1614 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
1615 return PMINFO_R_ERROR;
1617 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1622 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1624 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1625 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1626 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1628 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
1629 return PMINFO_R_ERROR;
1631 *taskmanage = _get_bool_value(info->app_info->taskmanage);
1636 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1638 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1639 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1640 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1642 if (info->app_info == NULL || info->app_info->enabled == NULL)
1643 return PMINFO_R_ERROR;
1645 *enabled = _get_bool_value(info->app_info->enabled);
1650 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
1652 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1653 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1654 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1656 if (info->app_info == NULL || info->app_info->onboot == NULL)
1657 return PMINFO_R_ERROR;
1659 *onboot = _get_bool_value(info->app_info->onboot);
1664 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
1666 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1667 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1668 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1670 if (info->app_info == NULL || info->app_info->autorestart == NULL)
1671 return PMINFO_R_ERROR;
1673 *autorestart = _get_bool_value(info->app_info->autorestart);
1678 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
1680 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1681 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1682 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1684 if (info->app_info == NULL || info->app_info->mainapp == NULL)
1685 return PMINFO_R_ERROR;
1687 *mainapp = _get_bool_value(info->app_info->mainapp);
1692 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1694 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1695 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1696 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1698 if (info->app_info == NULL || info->app_info->preload == NULL)
1699 return PMINFO_R_ERROR;
1701 *preload = _get_bool_value(info->app_info->preload);
1706 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1708 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1709 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1710 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1712 if (info->app_info == NULL || info->app_info->submode == NULL)
1713 return PMINFO_R_ERROR;
1715 *submode = _get_bool_value(info->app_info->submode);
1720 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1722 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1723 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1724 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1728 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1730 if (info->app_info == NULL)
1731 return PMINFO_R_ERROR;
1734 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1735 val = (const char *)tmp->data;
1738 if (strcasecmp(val, category) == 0) {
1747 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
1750 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1752 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
1753 _LOGE("invalid parameter");
1754 return PMINFO_R_EINVAL;
1757 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
1762 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
1763 bool *support_disable)
1765 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1767 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
1768 _LOGE("invalid parameter");
1769 return PMINFO_R_EINVAL;
1772 *support_disable = _get_bool_value(info->app_info->support_disable);
1777 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
1779 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1780 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1781 __cleanup_appinfo(info);
1785 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
1787 return (pkgmgrinfo_pkginfo_filter_create(handle));
1790 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
1792 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1795 static gint __compare_func(gconstpointer data1, gconstpointer data2)
1797 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
1798 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
1799 if (node1->prop == node2->prop)
1801 else if (node1->prop > node2->prop)
1807 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
1808 const char *property, const int value)
1810 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1811 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1812 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1814 GSList *link = NULL;
1816 prop = _pminfo_appinfo_convert_to_prop_int(property);
1817 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
1818 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
1819 _LOGE("Invalid Integer Property\n");
1820 return PMINFO_R_EINVAL;
1822 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1823 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1825 _LOGE("Out of Memory!!!\n");
1826 return PMINFO_R_ERROR;
1828 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1829 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1831 _LOGE("Out of Memory\n");
1834 return PMINFO_R_ERROR;
1838 /*If API is called multiple times for same property, we should override the previous values.
1839 Last value set will be used for filtering.*/
1840 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1842 filter->list = g_slist_delete_link(filter->list, link);
1843 filter->list = g_slist_append(filter->list, (gpointer)node);
1848 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
1849 const char *property, const bool value)
1851 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1852 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1854 GSList *link = NULL;
1856 prop = _pminfo_appinfo_convert_to_prop_bool(property);
1857 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
1858 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
1859 _LOGE("Invalid Boolean Property\n");
1860 return PMINFO_R_EINVAL;
1862 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1863 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1865 _LOGE("Out of Memory!!!\n");
1866 return PMINFO_R_ERROR;
1869 val = strndup("('true','True')", 15);
1871 val = strndup("('false','False')", 17);
1873 _LOGE("Out of Memory\n");
1876 return PMINFO_R_ERROR;
1880 /*If API is called multiple times for same property, we should override the previous values.
1881 Last value set will be used for filtering.*/
1882 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1884 filter->list = g_slist_delete_link(filter->list, link);
1885 filter->list = g_slist_append(filter->list, (gpointer)node);
1890 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
1891 const char *property, const char *value)
1893 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1894 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1895 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1897 pkgmgrinfo_node_x *ptr = NULL;
1898 char prev[PKG_STRING_LEN_MAX] = {'\0'};
1899 char temp[PKG_STRING_LEN_MAX] = {'\0'};
1900 GSList *link = NULL;
1902 prop = _pminfo_appinfo_convert_to_prop_str(property);
1903 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
1904 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
1905 _LOGE("Invalid String Property\n");
1906 return PMINFO_R_EINVAL;
1908 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1909 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1911 _LOGE("Out of Memory!!!\n");
1912 return PMINFO_R_ERROR;
1916 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
1917 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
1918 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
1920 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
1922 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1924 filter->list = g_slist_delete_link(filter->list, link);
1925 filter->list = g_slist_append(filter->list, (gpointer)node);
1927 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
1928 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
1929 case E_PMINFO_APPINFO_PROP_APP_URI:
1930 case E_PMINFO_APPINFO_PROP_APP_MIME:
1931 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
1933 _LOGE("Out of Memory\n");
1936 return PMINFO_R_ERROR;
1938 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1940 ptr = (pkgmgrinfo_node_x *)link->data;
1941 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
1942 _LOGE("Previous value is %s\n", prev);
1943 filter->list = g_slist_delete_link(filter->list, link);
1944 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
1945 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1946 _LOGE("New value is %s\n", val);
1948 filter->list = g_slist_append(filter->list, (gpointer)node);
1949 memset(temp, '\0', PKG_STRING_LEN_MAX);
1951 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
1952 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1953 _LOGE("First value is %s\n", val);
1955 filter->list = g_slist_append(filter->list, (gpointer)node);
1956 memset(temp, '\0', PKG_STRING_LEN_MAX);
1960 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
1961 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1963 filter->list = g_slist_delete_link(filter->list, link);
1964 filter->list = g_slist_append(filter->list, (gpointer)node);
1970 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
1975 if (handle == NULL || count == NULL) {
1976 _LOGE("invalid parameter");
1977 return PMINFO_R_EINVAL;
1980 ret = _appinfo_get_filtered_list(handle, uid, &list);
1981 if (ret != PMINFO_R_OK)
1982 return PMINFO_R_ERROR;
1984 *count = g_list_length(list);
1986 g_list_free_full(list, free);
1991 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
1993 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
1996 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
1997 pkgmgrinfo_appinfo_filter_h handle,
1998 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2000 if (handle == NULL || app_cb == NULL) {
2001 LOGE("invalid parameter");
2002 return PMINFO_R_EINVAL;
2005 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2009 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
2010 pkgmgrinfo_app_list_cb app_cb, void * user_data)
2012 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
2015 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
2017 return (pkgmgrinfo_pkginfo_filter_create(handle));
2020 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2022 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2025 API int pkgmgrinfo_appinfo_metadata_filter_add(
2026 pkgmgrinfo_appinfo_metadata_filter_h handle,
2027 const char *key, const char *value)
2031 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2032 PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
2033 if (ret != PMINFO_R_OK)
2036 /* value can be NULL.
2037 * In that case all apps with specified key should be displayed
2040 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2041 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2042 if (ret != PMINFO_R_OK)
2049 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2050 pkgmgrinfo_appinfo_metadata_filter_h handle,
2051 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2053 if (handle == NULL || app_cb == NULL) {
2054 LOGE("invalid parameter");
2055 return PMINFO_R_EINVAL;
2058 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2062 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2063 pkgmgrinfo_appinfo_metadata_filter_h handle,
2064 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2066 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2067 user_data, GLOBAL_USER);
2070 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2073 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2075 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2076 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2078 val = info->app_info->guestmode_visibility;
2079 *status = _get_bool_value(val);